Spicy
for-each.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 
16 public:
17  ForEach(const std::string& symbol, Production body, bool eod_ok, const Location& l = location::None)
18  : ProductionBase(symbol, l), _body(std::move(body)), _eod_ok(eod_ok) {}
19 
20  const Production& body() const { return _body; }
21 
22  // Production API
23  std::vector<std::vector<Production>> rhss() const { return {{_body}}; }
24  std::optional<spicy::Type> type() const { return {}; }
25  bool nullable() const { return production::nullable(rhss()); }
26  bool eodOk() const { return _eod_ok ? _eod_ok : nullable(); }
27  bool atomic() const { return false; }
28  std::string render() const { return hilti::util::fmt("foreach: %s", _body.symbol()); }
29 
30 private:
31  Production _body;
32  bool _eod_ok;
33 };
34 
35 } // 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