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,32 @@
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 ShellNode : public Node {
13
+ public:
14
+ ShellNode(const Token &token, SharedPtr<String> string)
15
+ : Node { token }
16
+ , m_string { string } {
17
+ assert(m_string);
18
+ }
19
+
20
+ virtual Type type() const override { return Type::Shell; }
21
+
22
+ SharedPtr<String> string() const { return m_string; }
23
+
24
+ virtual void transform(Creator *creator) const override {
25
+ creator->set_type("xstr");
26
+ creator->append_string(m_string);
27
+ }
28
+
29
+ protected:
30
+ SharedPtr<String> m_string {};
31
+ };
32
+ }
@@ -0,0 +1,39 @@
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 SplatNode : public Node {
14
+ public:
15
+ SplatNode(const Token &token)
16
+ : Node { token } { }
17
+
18
+ SplatNode(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::Splat; }
25
+
26
+ virtual bool is_assignable() const override { return true; }
27
+
28
+ const SharedPtr<Node> node() const { return m_node; }
29
+
30
+ virtual void transform(Creator *creator) const override {
31
+ creator->set_type("splat");
32
+ if (m_node)
33
+ creator->append(m_node.ref());
34
+ }
35
+
36
+ protected:
37
+ SharedPtr<Node> m_node {};
38
+ };
39
+ }
@@ -0,0 +1,32 @@
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 SplatValueNode : public Node {
14
+ public:
15
+ SplatValueNode(const Token &token, SharedPtr<Node> value)
16
+ : Node { token }
17
+ , m_value { value } { }
18
+
19
+ virtual Type type() const override { return Type::SplatValue; }
20
+
21
+ const SharedPtr<Node> value() const { return m_value; }
22
+
23
+ virtual void transform(Creator *creator) const override {
24
+ creator->set_type("svalue");
25
+ creator->append(m_value.ref());
26
+ }
27
+
28
+ protected:
29
+ SharedPtr<Node> m_value {};
30
+ };
31
+
32
+ }
@@ -0,0 +1,29 @@
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 StabbyProcNode : public NodeWithArgs {
13
+ public:
14
+ StabbyProcNode(const Token &token, bool has_args, const Vector<SharedPtr<Node>> &args)
15
+ : NodeWithArgs { token, args }
16
+ , m_has_args { has_args } { }
17
+
18
+ virtual Type type() const override { return Type::StabbyProc; }
19
+
20
+ virtual void transform(Creator *creator) const override {
21
+ creator->set_type("lambda");
22
+ }
23
+
24
+ bool has_args() const { return m_has_args; }
25
+
26
+ private:
27
+ bool m_has_args { false };
28
+ };
29
+ }
@@ -0,0 +1,42 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/interpolated_string_node.hpp"
4
+ #include "natalie_parser/node/node.hpp"
5
+ #include "natalie_parser/node/node_with_args.hpp"
6
+ #include "natalie_parser/node/symbol_node.hpp"
7
+ #include "tm/hashmap.hpp"
8
+ #include "tm/string.hpp"
9
+
10
+ namespace NatalieParser {
11
+
12
+ using namespace TM;
13
+
14
+ class StringNode : public Node {
15
+ public:
16
+ StringNode(const Token &token, SharedPtr<String> string)
17
+ : Node { token }
18
+ , m_string { string } {
19
+ assert(m_string);
20
+ }
21
+
22
+ virtual Type type() const override { return Type::String; }
23
+
24
+ virtual bool can_be_concatenated_to_a_string() const override { return true; }
25
+
26
+ SharedPtr<String> string() const { return m_string; }
27
+
28
+ SharedPtr<SymbolNode> to_symbol_node() const {
29
+ return new SymbolNode { m_token, m_string };
30
+ }
31
+
32
+ SharedPtr<Node> append_string_node(SharedPtr<Node> string2) const;
33
+
34
+ virtual void transform(Creator *creator) const override {
35
+ creator->set_type("str");
36
+ creator->append_string(m_string);
37
+ }
38
+
39
+ protected:
40
+ SharedPtr<String> m_string {};
41
+ };
42
+ }
@@ -0,0 +1,44 @@
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 SuperNode : public NodeWithArgs {
13
+ public:
14
+ SuperNode(const Token &token)
15
+ : NodeWithArgs { token } { }
16
+
17
+ virtual Type type() const override { return Type::Super; }
18
+
19
+ virtual bool is_callable() const override { return true; }
20
+ virtual bool can_accept_a_block() const override { return true; }
21
+
22
+ bool parens() const { return m_parens; }
23
+ void set_parens(bool parens) { m_parens = parens; }
24
+
25
+ bool empty_parens() const { return m_parens && m_args.is_empty(); }
26
+
27
+ virtual void transform(Creator *creator) const override {
28
+ if (empty_parens()) {
29
+ creator->set_type("super");
30
+ return;
31
+ } else if (args().is_empty()) {
32
+ creator->set_type("zsuper");
33
+ return;
34
+ }
35
+ creator->set_type("super");
36
+ for (auto arg : args()) {
37
+ creator->append(arg);
38
+ }
39
+ }
40
+
41
+ protected:
42
+ bool m_parens { false };
43
+ };
44
+ }
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "natalie_parser/node/symbol_node.hpp"
5
+ #include "tm/string.hpp"
6
+
7
+ namespace NatalieParser {
8
+
9
+ using namespace TM;
10
+
11
+ class SymbolKeyNode : public SymbolNode {
12
+ public:
13
+ using SymbolNode::SymbolNode;
14
+
15
+ virtual Type type() const override { return Type::SymbolKey; }
16
+
17
+ virtual bool is_symbol_key() const override { return true; }
18
+ };
19
+ }
@@ -0,0 +1,30 @@
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 SymbolNode : public Node {
13
+ public:
14
+ SymbolNode(const Token &token, SharedPtr<String> name)
15
+ : Node { token }
16
+ , m_name { name } { }
17
+
18
+ virtual Type type() const override { return Type::Symbol; }
19
+
20
+ SharedPtr<String> name() const { return m_name; }
21
+
22
+ virtual void transform(Creator *creator) const override {
23
+ creator->set_type("lit");
24
+ creator->append_symbol(m_name);
25
+ }
26
+
27
+ protected:
28
+ SharedPtr<String> m_name {};
29
+ };
30
+ }
@@ -0,0 +1,33 @@
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 ToArrayNode : public Node {
14
+ public:
15
+ ToArrayNode(const Token &token, SharedPtr<Node> value)
16
+ : Node { token }
17
+ , m_value { value } {
18
+ assert(m_value);
19
+ }
20
+
21
+ virtual Type type() const override { return Type::ToArray; }
22
+
23
+ const SharedPtr<Node> value() const { return m_value; }
24
+
25
+ virtual void transform(Creator *creator) const override {
26
+ creator->set_type("to_ary");
27
+ creator->append(m_value.ref());
28
+ }
29
+
30
+ protected:
31
+ SharedPtr<Node> m_value {};
32
+ };
33
+ }
@@ -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 TrueNode : public Node {
13
+ public:
14
+ TrueNode(const Token &token)
15
+ : Node { token } { }
16
+
17
+ virtual Type type() const override { return Type::True; }
18
+
19
+ virtual void transform(Creator *creator) const override {
20
+ creator->set_type("true");
21
+ }
22
+ };
23
+ }
@@ -0,0 +1,41 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/node/node.hpp"
4
+ #include "tm/owned_ptr.hpp"
5
+ #include "tm/string.hpp"
6
+
7
+ namespace NatalieParser {
8
+
9
+ using namespace TM;
10
+
11
+ class UnaryOpNode : public Node {
12
+ public:
13
+ UnaryOpNode(const Token &token, SharedPtr<String> op, SharedPtr<Node> right)
14
+ : Node { token }
15
+ , m_op { op }
16
+ , m_right { right } {
17
+ assert(m_op);
18
+ assert(m_right);
19
+ }
20
+
21
+ virtual Type type() const override { return Type::UnaryOp; }
22
+
23
+ virtual bool is_callable() const override { return true; }
24
+ virtual bool can_accept_a_block() const override { return false; }
25
+
26
+ const SharedPtr<String> op() const { return m_op; }
27
+ const SharedPtr<Node> right() const { return m_right; }
28
+
29
+ void set_right(SharedPtr<Node> right) { m_right = right; }
30
+
31
+ virtual void transform(Creator *creator) const override {
32
+ creator->set_type("call");
33
+ creator->append(m_right.ref());
34
+ creator->append_symbol(m_op);
35
+ }
36
+
37
+ protected:
38
+ SharedPtr<String> m_op {};
39
+ SharedPtr<Node> m_right {};
40
+ };
41
+ }
@@ -0,0 +1,31 @@
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 UndefNode : public NodeWithArgs {
13
+ public:
14
+ UndefNode(const Token &token)
15
+ : NodeWithArgs { token } { }
16
+
17
+ virtual Type type() const override { return Type::Undef; }
18
+
19
+ // NOTE: UndefNode is handled separately from yield, break, etc.,
20
+ // so for our purposes here, it is not "callable".
21
+ virtual bool is_callable() const override { return false; }
22
+
23
+ virtual void transform(Creator *creator) const override {
24
+ creator->set_type("undef");
25
+ if (args().is_empty())
26
+ return;
27
+ for (auto arg : args())
28
+ creator->append(arg);
29
+ }
30
+ };
31
+ }
@@ -0,0 +1,21 @@
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 "natalie_parser/node/while_node.hpp"
7
+ #include "tm/hashmap.hpp"
8
+ #include "tm/string.hpp"
9
+
10
+ namespace NatalieParser {
11
+
12
+ using namespace TM;
13
+
14
+ class UntilNode : public WhileNode {
15
+ public:
16
+ UntilNode(const Token &token, SharedPtr<Node> condition, SharedPtr<BlockNode> body, bool pre)
17
+ : WhileNode { token, condition, body, pre } { }
18
+
19
+ virtual Type type() const override { return Type::Until; }
20
+ };
21
+ }
@@ -0,0 +1,52 @@
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 WhileNode : public Node {
15
+ public:
16
+ WhileNode(const Token &token, SharedPtr<Node> condition, SharedPtr<BlockNode> body, bool pre)
17
+ : Node { token }
18
+ , m_condition { condition }
19
+ , m_body { body }
20
+ , m_pre { pre } {
21
+ assert(m_condition);
22
+ assert(m_body);
23
+ }
24
+
25
+ virtual Type type() const override { return Type::While; }
26
+
27
+ const SharedPtr<Node> condition() const { return m_condition; }
28
+ const SharedPtr<BlockNode> body() const { return m_body; }
29
+ bool pre() const { return m_pre; }
30
+
31
+ virtual void transform(Creator *creator) const override {
32
+ if (type() == Node::Type::Until)
33
+ creator->set_type("until");
34
+ else
35
+ creator->set_type("while");
36
+ creator->append(m_condition.ref());
37
+ if (m_body->is_empty())
38
+ creator->append_nil();
39
+ else
40
+ creator->append(m_body->without_unnecessary_nesting());
41
+ if (m_pre)
42
+ creator->append_true();
43
+ else
44
+ creator->append_false();
45
+ }
46
+
47
+ protected:
48
+ SharedPtr<Node> m_condition {};
49
+ SharedPtr<BlockNode> m_body {};
50
+ bool m_pre { false };
51
+ };
52
+ }
@@ -0,0 +1,29 @@
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 YieldNode : public NodeWithArgs {
13
+ public:
14
+ YieldNode(const Token &token)
15
+ : NodeWithArgs { token } { }
16
+
17
+ virtual Type type() const override { return Type::Yield; }
18
+
19
+ virtual bool is_callable() const override { return true; }
20
+
21
+ virtual void transform(Creator *creator) const override {
22
+ creator->set_type("yield");
23
+ if (args().is_empty())
24
+ return;
25
+ for (auto arg : args())
26
+ creator->append(arg);
27
+ }
28
+ };
29
+ }
@@ -0,0 +1,89 @@
1
+ #pragma once
2
+
3
+ #include "natalie_parser/creator.hpp"
4
+ #include "natalie_parser/node/alias_node.hpp"
5
+ #include "natalie_parser/node/arg_node.hpp"
6
+ #include "natalie_parser/node/array_node.hpp"
7
+ #include "natalie_parser/node/array_pattern_node.hpp"
8
+ #include "natalie_parser/node/assignment_node.hpp"
9
+ #include "natalie_parser/node/back_ref_node.hpp"
10
+ #include "natalie_parser/node/begin_block_node.hpp"
11
+ #include "natalie_parser/node/begin_node.hpp"
12
+ #include "natalie_parser/node/begin_rescue_node.hpp"
13
+ #include "natalie_parser/node/bignum_node.hpp"
14
+ #include "natalie_parser/node/block_node.hpp"
15
+ #include "natalie_parser/node/block_pass_node.hpp"
16
+ #include "natalie_parser/node/break_node.hpp"
17
+ #include "natalie_parser/node/call_node.hpp"
18
+ #include "natalie_parser/node/case_in_node.hpp"
19
+ #include "natalie_parser/node/case_node.hpp"
20
+ #include "natalie_parser/node/case_when_node.hpp"
21
+ #include "natalie_parser/node/class_node.hpp"
22
+ #include "natalie_parser/node/colon2_node.hpp"
23
+ #include "natalie_parser/node/colon3_node.hpp"
24
+ #include "natalie_parser/node/constant_node.hpp"
25
+ #include "natalie_parser/node/def_node.hpp"
26
+ #include "natalie_parser/node/defined_node.hpp"
27
+ #include "natalie_parser/node/encoding_node.hpp"
28
+ #include "natalie_parser/node/end_block_node.hpp"
29
+ #include "natalie_parser/node/evaluate_to_string_node.hpp"
30
+ #include "natalie_parser/node/false_node.hpp"
31
+ #include "natalie_parser/node/fixnum_node.hpp"
32
+ #include "natalie_parser/node/float_node.hpp"
33
+ #include "natalie_parser/node/hash_node.hpp"
34
+ #include "natalie_parser/node/hash_pattern_node.hpp"
35
+ #include "natalie_parser/node/identifier_node.hpp"
36
+ #include "natalie_parser/node/if_node.hpp"
37
+ #include "natalie_parser/node/infix_op_node.hpp"
38
+ #include "natalie_parser/node/interpolated_node.hpp"
39
+ #include "natalie_parser/node/interpolated_regexp_node.hpp"
40
+ #include "natalie_parser/node/interpolated_shell_node.hpp"
41
+ #include "natalie_parser/node/interpolated_string_node.hpp"
42
+ #include "natalie_parser/node/interpolated_symbol_key_node.hpp"
43
+ #include "natalie_parser/node/interpolated_symbol_node.hpp"
44
+ #include "natalie_parser/node/iter_node.hpp"
45
+ #include "natalie_parser/node/keyword_arg_node.hpp"
46
+ #include "natalie_parser/node/keyword_splat_node.hpp"
47
+ #include "natalie_parser/node/logical_and_node.hpp"
48
+ #include "natalie_parser/node/logical_or_node.hpp"
49
+ #include "natalie_parser/node/match_node.hpp"
50
+ #include "natalie_parser/node/module_node.hpp"
51
+ #include "natalie_parser/node/multiple_assignment_arg_node.hpp"
52
+ #include "natalie_parser/node/multiple_assignment_node.hpp"
53
+ #include "natalie_parser/node/next_node.hpp"
54
+ #include "natalie_parser/node/nil_node.hpp"
55
+ #include "natalie_parser/node/nil_sexp_node.hpp"
56
+ #include "natalie_parser/node/node_with_args.hpp"
57
+ #include "natalie_parser/node/not_match_node.hpp"
58
+ #include "natalie_parser/node/not_node.hpp"
59
+ #include "natalie_parser/node/nth_ref_node.hpp"
60
+ #include "natalie_parser/node/op_assign_accessor_node.hpp"
61
+ #include "natalie_parser/node/op_assign_and_node.hpp"
62
+ #include "natalie_parser/node/op_assign_node.hpp"
63
+ #include "natalie_parser/node/op_assign_or_node.hpp"
64
+ #include "natalie_parser/node/pin_node.hpp"
65
+ #include "natalie_parser/node/range_node.hpp"
66
+ #include "natalie_parser/node/redo_node.hpp"
67
+ #include "natalie_parser/node/regexp_node.hpp"
68
+ #include "natalie_parser/node/retry_node.hpp"
69
+ #include "natalie_parser/node/return_node.hpp"
70
+ #include "natalie_parser/node/safe_call_node.hpp"
71
+ #include "natalie_parser/node/sclass_node.hpp"
72
+ #include "natalie_parser/node/self_node.hpp"
73
+ #include "natalie_parser/node/shadow_arg_node.hpp"
74
+ #include "natalie_parser/node/shell_node.hpp"
75
+ #include "natalie_parser/node/splat_node.hpp"
76
+ #include "natalie_parser/node/splat_value_node.hpp"
77
+ #include "natalie_parser/node/stabby_proc_node.hpp"
78
+ #include "natalie_parser/node/string_node.hpp"
79
+ #include "natalie_parser/node/super_node.hpp"
80
+ #include "natalie_parser/node/symbol_key_node.hpp"
81
+ #include "natalie_parser/node/symbol_node.hpp"
82
+ #include "natalie_parser/node/to_array_node.hpp"
83
+ #include "natalie_parser/node/true_node.hpp"
84
+ #include "natalie_parser/node/unary_op_node.hpp"
85
+ #include "natalie_parser/node/undef_node.hpp"
86
+ #include "natalie_parser/node/until_node.hpp"
87
+ #include "natalie_parser/node/while_node.hpp"
88
+ #include "natalie_parser/node/yield_node.hpp"
89
+ #include "natalie_parser/token.hpp"