Spicy
sequence.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <algorithm>
6 #include <string>
7 #include <utility>
8 #include <vector>
9 
10 #include <hilti/base/util.h>
11 
12 #include <spicy/ast/types/unit.h>
13 #include <spicy/compiler/detail/codegen/production.h>
14 
16 
23 public:
24  Sequence(const std::string& symbol, std::vector<Production> prods, const Location& l = location::None)
25  : ProductionBase(symbol, l), _prods(std::move(prods)) {}
26 
27  const std::vector<Production>& sequence() const { return _prods; }
28  void add(Production p) { _prods.push_back(std::move(p)); }
29 
30  // Production API
31  std::vector<std::vector<Production>> rhss() const { return {_prods}; };
32  std::optional<spicy::Type> type() const { return {}; }
33  bool nullable() const { return production::nullable(rhss()); }
34  bool eodOk() const { return nullable(); }
35  bool atomic() const { return false; }
36  std::string render() const {
37  return hilti::util::join(hilti::util::transform(_prods, [](const auto& p) { return p.symbol(); }), " ");
38  }
39 
40 
41  std::vector<Production> _prods;
42 };
43 
44 } // 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