natalie_parser 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +22 -0
  3. data/Dockerfile +26 -0
  4. data/Gemfile +10 -0
  5. data/LICENSE +21 -0
  6. data/README.md +55 -0
  7. data/Rakefile +242 -0
  8. data/ext/natalie_parser/extconf.rb +9 -0
  9. data/ext/natalie_parser/mri_creator.hpp +139 -0
  10. data/ext/natalie_parser/natalie_parser.cpp +144 -0
  11. data/include/natalie_parser/creator/debug_creator.hpp +113 -0
  12. data/include/natalie_parser/creator.hpp +108 -0
  13. data/include/natalie_parser/lexer/interpolated_string_lexer.hpp +64 -0
  14. data/include/natalie_parser/lexer/regexp_lexer.hpp +37 -0
  15. data/include/natalie_parser/lexer/word_array_lexer.hpp +57 -0
  16. data/include/natalie_parser/lexer.hpp +135 -0
  17. data/include/natalie_parser/node/alias_node.hpp +35 -0
  18. data/include/natalie_parser/node/arg_node.hpp +74 -0
  19. data/include/natalie_parser/node/array_node.hpp +34 -0
  20. data/include/natalie_parser/node/array_pattern_node.hpp +28 -0
  21. data/include/natalie_parser/node/assignment_node.hpp +34 -0
  22. data/include/natalie_parser/node/back_ref_node.hpp +28 -0
  23. data/include/natalie_parser/node/begin_block_node.hpp +25 -0
  24. data/include/natalie_parser/node/begin_node.hpp +52 -0
  25. data/include/natalie_parser/node/begin_rescue_node.hpp +47 -0
  26. data/include/natalie_parser/node/bignum_node.hpp +37 -0
  27. data/include/natalie_parser/node/block_node.hpp +55 -0
  28. data/include/natalie_parser/node/block_pass_node.hpp +33 -0
  29. data/include/natalie_parser/node/break_node.hpp +32 -0
  30. data/include/natalie_parser/node/call_node.hpp +85 -0
  31. data/include/natalie_parser/node/case_in_node.hpp +40 -0
  32. data/include/natalie_parser/node/case_node.hpp +52 -0
  33. data/include/natalie_parser/node/case_when_node.hpp +43 -0
  34. data/include/natalie_parser/node/class_node.hpp +39 -0
  35. data/include/natalie_parser/node/colon2_node.hpp +44 -0
  36. data/include/natalie_parser/node/colon3_node.hpp +34 -0
  37. data/include/natalie_parser/node/constant_node.hpp +26 -0
  38. data/include/natalie_parser/node/def_node.hpp +55 -0
  39. data/include/natalie_parser/node/defined_node.hpp +33 -0
  40. data/include/natalie_parser/node/encoding_node.hpp +26 -0
  41. data/include/natalie_parser/node/end_block_node.hpp +25 -0
  42. data/include/natalie_parser/node/evaluate_to_string_node.hpp +37 -0
  43. data/include/natalie_parser/node/false_node.hpp +23 -0
  44. data/include/natalie_parser/node/fixnum_node.hpp +36 -0
  45. data/include/natalie_parser/node/float_node.hpp +36 -0
  46. data/include/natalie_parser/node/hash_node.hpp +34 -0
  47. data/include/natalie_parser/node/hash_pattern_node.hpp +27 -0
  48. data/include/natalie_parser/node/identifier_node.hpp +123 -0
  49. data/include/natalie_parser/node/if_node.hpp +43 -0
  50. data/include/natalie_parser/node/infix_op_node.hpp +46 -0
  51. data/include/natalie_parser/node/interpolated_node.hpp +33 -0
  52. data/include/natalie_parser/node/interpolated_regexp_node.hpp +28 -0
  53. data/include/natalie_parser/node/interpolated_shell_node.hpp +22 -0
  54. data/include/natalie_parser/node/interpolated_string_node.hpp +31 -0
  55. data/include/natalie_parser/node/interpolated_symbol_key_node.hpp +18 -0
  56. data/include/natalie_parser/node/interpolated_symbol_node.hpp +28 -0
  57. data/include/natalie_parser/node/iter_node.hpp +45 -0
  58. data/include/natalie_parser/node/keyword_arg_node.hpp +25 -0
  59. data/include/natalie_parser/node/keyword_splat_node.hpp +38 -0
  60. data/include/natalie_parser/node/logical_and_node.hpp +40 -0
  61. data/include/natalie_parser/node/logical_or_node.hpp +40 -0
  62. data/include/natalie_parser/node/match_node.hpp +38 -0
  63. data/include/natalie_parser/node/module_node.hpp +32 -0
  64. data/include/natalie_parser/node/multiple_assignment_arg_node.hpp +32 -0
  65. data/include/natalie_parser/node/multiple_assignment_node.hpp +37 -0
  66. data/include/natalie_parser/node/next_node.hpp +37 -0
  67. data/include/natalie_parser/node/nil_node.hpp +23 -0
  68. data/include/natalie_parser/node/nil_sexp_node.hpp +23 -0
  69. data/include/natalie_parser/node/node.hpp +155 -0
  70. data/include/natalie_parser/node/node_with_args.hpp +47 -0
  71. data/include/natalie_parser/node/not_match_node.hpp +35 -0
  72. data/include/natalie_parser/node/not_node.hpp +37 -0
  73. data/include/natalie_parser/node/nth_ref_node.hpp +27 -0
  74. data/include/natalie_parser/node/op_assign_accessor_node.hpp +74 -0
  75. data/include/natalie_parser/node/op_assign_and_node.hpp +34 -0
  76. data/include/natalie_parser/node/op_assign_node.hpp +47 -0
  77. data/include/natalie_parser/node/op_assign_or_node.hpp +34 -0
  78. data/include/natalie_parser/node/pin_node.hpp +33 -0
  79. data/include/natalie_parser/node/range_node.hpp +52 -0
  80. data/include/natalie_parser/node/redo_node.hpp +20 -0
  81. data/include/natalie_parser/node/regexp_node.hpp +36 -0
  82. data/include/natalie_parser/node/retry_node.hpp +20 -0
  83. data/include/natalie_parser/node/return_node.hpp +34 -0
  84. data/include/natalie_parser/node/safe_call_node.hpp +31 -0
  85. data/include/natalie_parser/node/sclass_node.hpp +37 -0
  86. data/include/natalie_parser/node/self_node.hpp +23 -0
  87. data/include/natalie_parser/node/shadow_arg_node.hpp +40 -0
  88. data/include/natalie_parser/node/shell_node.hpp +32 -0
  89. data/include/natalie_parser/node/splat_node.hpp +39 -0
  90. data/include/natalie_parser/node/splat_value_node.hpp +32 -0
  91. data/include/natalie_parser/node/stabby_proc_node.hpp +29 -0
  92. data/include/natalie_parser/node/string_node.hpp +42 -0
  93. data/include/natalie_parser/node/super_node.hpp +44 -0
  94. data/include/natalie_parser/node/symbol_key_node.hpp +19 -0
  95. data/include/natalie_parser/node/symbol_node.hpp +30 -0
  96. data/include/natalie_parser/node/to_array_node.hpp +33 -0
  97. data/include/natalie_parser/node/true_node.hpp +23 -0
  98. data/include/natalie_parser/node/unary_op_node.hpp +41 -0
  99. data/include/natalie_parser/node/undef_node.hpp +31 -0
  100. data/include/natalie_parser/node/until_node.hpp +21 -0
  101. data/include/natalie_parser/node/while_node.hpp +52 -0
  102. data/include/natalie_parser/node/yield_node.hpp +29 -0
  103. data/include/natalie_parser/node.hpp +89 -0
  104. data/include/natalie_parser/parser.hpp +218 -0
  105. data/include/natalie_parser/token.hpp +842 -0
  106. data/include/tm/defer.hpp +34 -0
  107. data/include/tm/hashmap.hpp +826 -0
  108. data/include/tm/macros.hpp +16 -0
  109. data/include/tm/optional.hpp +223 -0
  110. data/include/tm/owned_ptr.hpp +186 -0
  111. data/include/tm/recursion_guard.hpp +156 -0
  112. data/include/tm/shared_ptr.hpp +259 -0
  113. data/include/tm/string.hpp +1447 -0
  114. data/include/tm/tests.hpp +78 -0
  115. data/include/tm/vector.hpp +796 -0
  116. data/lib/natalie_parser/sexp.rb +36 -0
  117. data/lib/natalie_parser/version.rb +5 -0
  118. data/lib/natalie_parser.rb +3 -0
  119. data/natalie_parser.gemspec +23 -0
  120. data/src/lexer/interpolated_string_lexer.cpp +88 -0
  121. data/src/lexer/regexp_lexer.cpp +95 -0
  122. data/src/lexer/word_array_lexer.cpp +134 -0
  123. data/src/lexer.cpp +1703 -0
  124. data/src/node/alias_node.cpp +11 -0
  125. data/src/node/assignment_node.cpp +33 -0
  126. data/src/node/begin_node.cpp +29 -0
  127. data/src/node/begin_rescue_node.cpp +33 -0
  128. data/src/node/class_node.cpp +22 -0
  129. data/src/node/interpolated_regexp_node.cpp +19 -0
  130. data/src/node/interpolated_shell_node.cpp +25 -0
  131. data/src/node/interpolated_string_node.cpp +111 -0
  132. data/src/node/interpolated_symbol_node.cpp +25 -0
  133. data/src/node/match_node.cpp +14 -0
  134. data/src/node/module_node.cpp +21 -0
  135. data/src/node/multiple_assignment_node.cpp +37 -0
  136. data/src/node/node.cpp +10 -0
  137. data/src/node/node_with_args.cpp +35 -0
  138. data/src/node/op_assign_node.cpp +36 -0
  139. data/src/node/string_node.cpp +33 -0
  140. data/src/parser.cpp +2972 -0
  141. data/src/token.cpp +27 -0
  142. metadata +186 -0
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/interpolated_node.hpp"
4
+ #include "natalie_parser/node/interpolated_symbol_node.hpp"
5
+ #include "natalie_parser/node/node.hpp"
6
+ #include "natalie_parser/node/node_with_args.hpp"
7
+ #include "tm/hashmap.hpp"
8
+ #include "tm/string.hpp"
9
+
10
+ namespace NatalieParser {
11
+
12
+ using namespace TM;
13
+
14
+ class InterpolatedStringNode : public InterpolatedNode {
15
+ public:
16
+ InterpolatedStringNode(const Token &token)
17
+ : InterpolatedNode { token } { }
18
+
19
+ virtual Type type() const override { return Type::InterpolatedString; }
20
+
21
+ virtual bool can_be_concatenated_to_a_string() const override { return true; }
22
+
23
+ SharedPtr<InterpolatedSymbolNode> to_symbol_node() const {
24
+ return new InterpolatedSymbolNode { *this };
25
+ }
26
+
27
+ SharedPtr<Node> append_string_node(SharedPtr<Node> string2) const;
28
+
29
+ virtual void transform(Creator *creator) const override;
30
+ };
31
+ }
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/interpolated_symbol_node.hpp"
4
+
5
+ namespace NatalieParser {
6
+
7
+ using namespace TM;
8
+
9
+ class InterpolatedSymbolKeyNode : public InterpolatedSymbolNode {
10
+ public:
11
+ InterpolatedSymbolKeyNode(const InterpolatedNode &other)
12
+ : InterpolatedSymbolNode { other } { }
13
+
14
+ virtual Type type() const override { return Type::InterpolatedSymbolKey; }
15
+
16
+ virtual bool is_symbol_key() const override { return true; }
17
+ };
18
+ }
@@ -0,0 +1,28 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/interpolated_node.hpp"
4
+ #include "natalie_parser/node/node.hpp"
5
+ #include "natalie_parser/node/node_with_args.hpp"
6
+ #include "tm/hashmap.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class InterpolatedSymbolNode : public InterpolatedNode {
14
+ public:
15
+ InterpolatedSymbolNode(const Token &token)
16
+ : InterpolatedNode { token } { }
17
+
18
+ InterpolatedSymbolNode(const InterpolatedNode &other)
19
+ : InterpolatedNode { other.token() } {
20
+ for (auto node : other.nodes())
21
+ add_node(node);
22
+ }
23
+
24
+ virtual Type type() const override { return Type::InterpolatedSymbol; }
25
+
26
+ virtual void transform(Creator *creator) const override;
27
+ };
28
+ }
@@ -0,0 +1,45 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/block_node.hpp"
4
+ #include "natalie_parser/node/node.hpp"
5
+ #include "natalie_parser/node/node_with_args.hpp"
6
+ #include "tm/hashmap.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class IterNode : public NodeWithArgs {
14
+ public:
15
+ IterNode(const Token &token, SharedPtr<Node> call, bool has_args, const Vector<SharedPtr<Node>> &args, SharedPtr<BlockNode> body)
16
+ : NodeWithArgs { token, args }
17
+ , m_has_args { has_args }
18
+ , m_call { call }
19
+ , m_body { body } {
20
+ assert(m_call);
21
+ assert(m_body);
22
+ }
23
+
24
+ virtual Type type() const override { return Type::Iter; }
25
+
26
+ const SharedPtr<Node> call() const { return m_call; }
27
+ const SharedPtr<BlockNode> body() const { return m_body; }
28
+
29
+ virtual void transform(Creator *creator) const override {
30
+ creator->set_type("iter");
31
+ creator->append(m_call.ref());
32
+ if (m_has_args)
33
+ append_method_or_block_args(creator);
34
+ else
35
+ creator->append_integer(0);
36
+ if (!m_body->is_empty())
37
+ creator->append(m_body->without_unnecessary_nesting());
38
+ }
39
+
40
+ protected:
41
+ bool m_has_args { false };
42
+ SharedPtr<Node> m_call {};
43
+ SharedPtr<BlockNode> m_body {};
44
+ };
45
+ }
@@ -0,0 +1,25 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/arg_node.hpp"
4
+ #include "natalie_parser/node/node.hpp"
5
+ #include "natalie_parser/node/node_with_args.hpp"
6
+ #include "tm/hashmap.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class KeywordArgNode : public ArgNode {
14
+ public:
15
+ KeywordArgNode(const Token &token, SharedPtr<String> name)
16
+ : ArgNode { token, name } { }
17
+
18
+ virtual Type type() const override { return Type::KeywordArg; }
19
+
20
+ virtual void transform(Creator *creator) const override {
21
+ ArgNode::transform(creator);
22
+ creator->set_type("kwarg");
23
+ }
24
+ };
25
+ }
@@ -0,0 +1,38 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/node_with_args.hpp"
5
+ #include "tm/hashmap.hpp"
6
+ #include "tm/owned_ptr.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class KeywordSplatNode : public Node {
14
+ public:
15
+ KeywordSplatNode(const Token &token)
16
+ : Node { token } { }
17
+
18
+ KeywordSplatNode(const Token &token, SharedPtr<Node> node)
19
+ : Node { token }
20
+ , m_node { node } {
21
+ assert(m_node);
22
+ }
23
+
24
+ virtual Type type() const override { return Type::KeywordSplat; }
25
+
26
+ const SharedPtr<Node> node() const { return m_node; }
27
+
28
+ virtual void transform(Creator *creator) const override {
29
+ creator->set_type("kwsplat");
30
+ if (m_node)
31
+ creator->append(m_node.ref());
32
+ }
33
+
34
+ protected:
35
+ SharedPtr<Node> m_node {};
36
+ };
37
+
38
+ }
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/node_with_args.hpp"
5
+ #include "tm/hashmap.hpp"
6
+ #include "tm/owned_ptr.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class LogicalAndNode : public Node {
14
+ public:
15
+ LogicalAndNode(const Token &token, SharedPtr<Node> left, SharedPtr<Node> right)
16
+ : Node { token }
17
+ , m_left { left }
18
+ , m_right { right } {
19
+ assert(m_left);
20
+ assert(m_right);
21
+ }
22
+
23
+ virtual Type type() const override { return Type::LogicalAnd; }
24
+
25
+ const SharedPtr<Node> left() const { return m_left; }
26
+ const SharedPtr<Node> right() const { return m_right; }
27
+
28
+ void set_right(SharedPtr<Node> right) { m_right = right; }
29
+
30
+ virtual void transform(Creator *creator) const override {
31
+ creator->set_type("and");
32
+ creator->append(m_left.ref());
33
+ creator->append(m_right.ref());
34
+ }
35
+
36
+ protected:
37
+ SharedPtr<Node> m_left {};
38
+ SharedPtr<Node> m_right {};
39
+ };
40
+ }
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/node_with_args.hpp"
5
+ #include "tm/hashmap.hpp"
6
+ #include "tm/owned_ptr.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class LogicalOrNode : public Node {
14
+ public:
15
+ LogicalOrNode(const Token &token, SharedPtr<Node> left, SharedPtr<Node> right)
16
+ : Node { token }
17
+ , m_left { left }
18
+ , m_right { right } {
19
+ assert(m_left);
20
+ assert(m_right);
21
+ }
22
+
23
+ virtual Type type() const override { return Type::LogicalOr; }
24
+
25
+ const SharedPtr<Node> left() const { return m_left; }
26
+ const SharedPtr<Node> right() const { return m_right; }
27
+
28
+ void set_right(SharedPtr<Node> right) { m_right = right; }
29
+
30
+ virtual void transform(Creator *creator) const override {
31
+ creator->set_type("or");
32
+ creator->append(m_left.ref());
33
+ creator->append(m_right.ref());
34
+ }
35
+
36
+ protected:
37
+ SharedPtr<Node> m_left {};
38
+ SharedPtr<Node> m_right {};
39
+ };
40
+ }
@@ -0,0 +1,38 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/node_with_args.hpp"
5
+ #include "natalie_parser/node/regexp_node.hpp"
6
+ #include "tm/hashmap.hpp"
7
+ #include "tm/owned_ptr.hpp"
8
+ #include "tm/string.hpp"
9
+
10
+ namespace NatalieParser {
11
+
12
+ using namespace TM;
13
+
14
+ class MatchNode : public Node {
15
+ public:
16
+ MatchNode(const Token &token, SharedPtr<RegexpNode> regexp, SharedPtr<Node> arg, bool regexp_on_left)
17
+ : Node { token }
18
+ , m_regexp { regexp }
19
+ , m_arg { arg }
20
+ , m_regexp_on_left { regexp_on_left } {
21
+ assert(m_regexp);
22
+ assert(m_arg);
23
+ }
24
+
25
+ virtual Type type() const override { return Type::Match; }
26
+
27
+ const SharedPtr<RegexpNode> regexp() const { return m_regexp; }
28
+ const SharedPtr<Node> arg() const { return m_arg; }
29
+ bool regexp_on_left() const { return m_regexp_on_left; }
30
+
31
+ virtual void transform(Creator *creator) const override;
32
+
33
+ protected:
34
+ SharedPtr<RegexpNode> m_regexp {};
35
+ SharedPtr<Node> m_arg {};
36
+ bool m_regexp_on_left { false };
37
+ };
38
+ }
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/block_node.hpp"
4
+ #include "natalie_parser/node/node.hpp"
5
+ #include "natalie_parser/node/node_with_args.hpp"
6
+ #include "tm/hashmap.hpp"
7
+ #include "tm/owned_ptr.hpp"
8
+ #include "tm/string.hpp"
9
+
10
+ namespace NatalieParser {
11
+
12
+ using namespace TM;
13
+
14
+ class ModuleNode : public Node {
15
+ public:
16
+ ModuleNode(const Token &token, SharedPtr<Node> name, SharedPtr<BlockNode> body)
17
+ : Node { token }
18
+ , m_name { name }
19
+ , m_body { body } { }
20
+
21
+ virtual Type type() const override { return Type::Module; }
22
+
23
+ const SharedPtr<Node> name() const { return m_name; }
24
+ const SharedPtr<BlockNode> body() const { return m_body; }
25
+
26
+ virtual void transform(Creator *creator) const override;
27
+
28
+ protected:
29
+ SharedPtr<Node> m_name {};
30
+ SharedPtr<BlockNode> m_body {};
31
+ };
32
+ }
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/arg_node.hpp"
4
+ #include "natalie_parser/node/array_node.hpp"
5
+ #include "natalie_parser/node/node.hpp"
6
+ #include "natalie_parser/node/node_with_args.hpp"
7
+ #include "tm/hashmap.hpp"
8
+ #include "tm/string.hpp"
9
+
10
+ namespace NatalieParser {
11
+
12
+ using namespace TM;
13
+
14
+ class MultipleAssignmentArgNode : public ArrayNode {
15
+ public:
16
+ MultipleAssignmentArgNode(const Token &token)
17
+ : ArrayNode { token } { }
18
+
19
+ virtual Type type() const override { return Type::MultipleAssignmentArg; }
20
+
21
+ virtual void transform(Creator *creator) const override {
22
+ creator->set_type("masgn");
23
+ for (auto arg : nodes()) {
24
+ if (arg->type() == Node::Type::Arg) {
25
+ arg.static_cast_as<ArgNode>()->append_name(creator);
26
+ } else {
27
+ creator->append(arg);
28
+ }
29
+ }
30
+ }
31
+ };
32
+ }
@@ -0,0 +1,37 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/array_node.hpp"
4
+ #include "natalie_parser/node/node.hpp"
5
+ #include "natalie_parser/node/node_with_args.hpp"
6
+ #include "tm/hashmap.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class MultipleAssignmentNode : public ArrayNode {
14
+ public:
15
+ MultipleAssignmentNode(const Token &token)
16
+ : ArrayNode { token } { }
17
+
18
+ virtual Type type() const override { return Type::MultipleAssignment; }
19
+
20
+ virtual bool is_assignable() const override { return true; }
21
+
22
+ void add_locals(TM::Hashmap<TM::String> &);
23
+
24
+ virtual void transform(Creator *creator) const override {
25
+ creator->with_assignment(true, [&]() {
26
+ creator->set_type("masgn");
27
+ creator->append_array(*this);
28
+ });
29
+ }
30
+
31
+ int depth() { return m_depth; }
32
+ int increment_depth() { return ++m_depth; }
33
+
34
+ private:
35
+ int m_depth { 0 };
36
+ };
37
+ }
@@ -0,0 +1,37 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/node_with_args.hpp"
5
+ #include "tm/hashmap.hpp"
6
+ #include "tm/owned_ptr.hpp"
7
+ #include "tm/string.hpp"
8
+
9
+ namespace NatalieParser {
10
+
11
+ using namespace TM;
12
+
13
+ class NextNode : public Node {
14
+ public:
15
+ NextNode(const Token &token, SharedPtr<Node> arg = {})
16
+ : Node { token }
17
+ , m_arg { arg } {
18
+ }
19
+
20
+ virtual Type type() const override { return Type::Next; }
21
+
22
+ const Node &arg() const {
23
+ if (m_arg)
24
+ return m_arg.ref();
25
+ return Node::invalid();
26
+ }
27
+
28
+ virtual void transform(Creator *creator) const override {
29
+ creator->set_type("next");
30
+ if (m_arg)
31
+ creator->append(m_arg.ref());
32
+ }
33
+
34
+ protected:
35
+ SharedPtr<Node> m_arg {};
36
+ };
37
+ }
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/node_with_args.hpp"
5
+ #include "tm/hashmap.hpp"
6
+ #include "tm/string.hpp"
7
+
8
+ namespace NatalieParser {
9
+
10
+ using namespace TM;
11
+
12
+ class NilNode : public Node {
13
+ public:
14
+ NilNode(const Token &token)
15
+ : Node { token } { }
16
+
17
+ virtual Type type() const override { return Type::Nil; }
18
+
19
+ virtual void transform(Creator *creator) const override {
20
+ creator->set_type("nil");
21
+ }
22
+ };
23
+ }
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/node_with_args.hpp"
5
+ #include "tm/hashmap.hpp"
6
+ #include "tm/string.hpp"
7
+
8
+ namespace NatalieParser {
9
+
10
+ using namespace TM;
11
+
12
+ class NilSexpNode : public Node {
13
+ public:
14
+ NilSexpNode(const Token &token)
15
+ : Node { token } { }
16
+
17
+ virtual Type type() const override { return Type::NilSexp; }
18
+
19
+ virtual void transform(Creator *creator) const override {
20
+ creator->set_type("nil");
21
+ }
22
+ };
23
+ }
@@ -0,0 +1,155 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/creator.hpp"
4
+ #include "natalie_parser/token.hpp"
5
+
6
+ namespace NatalieParser {
7
+
8
+ class NodeWithArgs;
9
+
10
+ class BlockNode;
11
+
12
+ class Node {
13
+ public:
14
+ enum class Type {
15
+ Invalid,
16
+ Alias,
17
+ Arg,
18
+ Array,
19
+ ArrayPattern,
20
+ Assignment,
21
+ BackRef,
22
+ Begin,
23
+ BeginBlock,
24
+ BeginRescue,
25
+ Bignum,
26
+ Block,
27
+ BlockPass,
28
+ Break,
29
+ Call,
30
+ Case,
31
+ CaseIn,
32
+ CaseWhen,
33
+ Class,
34
+ Colon2,
35
+ Colon3,
36
+ Constant,
37
+ Def,
38
+ Defined,
39
+ Encoding,
40
+ EndBlock,
41
+ EvaluateToString,
42
+ False,
43
+ Fixnum,
44
+ Float,
45
+ Hash,
46
+ HashPattern,
47
+ Identifier,
48
+ If,
49
+ InfixOp,
50
+ Iter,
51
+ InterpolatedRegexp,
52
+ InterpolatedShell,
53
+ InterpolatedString,
54
+ InterpolatedSymbol,
55
+ InterpolatedSymbolKey,
56
+ KeywordArg,
57
+ KeywordSplat,
58
+ LogicalAnd,
59
+ LogicalOr,
60
+ Match,
61
+ Module,
62
+ MultipleAssignment,
63
+ MultipleAssignmentArg,
64
+ Next,
65
+ Nil,
66
+ NilSexp,
67
+ Not,
68
+ NotMatch,
69
+ NthRef,
70
+ OpAssign,
71
+ OpAssignAccessor,
72
+ OpAssignAnd,
73
+ OpAssignOr,
74
+ Pin,
75
+ Range,
76
+ Redo,
77
+ Regexp,
78
+ Retry,
79
+ Return,
80
+ SafeCall,
81
+ Sclass,
82
+ Self,
83
+ ShadowArg,
84
+ Shell,
85
+ Splat,
86
+ SplatValue,
87
+ StabbyProc,
88
+ String,
89
+ Super,
90
+ Symbol,
91
+ SymbolKey,
92
+ ToArray,
93
+ True,
94
+ UnaryOp,
95
+ Undef,
96
+ Until,
97
+ While,
98
+ Yield,
99
+ };
100
+
101
+ Node() { }
102
+
103
+ Node(const Token &token)
104
+ : m_token { token } { }
105
+
106
+ Node(const Node &) = delete;
107
+ Node &operator=(const Node &) = delete;
108
+
109
+ virtual ~Node() { }
110
+
111
+ virtual Type type() const { return Type::Invalid; }
112
+
113
+ virtual bool is_callable() const { return false; }
114
+ virtual bool is_assignable() const { return false; }
115
+ virtual bool is_numeric() const { return false; }
116
+ virtual bool is_symbol_key() const { return false; }
117
+ virtual bool can_accept_a_block() const { return false; }
118
+ virtual bool can_be_concatenated_to_a_string() const { return false; }
119
+ virtual bool has_block_pass() const { return false; }
120
+
121
+ BlockNode &as_block_node();
122
+
123
+ virtual void transform(Creator *creator) const {
124
+ creator->set_type("NOT_YET_IMPLEMENTED");
125
+ creator->append_integer((int)type());
126
+ }
127
+
128
+ SharedPtr<String> file() const { return m_token.file(); }
129
+
130
+ size_t line() const { return m_token.line(); }
131
+ void set_line(size_t line) { m_token.set_line(line); }
132
+
133
+ size_t column() const { return m_token.column(); }
134
+ void set_column(size_t column) { m_token.set_column(column); }
135
+
136
+ Optional<SharedPtr<String>> doc() const { return m_token.doc(); }
137
+
138
+ const Token &token() const { return m_token; }
139
+
140
+ const static Node &invalid() {
141
+ if (!s_invalid)
142
+ s_invalid = new Node;
143
+ return *s_invalid;
144
+ }
145
+
146
+ operator bool() const {
147
+ return type() != Type::Invalid;
148
+ }
149
+
150
+ protected:
151
+ static inline SharedPtr<Node> s_invalid {};
152
+ Token m_token {};
153
+ };
154
+
155
+ }