MyLang
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
mylang_syntax_spec.hpp
Go to the documentation of this file.
1 #ifndef MYLANG_SYNTAX_SPEC_HPP
2 #define MYLANG_SYNTAX_SPEC_HPP
3 
4 #include <set>
5 
7 
8 namespace myparser {
9 
10 using RuleId = MP_STR("id", 2);
11 
12 using ErrorId = MP_STR("Illegal identifier", 18);
13 
14 template <class TX = void> // actually not a template
15 class NodeId: public NodeTextOrError<ErrorId> {
16 private:
17  /* const */ bool ok;
18 
19 public:
20  inline NodeId(
21  const Input &input, std::string &&value
22  ): NodeTextOrError(input, std::move(value)) {
23  static const std::set<std::string> keywords = {
24  "program", "function", "class",
25  "is", "begin", "end", "in", "out", "fast",
26  "extends", "encloses",
27  "type", "var", "const", "static", "return",
28  "if", "then", "for", "do", "foreach", "while", "elif", "else",
29  "to", "downto",
30  "repeat", "until",
31  "array", "of",
32  "or", "xor", "div", "mod", "and", "shl", "shr", "rol", "ror", "not"
33  };
34 
35  ok = keywords.find(getText()) == keywords.cend();
36  }
37 
38  // virtual ~NodeId() {}
39 
40  virtual bool accepted() const {
41  return ok;
42  }
43 };
44 
45 template <size_t I>
47 public NodeTypedProto<BuiltinSpace, NodeSpace<I>> {
48 public:
50 };
51 
52 template <>
54 public NodeTypedProto<RuleId, NodeId<>> {
55 public:
57 };
58 
59 }
60 
61 #endif
virtual bool accepted() const
Definition: mylang_syntax_spec.hpp:40
Definition: myparser_ast.hpp:229
MP_STR("id", 2) RuleId
Definition: mylang_syntax_spec.hpp:10
Definition: mylang_syntax_spec.hpp:15
bool ok
Definition: mylang_syntax_spec.hpp:17
Definition: myparser_ast.hpp:183
#define MP_STR(str, len)
Definition: myparser_str.hpp:9
Definition: myparser_ast.hpp:137
MP_STR("space", 5) BuiltinSpace
Definition: myparser_rule.hpp:10
Definition: myparser_ast.hpp:150
NodeId(const Input &input, std::string &&value)
Definition: mylang_syntax_spec.hpp:20
MP_STR("Illegal identifier", 18) ErrorId
Definition: mylang_syntax_spec.hpp:12
std::string::const_iterator Input
Definition: myparser_ast.hpp:8
Definition: myparser_ast.hpp:214
const std::string & getText() const
Definition: myparser_ast.hpp:177