Spicy
counter.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 
13 
19 public:
20  Counter(const std::string& symbol, Expression e, Production body, const Location& l = location::None)
21  : ProductionBase(symbol, l), _expression(std::move(e)), _body(std::move(body)) {}
22 
23  const Expression& expression() const { return _expression; }
24  const Production& body() const { return _body; }
25 
26  // Production API
27  std::vector<std::vector<Production>> rhss() const { return {{_body}}; }
28  std::optional<spicy::Type> type() const { return {}; }
29  bool nullable() const { return production::nullable(rhss()); }
30  bool eodOk() const { return nullable(); }
31  bool atomic() const { return false; }
32  std::string render() const { return hilti::util::fmt("counter(%s): %s", _expression, _body.symbol()); }
33 
34 private:
35  Expression _expression;
36  Production _body;
37 };
38 
39 } // namespace spicy::detail::codegen::production
Definition: production.h:24
Definition: production.h:120
const std::string & symbol() const
Definition: production.h:191
Definition: production.h:170
Definition: grammar.h:15
Definition: location.h:18
ProductionBase(std::string symbol, Location l=location::None)
Definition: production.h:181