natalie_parser 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -0
- data/Dockerfile +26 -0
- data/Gemfile +10 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/Rakefile +242 -0
- data/ext/natalie_parser/extconf.rb +9 -0
- data/ext/natalie_parser/mri_creator.hpp +139 -0
- data/ext/natalie_parser/natalie_parser.cpp +144 -0
- data/include/natalie_parser/creator/debug_creator.hpp +113 -0
- data/include/natalie_parser/creator.hpp +108 -0
- data/include/natalie_parser/lexer/interpolated_string_lexer.hpp +64 -0
- data/include/natalie_parser/lexer/regexp_lexer.hpp +37 -0
- data/include/natalie_parser/lexer/word_array_lexer.hpp +57 -0
- data/include/natalie_parser/lexer.hpp +135 -0
- data/include/natalie_parser/node/alias_node.hpp +35 -0
- data/include/natalie_parser/node/arg_node.hpp +74 -0
- data/include/natalie_parser/node/array_node.hpp +34 -0
- data/include/natalie_parser/node/array_pattern_node.hpp +28 -0
- data/include/natalie_parser/node/assignment_node.hpp +34 -0
- data/include/natalie_parser/node/back_ref_node.hpp +28 -0
- data/include/natalie_parser/node/begin_block_node.hpp +25 -0
- data/include/natalie_parser/node/begin_node.hpp +52 -0
- data/include/natalie_parser/node/begin_rescue_node.hpp +47 -0
- data/include/natalie_parser/node/bignum_node.hpp +37 -0
- data/include/natalie_parser/node/block_node.hpp +55 -0
- data/include/natalie_parser/node/block_pass_node.hpp +33 -0
- data/include/natalie_parser/node/break_node.hpp +32 -0
- data/include/natalie_parser/node/call_node.hpp +85 -0
- data/include/natalie_parser/node/case_in_node.hpp +40 -0
- data/include/natalie_parser/node/case_node.hpp +52 -0
- data/include/natalie_parser/node/case_when_node.hpp +43 -0
- data/include/natalie_parser/node/class_node.hpp +39 -0
- data/include/natalie_parser/node/colon2_node.hpp +44 -0
- data/include/natalie_parser/node/colon3_node.hpp +34 -0
- data/include/natalie_parser/node/constant_node.hpp +26 -0
- data/include/natalie_parser/node/def_node.hpp +55 -0
- data/include/natalie_parser/node/defined_node.hpp +33 -0
- data/include/natalie_parser/node/encoding_node.hpp +26 -0
- data/include/natalie_parser/node/end_block_node.hpp +25 -0
- data/include/natalie_parser/node/evaluate_to_string_node.hpp +37 -0
- data/include/natalie_parser/node/false_node.hpp +23 -0
- data/include/natalie_parser/node/fixnum_node.hpp +36 -0
- data/include/natalie_parser/node/float_node.hpp +36 -0
- data/include/natalie_parser/node/hash_node.hpp +34 -0
- data/include/natalie_parser/node/hash_pattern_node.hpp +27 -0
- data/include/natalie_parser/node/identifier_node.hpp +123 -0
- data/include/natalie_parser/node/if_node.hpp +43 -0
- data/include/natalie_parser/node/infix_op_node.hpp +46 -0
- data/include/natalie_parser/node/interpolated_node.hpp +33 -0
- data/include/natalie_parser/node/interpolated_regexp_node.hpp +28 -0
- data/include/natalie_parser/node/interpolated_shell_node.hpp +22 -0
- data/include/natalie_parser/node/interpolated_string_node.hpp +31 -0
- data/include/natalie_parser/node/interpolated_symbol_key_node.hpp +18 -0
- data/include/natalie_parser/node/interpolated_symbol_node.hpp +28 -0
- data/include/natalie_parser/node/iter_node.hpp +45 -0
- data/include/natalie_parser/node/keyword_arg_node.hpp +25 -0
- data/include/natalie_parser/node/keyword_splat_node.hpp +38 -0
- data/include/natalie_parser/node/logical_and_node.hpp +40 -0
- data/include/natalie_parser/node/logical_or_node.hpp +40 -0
- data/include/natalie_parser/node/match_node.hpp +38 -0
- data/include/natalie_parser/node/module_node.hpp +32 -0
- data/include/natalie_parser/node/multiple_assignment_arg_node.hpp +32 -0
- data/include/natalie_parser/node/multiple_assignment_node.hpp +37 -0
- data/include/natalie_parser/node/next_node.hpp +37 -0
- data/include/natalie_parser/node/nil_node.hpp +23 -0
- data/include/natalie_parser/node/nil_sexp_node.hpp +23 -0
- data/include/natalie_parser/node/node.hpp +155 -0
- data/include/natalie_parser/node/node_with_args.hpp +47 -0
- data/include/natalie_parser/node/not_match_node.hpp +35 -0
- data/include/natalie_parser/node/not_node.hpp +37 -0
- data/include/natalie_parser/node/nth_ref_node.hpp +27 -0
- data/include/natalie_parser/node/op_assign_accessor_node.hpp +74 -0
- data/include/natalie_parser/node/op_assign_and_node.hpp +34 -0
- data/include/natalie_parser/node/op_assign_node.hpp +47 -0
- data/include/natalie_parser/node/op_assign_or_node.hpp +34 -0
- data/include/natalie_parser/node/pin_node.hpp +33 -0
- data/include/natalie_parser/node/range_node.hpp +52 -0
- data/include/natalie_parser/node/redo_node.hpp +20 -0
- data/include/natalie_parser/node/regexp_node.hpp +36 -0
- data/include/natalie_parser/node/retry_node.hpp +20 -0
- data/include/natalie_parser/node/return_node.hpp +34 -0
- data/include/natalie_parser/node/safe_call_node.hpp +31 -0
- data/include/natalie_parser/node/sclass_node.hpp +37 -0
- data/include/natalie_parser/node/self_node.hpp +23 -0
- data/include/natalie_parser/node/shadow_arg_node.hpp +40 -0
- data/include/natalie_parser/node/shell_node.hpp +32 -0
- data/include/natalie_parser/node/splat_node.hpp +39 -0
- data/include/natalie_parser/node/splat_value_node.hpp +32 -0
- data/include/natalie_parser/node/stabby_proc_node.hpp +29 -0
- data/include/natalie_parser/node/string_node.hpp +42 -0
- data/include/natalie_parser/node/super_node.hpp +44 -0
- data/include/natalie_parser/node/symbol_key_node.hpp +19 -0
- data/include/natalie_parser/node/symbol_node.hpp +30 -0
- data/include/natalie_parser/node/to_array_node.hpp +33 -0
- data/include/natalie_parser/node/true_node.hpp +23 -0
- data/include/natalie_parser/node/unary_op_node.hpp +41 -0
- data/include/natalie_parser/node/undef_node.hpp +31 -0
- data/include/natalie_parser/node/until_node.hpp +21 -0
- data/include/natalie_parser/node/while_node.hpp +52 -0
- data/include/natalie_parser/node/yield_node.hpp +29 -0
- data/include/natalie_parser/node.hpp +89 -0
- data/include/natalie_parser/parser.hpp +218 -0
- data/include/natalie_parser/token.hpp +842 -0
- data/include/tm/defer.hpp +34 -0
- data/include/tm/hashmap.hpp +826 -0
- data/include/tm/macros.hpp +16 -0
- data/include/tm/optional.hpp +223 -0
- data/include/tm/owned_ptr.hpp +186 -0
- data/include/tm/recursion_guard.hpp +156 -0
- data/include/tm/shared_ptr.hpp +259 -0
- data/include/tm/string.hpp +1447 -0
- data/include/tm/tests.hpp +78 -0
- data/include/tm/vector.hpp +796 -0
- data/lib/natalie_parser/sexp.rb +36 -0
- data/lib/natalie_parser/version.rb +5 -0
- data/lib/natalie_parser.rb +3 -0
- data/natalie_parser.gemspec +23 -0
- data/src/lexer/interpolated_string_lexer.cpp +88 -0
- data/src/lexer/regexp_lexer.cpp +95 -0
- data/src/lexer/word_array_lexer.cpp +134 -0
- data/src/lexer.cpp +1703 -0
- data/src/node/alias_node.cpp +11 -0
- data/src/node/assignment_node.cpp +33 -0
- data/src/node/begin_node.cpp +29 -0
- data/src/node/begin_rescue_node.cpp +33 -0
- data/src/node/class_node.cpp +22 -0
- data/src/node/interpolated_regexp_node.cpp +19 -0
- data/src/node/interpolated_shell_node.cpp +25 -0
- data/src/node/interpolated_string_node.cpp +111 -0
- data/src/node/interpolated_symbol_node.cpp +25 -0
- data/src/node/match_node.cpp +14 -0
- data/src/node/module_node.cpp +21 -0
- data/src/node/multiple_assignment_node.cpp +37 -0
- data/src/node/node.cpp +10 -0
- data/src/node/node_with_args.cpp +35 -0
- data/src/node/op_assign_node.cpp +36 -0
- data/src/node/string_node.cpp +33 -0
- data/src/parser.cpp +2972 -0
- data/src/token.cpp +27 -0
- metadata +186 -0
|
@@ -0,0 +1,34 @@
|
|
|
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 AssignmentNode : public Node {
|
|
14
|
+
public:
|
|
15
|
+
AssignmentNode(const Token &token, SharedPtr<Node> identifier, SharedPtr<Node> value)
|
|
16
|
+
: Node { token }
|
|
17
|
+
, m_identifier { identifier }
|
|
18
|
+
, m_value { value } {
|
|
19
|
+
assert(m_identifier);
|
|
20
|
+
assert(m_value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
virtual Type type() const override { return Type::Assignment; }
|
|
24
|
+
|
|
25
|
+
const SharedPtr<Node> identifier() const { return m_identifier; }
|
|
26
|
+
const SharedPtr<Node> value() const { return m_value; }
|
|
27
|
+
|
|
28
|
+
virtual void transform(Creator *creator) const override;
|
|
29
|
+
|
|
30
|
+
protected:
|
|
31
|
+
SharedPtr<Node> m_identifier {};
|
|
32
|
+
SharedPtr<Node> m_value {};
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "natalie_parser/node/node.hpp"
|
|
4
|
+
|
|
5
|
+
namespace NatalieParser {
|
|
6
|
+
|
|
7
|
+
using namespace TM;
|
|
8
|
+
|
|
9
|
+
class BackRefNode : public Node {
|
|
10
|
+
public:
|
|
11
|
+
BackRefNode(const Token &token, char ref_type)
|
|
12
|
+
: Node { token }
|
|
13
|
+
, m_ref_type { ref_type } { }
|
|
14
|
+
|
|
15
|
+
virtual Type type() const override { return Type::BackRef; }
|
|
16
|
+
|
|
17
|
+
char ref_type() const { return m_ref_type; }
|
|
18
|
+
|
|
19
|
+
virtual void transform(Creator *creator) const override {
|
|
20
|
+
creator->set_type("back_ref");
|
|
21
|
+
auto type = String(m_ref_type);
|
|
22
|
+
creator->append_symbol(type);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected:
|
|
26
|
+
char m_ref_type { 0 };
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 BeginBlockNode : public Node {
|
|
13
|
+
public:
|
|
14
|
+
BeginBlockNode(const Token &token)
|
|
15
|
+
: Node { token } { }
|
|
16
|
+
|
|
17
|
+
virtual Type type() const override { return Type::BeginBlock; }
|
|
18
|
+
|
|
19
|
+
virtual bool can_accept_a_block() const override { return true; }
|
|
20
|
+
|
|
21
|
+
virtual void transform(Creator *creator) const override {
|
|
22
|
+
creator->set_type("preexe");
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "natalie_parser/node/begin_rescue_node.hpp"
|
|
4
|
+
#include "natalie_parser/node/block_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/owned_ptr.hpp"
|
|
9
|
+
#include "tm/string.hpp"
|
|
10
|
+
|
|
11
|
+
namespace NatalieParser {
|
|
12
|
+
|
|
13
|
+
using namespace TM;
|
|
14
|
+
|
|
15
|
+
class BeginNode : public Node {
|
|
16
|
+
public:
|
|
17
|
+
BeginNode(const Token &token, SharedPtr<BlockNode> body)
|
|
18
|
+
: Node { token }
|
|
19
|
+
, m_body { body } {
|
|
20
|
+
assert(m_body);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
virtual Type type() const override { return Type::Begin; }
|
|
24
|
+
|
|
25
|
+
bool can_be_simple_block() const {
|
|
26
|
+
return !has_rescue_nodes() && !has_else_body() && !has_ensure_body();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void add_rescue_node(SharedPtr<BeginRescueNode> node) { m_rescue_nodes.push(node); }
|
|
30
|
+
bool has_rescue_nodes() const { return !m_rescue_nodes.is_empty(); }
|
|
31
|
+
|
|
32
|
+
bool has_else_body() const { return m_else_body ? true : false; }
|
|
33
|
+
bool has_ensure_body() const { return m_ensure_body ? true : false; }
|
|
34
|
+
|
|
35
|
+
void set_else_body(SharedPtr<BlockNode> else_body) { m_else_body = else_body; }
|
|
36
|
+
void set_ensure_body(SharedPtr<BlockNode> ensure_body) { m_ensure_body = ensure_body; }
|
|
37
|
+
|
|
38
|
+
const SharedPtr<BlockNode> body() const { return m_body; }
|
|
39
|
+
const SharedPtr<BlockNode> else_body() const { return m_else_body; }
|
|
40
|
+
const SharedPtr<BlockNode> ensure_body() const { return m_ensure_body; }
|
|
41
|
+
|
|
42
|
+
const Vector<SharedPtr<BeginRescueNode>> &rescue_nodes() const { return m_rescue_nodes; }
|
|
43
|
+
|
|
44
|
+
virtual void transform(Creator *creator) const override;
|
|
45
|
+
|
|
46
|
+
protected:
|
|
47
|
+
SharedPtr<BlockNode> m_body {};
|
|
48
|
+
SharedPtr<BlockNode> m_else_body {};
|
|
49
|
+
SharedPtr<BlockNode> m_ensure_body {};
|
|
50
|
+
Vector<SharedPtr<BeginRescueNode>> m_rescue_nodes {};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "natalie_parser/node/block_node.hpp"
|
|
4
|
+
#include "natalie_parser/node/identifier_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/owned_ptr.hpp"
|
|
9
|
+
#include "tm/string.hpp"
|
|
10
|
+
|
|
11
|
+
namespace NatalieParser {
|
|
12
|
+
|
|
13
|
+
using namespace TM;
|
|
14
|
+
|
|
15
|
+
class BeginRescueNode : public Node {
|
|
16
|
+
public:
|
|
17
|
+
BeginRescueNode(const Token &token)
|
|
18
|
+
: Node { token } { }
|
|
19
|
+
|
|
20
|
+
virtual Type type() const override { return Type::BeginRescue; }
|
|
21
|
+
|
|
22
|
+
void add_exception_node(SharedPtr<Node> node) {
|
|
23
|
+
m_exceptions.push(node);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void set_exception_name(SharedPtr<IdentifierNode> name) {
|
|
27
|
+
m_name = name;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void set_body(SharedPtr<BlockNode> body) { m_body = body; }
|
|
31
|
+
|
|
32
|
+
SharedPtr<Node> name_to_node() const;
|
|
33
|
+
|
|
34
|
+
bool has_name() const { return m_name; }
|
|
35
|
+
|
|
36
|
+
const SharedPtr<IdentifierNode> name() const { return m_name; }
|
|
37
|
+
const Vector<SharedPtr<Node>> &exceptions() const { return m_exceptions; }
|
|
38
|
+
const SharedPtr<BlockNode> body() const { return m_body; }
|
|
39
|
+
|
|
40
|
+
virtual void transform(Creator *creator) const override;
|
|
41
|
+
|
|
42
|
+
protected:
|
|
43
|
+
SharedPtr<IdentifierNode> m_name {};
|
|
44
|
+
Vector<SharedPtr<Node>> m_exceptions {};
|
|
45
|
+
SharedPtr<BlockNode> m_body {};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -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/string.hpp"
|
|
7
|
+
|
|
8
|
+
namespace NatalieParser {
|
|
9
|
+
|
|
10
|
+
using namespace TM;
|
|
11
|
+
|
|
12
|
+
class BignumNode : public Node {
|
|
13
|
+
public:
|
|
14
|
+
BignumNode(const Token &token, SharedPtr<String> number)
|
|
15
|
+
: Node { token }
|
|
16
|
+
, m_number { number } { }
|
|
17
|
+
|
|
18
|
+
virtual Type type() const override { return Type::Bignum; }
|
|
19
|
+
|
|
20
|
+
virtual bool is_numeric() const override { return true; }
|
|
21
|
+
|
|
22
|
+
SharedPtr<String> number() const { return m_number; }
|
|
23
|
+
|
|
24
|
+
virtual void transform(Creator *creator) const override {
|
|
25
|
+
creator->set_type("lit");
|
|
26
|
+
creator->append_integer(*m_number);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void negate() {
|
|
30
|
+
assert(m_number->at(0) != '-');
|
|
31
|
+
m_number->prepend_char('-');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected:
|
|
35
|
+
SharedPtr<String> m_number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 BlockNode : public Node {
|
|
13
|
+
public:
|
|
14
|
+
BlockNode(const Token &token)
|
|
15
|
+
: Node { token } { }
|
|
16
|
+
|
|
17
|
+
BlockNode(const Token &token, SharedPtr<Node> single_node)
|
|
18
|
+
: Node { token } {
|
|
19
|
+
add_node(single_node);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
virtual Type type() const override { return Type::Block; }
|
|
23
|
+
|
|
24
|
+
const Vector<SharedPtr<Node>> &nodes() const { return m_nodes; }
|
|
25
|
+
|
|
26
|
+
void add_node(SharedPtr<Node> node) {
|
|
27
|
+
m_nodes.push(node);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
SharedPtr<Node> take_first_node() {
|
|
31
|
+
return m_nodes.pop_front();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
bool is_empty() const { return m_nodes.is_empty(); }
|
|
35
|
+
|
|
36
|
+
bool has_one_node() const { return m_nodes.size() == 1; }
|
|
37
|
+
SharedPtr<Node> first() const { return m_nodes.at(0); }
|
|
38
|
+
|
|
39
|
+
const Node &without_unnecessary_nesting() const {
|
|
40
|
+
if (has_one_node())
|
|
41
|
+
return *first();
|
|
42
|
+
else
|
|
43
|
+
return *this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
virtual void transform(Creator *creator) const override {
|
|
47
|
+
creator->set_type("block");
|
|
48
|
+
for (auto node : m_nodes)
|
|
49
|
+
creator->append(node);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected:
|
|
53
|
+
Vector<SharedPtr<Node>> m_nodes {};
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -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 BlockPassNode : public Node {
|
|
14
|
+
public:
|
|
15
|
+
BlockPassNode(const Token &token, SharedPtr<Node> node)
|
|
16
|
+
: Node { token }
|
|
17
|
+
, m_node { node } {
|
|
18
|
+
assert(m_node);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
virtual Type type() const override { return Type::BlockPass; }
|
|
22
|
+
|
|
23
|
+
const SharedPtr<Node> node() const { return m_node; }
|
|
24
|
+
|
|
25
|
+
virtual void transform(Creator *creator) const override {
|
|
26
|
+
creator->set_type("block_pass");
|
|
27
|
+
creator->append(m_node.ref());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected:
|
|
31
|
+
SharedPtr<Node> m_node {};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -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 BreakNode : public NodeWithArgs {
|
|
14
|
+
public:
|
|
15
|
+
BreakNode(const Token &token, SharedPtr<Node> arg = {})
|
|
16
|
+
: NodeWithArgs { token }
|
|
17
|
+
, m_arg { arg } { }
|
|
18
|
+
|
|
19
|
+
virtual Type type() const override { return Type::Break; }
|
|
20
|
+
|
|
21
|
+
const SharedPtr<Node> arg() const { return m_arg; }
|
|
22
|
+
|
|
23
|
+
virtual void transform(Creator *creator) const override {
|
|
24
|
+
creator->set_type("break");
|
|
25
|
+
if (m_arg)
|
|
26
|
+
creator->append(m_arg.ref());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected:
|
|
30
|
+
SharedPtr<Node> m_arg {};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 CallNode : public NodeWithArgs {
|
|
14
|
+
public:
|
|
15
|
+
CallNode(const Token &token, SharedPtr<Node> receiver, SharedPtr<String> message)
|
|
16
|
+
: NodeWithArgs { token }
|
|
17
|
+
, m_receiver { receiver }
|
|
18
|
+
, m_message { message } {
|
|
19
|
+
assert(m_receiver);
|
|
20
|
+
assert(m_message);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
CallNode(const Token &token, CallNode &node)
|
|
24
|
+
: NodeWithArgs { token }
|
|
25
|
+
, m_receiver { node.receiver() }
|
|
26
|
+
, m_message { node.m_message } {
|
|
27
|
+
for (auto arg : node.m_args) {
|
|
28
|
+
add_arg(arg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
virtual Type type() const override { return Type::Call; }
|
|
33
|
+
|
|
34
|
+
virtual bool is_assignable() const override {
|
|
35
|
+
return *m_message == "[]" || m_args.is_empty();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
virtual bool is_callable() const override { return true; }
|
|
39
|
+
|
|
40
|
+
virtual bool can_accept_a_block() const override {
|
|
41
|
+
if (*m_message == "private" || *m_message == "protected" || *m_message == "public")
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const SharedPtr<Node> receiver() const { return m_receiver; }
|
|
47
|
+
void set_receiver(SharedPtr<Node> receiver) { m_receiver = receiver; }
|
|
48
|
+
|
|
49
|
+
SharedPtr<String> message() const { return m_message; }
|
|
50
|
+
|
|
51
|
+
void set_message(SharedPtr<String> message) {
|
|
52
|
+
assert(message);
|
|
53
|
+
m_message = message;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void set_message(const char *message) {
|
|
57
|
+
assert(message);
|
|
58
|
+
m_message = new String(message);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
virtual void transform(Creator *creator) const override {
|
|
62
|
+
if (creator->assignment()) {
|
|
63
|
+
creator->set_type("attrasgn");
|
|
64
|
+
creator->with_assignment(false, [&]() {
|
|
65
|
+
creator->append(m_receiver.ref());
|
|
66
|
+
});
|
|
67
|
+
auto message = m_message->clone();
|
|
68
|
+
message.append_char('=');
|
|
69
|
+
creator->append_symbol(message);
|
|
70
|
+
} else {
|
|
71
|
+
creator->set_type("call");
|
|
72
|
+
creator->append(m_receiver.ref());
|
|
73
|
+
creator->append_symbol(m_message);
|
|
74
|
+
}
|
|
75
|
+
creator->with_assignment(false, [&]() {
|
|
76
|
+
for (auto arg : args())
|
|
77
|
+
creator->append(arg);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected:
|
|
82
|
+
SharedPtr<Node> m_receiver {};
|
|
83
|
+
SharedPtr<String> m_message {};
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 CaseInNode : public Node {
|
|
15
|
+
public:
|
|
16
|
+
CaseInNode(const Token &token, SharedPtr<Node> pattern, SharedPtr<BlockNode> body)
|
|
17
|
+
: Node { token }
|
|
18
|
+
, m_pattern { pattern }
|
|
19
|
+
, m_body { body } {
|
|
20
|
+
assert(m_pattern);
|
|
21
|
+
assert(m_body);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
virtual Type type() const override { return Type::CaseIn; }
|
|
25
|
+
|
|
26
|
+
const SharedPtr<Node> pattern() const { return m_pattern; }
|
|
27
|
+
const SharedPtr<BlockNode> body() const { return m_body; }
|
|
28
|
+
|
|
29
|
+
virtual void transform(Creator *creator) const override {
|
|
30
|
+
creator->set_type("in");
|
|
31
|
+
creator->append(m_pattern.ref());
|
|
32
|
+
for (auto node : m_body->nodes())
|
|
33
|
+
creator->append(node);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected:
|
|
37
|
+
SharedPtr<Node> m_pattern {};
|
|
38
|
+
SharedPtr<BlockNode> m_body {};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -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 CaseNode : public Node {
|
|
15
|
+
public:
|
|
16
|
+
CaseNode(const Token &token, SharedPtr<Node> subject)
|
|
17
|
+
: Node { token }
|
|
18
|
+
, m_subject { subject } {
|
|
19
|
+
assert(m_subject);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
virtual Type type() const override { return Type::Case; }
|
|
23
|
+
|
|
24
|
+
void add_node(SharedPtr<Node> node) {
|
|
25
|
+
m_nodes.push(node);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void set_else_node(SharedPtr<BlockNode> node) {
|
|
29
|
+
m_else_node = node;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const SharedPtr<Node> subject() const { return m_subject; }
|
|
33
|
+
Vector<SharedPtr<Node>> &nodes() { return m_nodes; }
|
|
34
|
+
const SharedPtr<BlockNode> else_node() const { return m_else_node; }
|
|
35
|
+
|
|
36
|
+
virtual void transform(Creator *creator) const override {
|
|
37
|
+
creator->set_type("case");
|
|
38
|
+
creator->append(m_subject.ref());
|
|
39
|
+
for (auto when_node : m_nodes)
|
|
40
|
+
creator->append(when_node);
|
|
41
|
+
if (m_else_node)
|
|
42
|
+
creator->append(m_else_node->without_unnecessary_nesting());
|
|
43
|
+
else
|
|
44
|
+
creator->append_nil();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected:
|
|
48
|
+
SharedPtr<Node> m_subject {};
|
|
49
|
+
Vector<SharedPtr<Node>> m_nodes {};
|
|
50
|
+
SharedPtr<BlockNode> m_else_node {};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 CaseWhenNode : public Node {
|
|
15
|
+
public:
|
|
16
|
+
CaseWhenNode(const Token &token, SharedPtr<Node> condition, SharedPtr<BlockNode> body)
|
|
17
|
+
: Node { token }
|
|
18
|
+
, m_condition { condition }
|
|
19
|
+
, m_body { body } {
|
|
20
|
+
assert(m_condition);
|
|
21
|
+
assert(m_body);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
virtual Type type() const override { return Type::CaseWhen; }
|
|
25
|
+
|
|
26
|
+
const SharedPtr<Node> condition() const { return m_condition; }
|
|
27
|
+
const SharedPtr<BlockNode> body() const { return m_body; }
|
|
28
|
+
|
|
29
|
+
virtual void transform(Creator *creator) const override {
|
|
30
|
+
creator->set_type("when");
|
|
31
|
+
creator->append(m_condition.ref());
|
|
32
|
+
if (m_body->nodes().is_empty())
|
|
33
|
+
creator->append_nil();
|
|
34
|
+
else
|
|
35
|
+
for (auto node : m_body->nodes())
|
|
36
|
+
creator->append(node);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected:
|
|
40
|
+
SharedPtr<Node> m_condition {};
|
|
41
|
+
SharedPtr<BlockNode> m_body {};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 ClassNode : public Node {
|
|
15
|
+
public:
|
|
16
|
+
ClassNode(const Token &token, SharedPtr<Node> name, SharedPtr<Node> superclass, SharedPtr<BlockNode> body)
|
|
17
|
+
: Node { token }
|
|
18
|
+
, m_name { name }
|
|
19
|
+
, m_superclass { superclass }
|
|
20
|
+
, m_body { body } {
|
|
21
|
+
assert(m_name);
|
|
22
|
+
assert(m_superclass);
|
|
23
|
+
assert(m_body);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
virtual Type type() const override { return Type::Class; }
|
|
27
|
+
|
|
28
|
+
const SharedPtr<Node> name() const { return m_name; }
|
|
29
|
+
const SharedPtr<Node> superclass() const { return m_superclass; }
|
|
30
|
+
const SharedPtr<BlockNode> body() const { return m_body; }
|
|
31
|
+
|
|
32
|
+
virtual void transform(Creator *creator) const override;
|
|
33
|
+
|
|
34
|
+
protected:
|
|
35
|
+
SharedPtr<Node> m_name {};
|
|
36
|
+
SharedPtr<Node> m_superclass {};
|
|
37
|
+
SharedPtr<BlockNode> m_body {};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -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/owned_ptr.hpp"
|
|
7
|
+
#include "tm/string.hpp"
|
|
8
|
+
|
|
9
|
+
namespace NatalieParser {
|
|
10
|
+
|
|
11
|
+
using namespace TM;
|
|
12
|
+
|
|
13
|
+
class Colon2Node : public Node {
|
|
14
|
+
public:
|
|
15
|
+
Colon2Node(const Token &token, SharedPtr<Node> left, SharedPtr<String> name)
|
|
16
|
+
: Node { token }
|
|
17
|
+
, m_left { left }
|
|
18
|
+
, m_name { name } {
|
|
19
|
+
assert(m_left);
|
|
20
|
+
assert(m_name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
virtual Type type() const override { return Type::Colon2; }
|
|
24
|
+
|
|
25
|
+
virtual bool is_assignable() const override { return true; }
|
|
26
|
+
|
|
27
|
+
const SharedPtr<Node> left() const { return m_left; }
|
|
28
|
+
SharedPtr<String> name() const { return m_name; }
|
|
29
|
+
|
|
30
|
+
virtual void transform(Creator *creator) const override {
|
|
31
|
+
creator->set_type("colon2");
|
|
32
|
+
creator->with_assignment(false, [&]() {
|
|
33
|
+
creator->append(m_left.ref());
|
|
34
|
+
});
|
|
35
|
+
creator->append_symbol(m_name);
|
|
36
|
+
if (creator->assignment())
|
|
37
|
+
creator->wrap("cdecl");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected:
|
|
41
|
+
SharedPtr<Node> m_left {};
|
|
42
|
+
SharedPtr<String> m_name {};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 Colon3Node : public Node {
|
|
13
|
+
public:
|
|
14
|
+
Colon3Node(const Token &token, SharedPtr<String> name)
|
|
15
|
+
: Node { token }
|
|
16
|
+
, m_name { name } { }
|
|
17
|
+
|
|
18
|
+
virtual Type type() const override { return Type::Colon3; }
|
|
19
|
+
|
|
20
|
+
virtual bool is_assignable() const override { return true; }
|
|
21
|
+
|
|
22
|
+
SharedPtr<String> name() const { return m_name; }
|
|
23
|
+
|
|
24
|
+
virtual void transform(Creator *creator) const override {
|
|
25
|
+
creator->set_type("colon3");
|
|
26
|
+
creator->append_symbol(m_name);
|
|
27
|
+
if (creator->assignment())
|
|
28
|
+
creator->wrap("cdecl");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected:
|
|
32
|
+
SharedPtr<String> m_name {};
|
|
33
|
+
};
|
|
34
|
+
}
|