Spicy
while.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 #include <spicy/ast/types/unit.h>
10 #include <spicy/compiler/detail/codegen/production.h>
11 #include <spicy/compiler/detail/codegen/productions/look-ahead.h>
12 
14 
20 public:
24  While(const std::string& symbol, Expression e, Production body, const Location& l = location::None)
25  : ProductionBase(symbol, l), _body(std::move(body)), _expression(std::move(e)) {}
26 
33  While(const std::string& symbol, Production body, const Location& l = location::None);
34 
36  const auto& expression() const { return _expression; }
37 
39  const auto& body() const { return _body; }
40 
47  void preprocessLookAhead(Grammar* grammar);
48 
57  assert(_body_for_grammar); // set by preprocessLookAhead() return
58  return _body_for_grammar->as<production::LookAhead>();
59  }
60 
61  // Production API
62  std::vector<std::vector<Production>> rhss() const { return {{(_body_for_grammar ? *_body_for_grammar : _body)}}; }
63  std::optional<spicy::Type> type() const { return {}; }
64  bool nullable() const { return production::nullable(rhss()); }
65  bool eodOk() const { return nullable(); }
66  bool atomic() const { return false; }
67  std::string render() const;
68 
69 private:
70  Production _body;
71  std::optional<Expression> _expression;
72  std::optional<Production> _body_for_grammar;
73 };
74 
75 } // namespace spicy::detail::codegen::production
While(const std::string &symbol, Expression e, Production body, const Location &l=location::None)
Definition: while.h:24
Definition: production.h:24
const production::LookAhead & lookAheadProduction() const
Definition: while.h:56
Definition: production.h:120
Definition: optional.h:79
const std::string & symbol() const
Definition: production.h:191
Definition: production.h:170
Definition: grammar.h:15
void preprocessLookAhead(Grammar *grammar)
Definition: while.cc:27
Definition: location.h:18
Definition: grammar.h:21
const auto & expression() const
Definition: while.h:36
const auto & body() const
Definition: while.h:39