natalie_parser 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,47 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/creator.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 NodeWithArgs : public Node {
|
14
|
+
public:
|
15
|
+
NodeWithArgs(const Token &token)
|
16
|
+
: Node { token } { }
|
17
|
+
|
18
|
+
NodeWithArgs(const Token &token, const Vector<SharedPtr<Node>> &args)
|
19
|
+
: Node { token } {
|
20
|
+
for (auto arg : args)
|
21
|
+
add_arg(arg);
|
22
|
+
}
|
23
|
+
|
24
|
+
NodeWithArgs(const NodeWithArgs &other)
|
25
|
+
: NodeWithArgs { other.token() } {
|
26
|
+
for (auto arg : other.args())
|
27
|
+
add_arg(arg);
|
28
|
+
}
|
29
|
+
|
30
|
+
void add_arg(SharedPtr<Node> arg) {
|
31
|
+
// TODO: error if BlockPass already added (must be last)
|
32
|
+
m_args.push(arg);
|
33
|
+
}
|
34
|
+
|
35
|
+
bool has_block_pass() const override {
|
36
|
+
return m_args.size() > 0 && m_args.last()->type() == Node::Type::BlockPass;
|
37
|
+
}
|
38
|
+
|
39
|
+
Vector<SharedPtr<Node>> &args() { return m_args; }
|
40
|
+
const Vector<SharedPtr<Node>> &args() const { return m_args; }
|
41
|
+
|
42
|
+
void append_method_or_block_args(Creator *creator) const;
|
43
|
+
|
44
|
+
protected:
|
45
|
+
Vector<SharedPtr<Node>> m_args {};
|
46
|
+
};
|
47
|
+
}
|
@@ -0,0 +1,35 @@
|
|
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 NotMatchNode : public Node {
|
14
|
+
public:
|
15
|
+
NotMatchNode(const Token &token, SharedPtr<Node> expression)
|
16
|
+
: Node { token }
|
17
|
+
, m_expression { expression } {
|
18
|
+
assert(m_expression);
|
19
|
+
}
|
20
|
+
|
21
|
+
virtual Type type() const override { return Type::NotMatch; }
|
22
|
+
|
23
|
+
const SharedPtr<Node> expression() const { return m_expression; }
|
24
|
+
|
25
|
+
void set_expression(SharedPtr<Node> expression) { m_expression = expression; }
|
26
|
+
|
27
|
+
virtual void transform(Creator *creator) const override {
|
28
|
+
creator->set_type("not");
|
29
|
+
creator->append(m_expression.ref());
|
30
|
+
}
|
31
|
+
|
32
|
+
protected:
|
33
|
+
SharedPtr<Node> m_expression {};
|
34
|
+
};
|
35
|
+
}
|
@@ -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 NotNode : public Node {
|
14
|
+
public:
|
15
|
+
NotNode(const Token &token, SharedPtr<Node> expression)
|
16
|
+
: Node { token }
|
17
|
+
, m_expression { expression } {
|
18
|
+
assert(m_expression);
|
19
|
+
}
|
20
|
+
|
21
|
+
virtual Type type() const override { return Type::Not; }
|
22
|
+
|
23
|
+
const SharedPtr<Node> expression() const { return m_expression; }
|
24
|
+
|
25
|
+
void set_expression(SharedPtr<Node> expression) { m_expression = expression; }
|
26
|
+
|
27
|
+
virtual void transform(Creator *creator) const override {
|
28
|
+
creator->set_type("call");
|
29
|
+
creator->append(m_expression.ref());
|
30
|
+
auto message = String("!");
|
31
|
+
creator->append_symbol(message);
|
32
|
+
}
|
33
|
+
|
34
|
+
protected:
|
35
|
+
SharedPtr<Node> m_expression {};
|
36
|
+
};
|
37
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/node.hpp"
|
4
|
+
|
5
|
+
namespace NatalieParser {
|
6
|
+
|
7
|
+
using namespace TM;
|
8
|
+
|
9
|
+
class NthRefNode : public Node {
|
10
|
+
public:
|
11
|
+
NthRefNode(const Token &token, long long num)
|
12
|
+
: Node { token }
|
13
|
+
, m_num { num } { }
|
14
|
+
|
15
|
+
virtual Type type() const override { return Type::NthRef; }
|
16
|
+
|
17
|
+
long long num() const { return m_num; }
|
18
|
+
|
19
|
+
virtual void transform(Creator *creator) const override {
|
20
|
+
creator->set_type("nth_ref");
|
21
|
+
creator->append_integer(m_num);
|
22
|
+
}
|
23
|
+
|
24
|
+
protected:
|
25
|
+
long long m_num { 0 };
|
26
|
+
};
|
27
|
+
}
|
@@ -0,0 +1,74 @@
|
|
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 OpAssignAccessorNode : public NodeWithArgs {
|
14
|
+
public:
|
15
|
+
OpAssignAccessorNode(const Token &token, SharedPtr<String> op, SharedPtr<Node> receiver, SharedPtr<String> message, SharedPtr<Node> value, Vector<SharedPtr<Node>> &args)
|
16
|
+
: NodeWithArgs { token }
|
17
|
+
, m_op { op }
|
18
|
+
, m_receiver { receiver }
|
19
|
+
, m_message { message }
|
20
|
+
, m_value { value } {
|
21
|
+
assert(m_op);
|
22
|
+
assert(m_receiver);
|
23
|
+
assert(m_message);
|
24
|
+
assert(m_value);
|
25
|
+
for (auto arg : args)
|
26
|
+
add_arg(arg);
|
27
|
+
}
|
28
|
+
|
29
|
+
virtual Type type() const override { return Type::OpAssignAccessor; }
|
30
|
+
|
31
|
+
const SharedPtr<String> op() const { return m_op; }
|
32
|
+
const SharedPtr<Node> receiver() const { return m_receiver; }
|
33
|
+
const SharedPtr<String> message() const { return m_message; }
|
34
|
+
const SharedPtr<Node> value() const { return m_value; }
|
35
|
+
|
36
|
+
bool safe() const { return m_safe; }
|
37
|
+
void set_safe(bool safe) { m_safe = safe; }
|
38
|
+
|
39
|
+
virtual void transform(Creator *creator) const override {
|
40
|
+
if (*m_message == "[]=") {
|
41
|
+
creator->set_type("op_asgn1");
|
42
|
+
creator->append(m_receiver.ref());
|
43
|
+
if (m_args.is_empty()) {
|
44
|
+
creator->append_nil();
|
45
|
+
} else {
|
46
|
+
creator->append_sexp([&](Creator *c) {
|
47
|
+
c->set_type("arglist");
|
48
|
+
for (auto arg : m_args)
|
49
|
+
c->append(arg);
|
50
|
+
});
|
51
|
+
}
|
52
|
+
creator->append_symbol(m_op);
|
53
|
+
creator->append(m_value.ref());
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
assert(args().is_empty());
|
57
|
+
if (m_safe)
|
58
|
+
creator->set_type("safe_op_asgn2");
|
59
|
+
else
|
60
|
+
creator->set_type("op_asgn2");
|
61
|
+
creator->append(m_receiver.ref());
|
62
|
+
creator->append_symbol(m_message);
|
63
|
+
creator->append_symbol(m_op);
|
64
|
+
creator->append(m_value.ref());
|
65
|
+
}
|
66
|
+
|
67
|
+
protected:
|
68
|
+
SharedPtr<String> m_op {};
|
69
|
+
SharedPtr<Node> m_receiver {};
|
70
|
+
SharedPtr<String> m_message {};
|
71
|
+
SharedPtr<Node> m_value {};
|
72
|
+
bool m_safe { false };
|
73
|
+
};
|
74
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/assignment_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 "natalie_parser/node/op_assign_node.hpp"
|
8
|
+
#include "tm/hashmap.hpp"
|
9
|
+
#include "tm/string.hpp"
|
10
|
+
|
11
|
+
namespace NatalieParser {
|
12
|
+
|
13
|
+
using namespace TM;
|
14
|
+
|
15
|
+
class OpAssignAndNode : public OpAssignNode {
|
16
|
+
public:
|
17
|
+
OpAssignAndNode(const Token &token, SharedPtr<Node> name, SharedPtr<Node> value)
|
18
|
+
: OpAssignNode { token, name, value } { }
|
19
|
+
|
20
|
+
virtual Type type() const override { return Type::OpAssignAnd; }
|
21
|
+
|
22
|
+
virtual void transform(Creator *creator) const override {
|
23
|
+
// s(:op_asgn_and, s(:lvar, :x), s(:lasgn, :x, s(:lit, 1)))
|
24
|
+
creator->set_type("op_asgn_and");
|
25
|
+
creator->append(m_name.ref());
|
26
|
+
auto assignment = AssignmentNode {
|
27
|
+
token(),
|
28
|
+
m_name.static_cast_as<Node>(),
|
29
|
+
m_value
|
30
|
+
};
|
31
|
+
creator->append(assignment);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/call_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/string.hpp"
|
9
|
+
|
10
|
+
namespace NatalieParser {
|
11
|
+
|
12
|
+
using namespace TM;
|
13
|
+
|
14
|
+
class OpAssignNode : public Node {
|
15
|
+
public:
|
16
|
+
OpAssignNode(const Token &token, SharedPtr<Node> name, SharedPtr<Node> value)
|
17
|
+
: Node { token }
|
18
|
+
, m_name { name }
|
19
|
+
, m_value { value } {
|
20
|
+
assert(m_name);
|
21
|
+
assert(m_value);
|
22
|
+
}
|
23
|
+
|
24
|
+
OpAssignNode(const Token &token, SharedPtr<String> op, SharedPtr<Node> name, SharedPtr<Node> value)
|
25
|
+
: Node { token }
|
26
|
+
, m_op { op }
|
27
|
+
, m_name { name }
|
28
|
+
, m_value { value } {
|
29
|
+
assert(m_op);
|
30
|
+
assert(m_name);
|
31
|
+
assert(m_value);
|
32
|
+
}
|
33
|
+
|
34
|
+
virtual Type type() const override { return Type::OpAssign; }
|
35
|
+
|
36
|
+
const SharedPtr<String> op() const { return m_op; }
|
37
|
+
const SharedPtr<Node> name() const { return m_name; }
|
38
|
+
const SharedPtr<Node> value() const { return m_value; }
|
39
|
+
|
40
|
+
virtual void transform(Creator *creator) const override;
|
41
|
+
|
42
|
+
protected:
|
43
|
+
SharedPtr<String> m_op {};
|
44
|
+
SharedPtr<Node> m_name {};
|
45
|
+
SharedPtr<Node> m_value {};
|
46
|
+
};
|
47
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/assignment_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 "natalie_parser/node/op_assign_node.hpp"
|
8
|
+
#include "tm/hashmap.hpp"
|
9
|
+
#include "tm/string.hpp"
|
10
|
+
|
11
|
+
namespace NatalieParser {
|
12
|
+
|
13
|
+
using namespace TM;
|
14
|
+
|
15
|
+
class OpAssignOrNode : public OpAssignNode {
|
16
|
+
public:
|
17
|
+
OpAssignOrNode(const Token &token, SharedPtr<Node> name, SharedPtr<Node> value)
|
18
|
+
: OpAssignNode { token, name, value } { }
|
19
|
+
|
20
|
+
virtual Type type() const override { return Type::OpAssignOr; }
|
21
|
+
|
22
|
+
virtual void transform(Creator *creator) const override {
|
23
|
+
// s(:op_asgn_or, s(:lvar, :x), s(:lasgn, :x, s(:lit, 1)))
|
24
|
+
creator->set_type("op_asgn_or");
|
25
|
+
creator->append(m_name.ref());
|
26
|
+
auto assignment = AssignmentNode {
|
27
|
+
token(),
|
28
|
+
m_name.static_cast_as<Node>(),
|
29
|
+
m_value
|
30
|
+
};
|
31
|
+
creator->append(assignment);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
}
|
@@ -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 PinNode : public Node {
|
14
|
+
public:
|
15
|
+
PinNode(const Token &token, SharedPtr<Node> identifier)
|
16
|
+
: Node { token }
|
17
|
+
, m_identifier { identifier } {
|
18
|
+
assert(m_identifier);
|
19
|
+
}
|
20
|
+
|
21
|
+
virtual Type type() const override { return Type::Pin; }
|
22
|
+
|
23
|
+
const SharedPtr<Node> identifier() const { return m_identifier; }
|
24
|
+
|
25
|
+
virtual void transform(Creator *creator) const override {
|
26
|
+
creator->set_type("pin");
|
27
|
+
creator->append(m_identifier.ref());
|
28
|
+
}
|
29
|
+
|
30
|
+
protected:
|
31
|
+
SharedPtr<Node> m_identifier {};
|
32
|
+
};
|
33
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/fixnum_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 RangeNode : public Node {
|
15
|
+
public:
|
16
|
+
RangeNode(const Token &token, SharedPtr<Node> first, SharedPtr<Node> last, bool exclude_end)
|
17
|
+
: Node { token }
|
18
|
+
, m_first { first }
|
19
|
+
, m_last { last }
|
20
|
+
, m_exclude_end { exclude_end } {
|
21
|
+
assert(m_first);
|
22
|
+
assert(m_last);
|
23
|
+
}
|
24
|
+
|
25
|
+
virtual Type type() const override { return Type::Range; }
|
26
|
+
|
27
|
+
const SharedPtr<Node> first() const { return m_first; }
|
28
|
+
const SharedPtr<Node> last() const { return m_last; }
|
29
|
+
bool exclude_end() const { return m_exclude_end; }
|
30
|
+
|
31
|
+
virtual void transform(Creator *creator) const override {
|
32
|
+
if (m_first->type() == Node::Type::Fixnum && m_last->type() == Node::Type::Fixnum) {
|
33
|
+
creator->set_type("lit");
|
34
|
+
auto first_num = m_first.static_cast_as<FixnumNode>()->number();
|
35
|
+
auto last_num = m_last.static_cast_as<FixnumNode>()->number();
|
36
|
+
creator->append_range(first_num, last_num, m_exclude_end);
|
37
|
+
} else {
|
38
|
+
if (m_exclude_end)
|
39
|
+
creator->set_type("dot3");
|
40
|
+
else
|
41
|
+
creator->set_type("dot2");
|
42
|
+
creator->append(m_first.ref());
|
43
|
+
creator->append(m_last.ref());
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
protected:
|
48
|
+
SharedPtr<Node> m_first {};
|
49
|
+
SharedPtr<Node> m_last {};
|
50
|
+
bool m_exclude_end { false };
|
51
|
+
};
|
52
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/node.hpp"
|
4
|
+
|
5
|
+
namespace NatalieParser {
|
6
|
+
|
7
|
+
using namespace TM;
|
8
|
+
|
9
|
+
class RedoNode : public Node {
|
10
|
+
public:
|
11
|
+
RedoNode(const Token &token)
|
12
|
+
: Node { token } { }
|
13
|
+
|
14
|
+
virtual Type type() const override { return Type::Redo; }
|
15
|
+
|
16
|
+
virtual void transform(Creator *creator) const override {
|
17
|
+
creator->set_type("redo");
|
18
|
+
}
|
19
|
+
};
|
20
|
+
}
|
@@ -0,0 +1,36 @@
|
|
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 RegexpNode : public Node {
|
13
|
+
public:
|
14
|
+
RegexpNode(const Token &token, SharedPtr<String> pattern)
|
15
|
+
: Node { token }
|
16
|
+
, m_pattern { pattern } {
|
17
|
+
assert(m_pattern);
|
18
|
+
}
|
19
|
+
|
20
|
+
virtual Type type() const override { return Type::Regexp; }
|
21
|
+
|
22
|
+
SharedPtr<String> pattern() const { return m_pattern; }
|
23
|
+
|
24
|
+
int options() const { return m_options; }
|
25
|
+
void set_options(int options) { m_options = options; }
|
26
|
+
|
27
|
+
virtual void transform(Creator *creator) const override {
|
28
|
+
creator->set_type("lit");
|
29
|
+
creator->append_regexp(m_pattern, m_options);
|
30
|
+
}
|
31
|
+
|
32
|
+
protected:
|
33
|
+
SharedPtr<String> m_pattern {};
|
34
|
+
int m_options { 0 };
|
35
|
+
};
|
36
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/node.hpp"
|
4
|
+
|
5
|
+
namespace NatalieParser {
|
6
|
+
|
7
|
+
using namespace TM;
|
8
|
+
|
9
|
+
class RetryNode : public Node {
|
10
|
+
public:
|
11
|
+
RetryNode(const Token &token)
|
12
|
+
: Node { token } { }
|
13
|
+
|
14
|
+
virtual Type type() const override { return Type::Retry; }
|
15
|
+
|
16
|
+
virtual void transform(Creator *creator) const override {
|
17
|
+
creator->set_type("retry");
|
18
|
+
}
|
19
|
+
};
|
20
|
+
}
|
@@ -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 ReturnNode : public Node {
|
14
|
+
public:
|
15
|
+
ReturnNode(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::Return; }
|
22
|
+
|
23
|
+
const SharedPtr<Node> value() const { return m_value; }
|
24
|
+
|
25
|
+
virtual void transform(Creator *creator) const override {
|
26
|
+
creator->set_type("return");
|
27
|
+
if (m_value->type() != Node::Type::Nil)
|
28
|
+
creator->append(m_value.ref());
|
29
|
+
}
|
30
|
+
|
31
|
+
protected:
|
32
|
+
SharedPtr<Node> m_value {};
|
33
|
+
};
|
34
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "natalie_parser/node/call_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 SafeCallNode : public CallNode {
|
14
|
+
public:
|
15
|
+
SafeCallNode(const Token &token, SharedPtr<Node> receiver, SharedPtr<String> message)
|
16
|
+
: CallNode { token, receiver, message } { }
|
17
|
+
|
18
|
+
SafeCallNode(const Token &token, CallNode &node)
|
19
|
+
: CallNode { token, node } { }
|
20
|
+
|
21
|
+
virtual Type type() const override { return Type::SafeCall; }
|
22
|
+
|
23
|
+
virtual void transform(Creator *creator) const override {
|
24
|
+
CallNode::transform(creator);
|
25
|
+
if (creator->assignment())
|
26
|
+
creator->set_type("safe_attrasgn");
|
27
|
+
else
|
28
|
+
creator->set_type("safe_call");
|
29
|
+
}
|
30
|
+
};
|
31
|
+
}
|
@@ -0,0 +1,37 @@
|
|
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 SclassNode : public Node {
|
15
|
+
public:
|
16
|
+
SclassNode(const Token &token, SharedPtr<Node> klass, SharedPtr<BlockNode> body)
|
17
|
+
: Node { token }
|
18
|
+
, m_klass { klass }
|
19
|
+
, m_body { body } { }
|
20
|
+
|
21
|
+
virtual Type type() const override { return Type::Sclass; }
|
22
|
+
|
23
|
+
const SharedPtr<Node> klass() const { return m_klass; }
|
24
|
+
const SharedPtr<BlockNode> body() const { return m_body; }
|
25
|
+
|
26
|
+
virtual void transform(Creator *creator) const override {
|
27
|
+
creator->set_type("sclass");
|
28
|
+
creator->append(m_klass.ref());
|
29
|
+
for (auto node : m_body->nodes())
|
30
|
+
creator->append(node);
|
31
|
+
}
|
32
|
+
|
33
|
+
protected:
|
34
|
+
SharedPtr<Node> m_klass {};
|
35
|
+
SharedPtr<BlockNode> m_body {};
|
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 SelfNode : public Node {
|
13
|
+
public:
|
14
|
+
SelfNode(const Token &token)
|
15
|
+
: Node { token } { }
|
16
|
+
|
17
|
+
virtual Type type() const override { return Type::Self; }
|
18
|
+
|
19
|
+
virtual void transform(Creator *creator) const override {
|
20
|
+
creator->set_type("self");
|
21
|
+
}
|
22
|
+
};
|
23
|
+
}
|
@@ -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 ShadowArgNode : public Node {
|
14
|
+
public:
|
15
|
+
ShadowArgNode(const Token &token)
|
16
|
+
: Node { token } { }
|
17
|
+
|
18
|
+
virtual Type type() const override { return Type::ShadowArg; }
|
19
|
+
|
20
|
+
const Vector<SharedPtr<String>> &names() const { return m_names; }
|
21
|
+
|
22
|
+
void add_name(SharedPtr<String> name) {
|
23
|
+
m_names.push(name);
|
24
|
+
}
|
25
|
+
|
26
|
+
void add_to_locals(TM::Hashmap<TM::String> &locals) {
|
27
|
+
for (auto name : m_names)
|
28
|
+
locals.set(name->c_str());
|
29
|
+
}
|
30
|
+
|
31
|
+
virtual void transform(Creator *creator) const override {
|
32
|
+
creator->set_type("shadow");
|
33
|
+
for (auto name : m_names)
|
34
|
+
creator->append_symbol(name);
|
35
|
+
}
|
36
|
+
|
37
|
+
protected:
|
38
|
+
Vector<SharedPtr<String>> m_names {};
|
39
|
+
};
|
40
|
+
}
|