jievro-parser 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/Rakefile +1 -1
- data/jievro-parser.gemspec +1 -1
- data/lib/jievro/parser/binary_operator.rb +27 -38
- data/lib/jievro/parser/grammar/code_block.treetop +1 -1
- data/lib/jievro/parser/grammar/declaration/constant_declaration.treetop +2 -8
- data/lib/jievro/parser/grammar/declaration/declaration.treetop +47 -5
- data/lib/jievro/parser/grammar/declaration/function_declaration.treetop +26 -105
- data/lib/jievro/parser/grammar/declaration/initializer_declaration.treetop +16 -0
- data/lib/jievro/parser/grammar/declaration/protocol_declaration.treetop +164 -0
- data/lib/jievro/parser/grammar/declaration/struct_declaration.treetop +49 -0
- data/lib/jievro/parser/grammar/declaration/typealias_declaration.treetop +64 -0
- data/lib/jievro/parser/grammar/declaration/variable_declaration.treetop +113 -9
- data/lib/jievro/parser/grammar/expression/binary_expression.treetop +5 -22
- data/lib/jievro/parser/grammar/expression/closure_expression.treetop +28 -86
- data/lib/jievro/parser/grammar/expression/expression.treetop +13 -13
- data/lib/jievro/parser/grammar/expression/function_call_expression.treetop +2 -6
- data/lib/jievro/parser/grammar/expression/literal_expression.treetop +1 -1
- data/lib/jievro/parser/grammar/expression/parenthesized_expression.treetop +15 -54
- data/lib/jievro/parser/grammar/expression/postfix_expression.treetop +1 -1
- data/lib/jievro/parser/grammar/expression/prefix_expression.treetop +1 -1
- data/lib/jievro/parser/grammar/expression/primary_expression.treetop +1 -1
- data/lib/jievro/parser/grammar/expression/range_expression.treetop +4 -18
- data/lib/jievro/parser/grammar/expression/self_expression.treetop +2 -7
- data/lib/jievro/parser/grammar/expression/super_expression.treetop +2 -7
- data/lib/jievro/parser/grammar/expression/wildcard_expression.treetop +1 -1
- data/lib/jievro/parser/grammar/generics/generic_argument_clause.treetop +8 -34
- data/lib/jievro/parser/grammar/generics/generics.treetop +2 -2
- data/lib/jievro/parser/grammar/grammar.treetop +35 -28
- data/lib/jievro/parser/grammar/identifier.treetop +2 -2
- data/lib/jievro/parser/grammar/implicit_parameter_name.treetop +1 -1
- data/lib/jievro/parser/grammar/literal/literal.treetop +25 -24
- data/lib/jievro/parser/grammar/literal/literal_array.treetop +12 -40
- data/lib/jievro/parser/grammar/literal/literal_boolean.treetop +5 -13
- data/lib/jievro/parser/grammar/literal/literal_decimal_floating_point.treetop +3 -9
- data/lib/jievro/parser/grammar/literal/literal_dictionary.treetop +18 -57
- data/lib/jievro/parser/grammar/literal/literal_hexadecimal_floating_point.treetop +3 -9
- data/lib/jievro/parser/grammar/literal/literal_integer_binary.treetop +3 -9
- data/lib/jievro/parser/grammar/literal/literal_integer_decimal.treetop +3 -9
- data/lib/jievro/parser/grammar/literal/literal_integer_hexadecimal.treetop +3 -9
- data/lib/jievro/parser/grammar/literal/literal_integer_octal.treetop +3 -9
- data/lib/jievro/parser/grammar/literal/literal_nil.treetop +2 -7
- data/lib/jievro/parser/grammar/literal/literal_numeric.treetop +11 -18
- data/lib/jievro/parser/grammar/literal/literal_string.treetop +14 -46
- data/lib/jievro/parser/grammar/operator.treetop +1 -1
- data/lib/jievro/parser/grammar/pattern/pattern.treetop +4 -4
- data/lib/jievro/parser/grammar/pattern/pattern_identifier.treetop +1 -1
- data/lib/jievro/parser/grammar/pattern/pattern_initializer.treetop +18 -70
- data/lib/jievro/parser/grammar/pattern/pattern_wildcard.treetop +1 -1
- data/lib/jievro/parser/grammar/statement/branch/branch.treetop +2 -2
- data/lib/jievro/parser/grammar/statement/branch/if.treetop +1 -1
- data/lib/jievro/parser/grammar/statement/loop/do_while.treetop +1 -1
- data/lib/jievro/parser/grammar/statement/loop/for.treetop +1 -1
- data/lib/jievro/parser/grammar/statement/loop/for_in.treetop +1 -1
- data/lib/jievro/parser/grammar/statement/loop/loop.treetop +5 -5
- data/lib/jievro/parser/grammar/statement/loop/while.treetop +1 -1
- data/lib/jievro/parser/grammar/statement/statement.treetop +3 -3
- data/lib/jievro/parser/grammar/type/type.treetop +7 -5
- data/lib/jievro/parser/grammar/type/type_annotation.treetop +1 -1
- data/lib/jievro/parser/grammar/type/type_array.treetop +1 -1
- data/lib/jievro/parser/grammar/type/type_dictionary.treetop +1 -1
- data/lib/jievro/parser/grammar/type/type_identifier.treetop +7 -14
- data/lib/jievro/parser/grammar/type/type_inheritance_clause.treetop +57 -0
- data/lib/jievro/parser/grammar/whitespace.treetop +1 -1
- data/lib/jievro/parser/grammar/wildcard.treetop +1 -1
- data/lib/jievro/parser/string_parser.rb +2 -7
- data/lib/jievro/parser/tools/converter/binary_string_to_int_converter.rb +6 -7
- data/lib/jievro/parser/tools/converter/converter.rb +1 -1
- data/lib/jievro/parser/tools/converter/decimal_float_string_to_float_converter.rb +5 -6
- data/lib/jievro/parser/tools/converter/decimal_string_to_int_converter.rb +5 -6
- data/lib/jievro/parser/tools/converter/hexadecimal_float_string_to_float_converter.rb +9 -14
- data/lib/jievro/parser/tools/converter/hexadecimal_string_to_int_converter.rb +5 -6
- data/lib/jievro/parser/tools/converter/octal_string_to_int_converter.rb +5 -6
- data/lib/jievro/parser/tools/quote_stripper.rb +1 -2
- data/lib/jievro/parser/tools/shunting_yard.rb +18 -32
- data/lib/jievro/parser/tools/tokens.rb +159 -0
- data/lib/jievro/parser/version.rb +1 -1
- metadata +24 -19
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Jievro
|
2
2
|
grammar ClosureExpression
|
3
3
|
|
4
4
|
rule closure_expression
|
@@ -6,33 +6,15 @@ module Kauri
|
|
6
6
|
def tokens
|
7
7
|
tokens = []
|
8
8
|
|
9
|
-
tokens.push(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
unless ws1.text_value.empty?
|
15
|
-
tokens.concat(ws1.tokens)
|
16
|
-
end
|
17
|
-
|
18
|
-
unless closure_signature.text_value.empty?
|
19
|
-
tokens.concat(closure_signature.tokens)
|
20
|
-
end
|
21
|
-
|
22
|
-
unless ws2.text_value.empty?
|
23
|
-
tokens.concat(ws2.tokens)
|
24
|
-
end
|
9
|
+
tokens.push(T_OPEN_CURLY_BRACKET)
|
10
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
11
|
+
tokens.concat(closure_signature.tokens) \
|
12
|
+
unless closure_signature.text_value.empty?
|
25
13
|
|
14
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
26
15
|
tokens.concat(statement_list.tokens)
|
27
|
-
|
28
|
-
|
29
|
-
tokens.concat(ws3.tokens)
|
30
|
-
end
|
31
|
-
|
32
|
-
tokens.push({
|
33
|
-
type: 'T_CLOSE_CURLY_BRACKET',
|
34
|
-
value: '}'
|
35
|
-
})
|
16
|
+
tokens.concat(ws3.tokens) unless ws3.text_value.empty?
|
17
|
+
tokens.push(T_CLOSE_CURLY_BRACKET)
|
36
18
|
|
37
19
|
tokens
|
38
20
|
end
|
@@ -44,9 +26,8 @@ module Kauri
|
|
44
26
|
body: statement_list.ast
|
45
27
|
}
|
46
28
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
29
|
+
ast[:signature] = closure_signature.ast \
|
30
|
+
unless closure_signature.text_value.empty?
|
50
31
|
|
51
32
|
[ast]
|
52
33
|
end
|
@@ -60,11 +41,7 @@ module Kauri
|
|
60
41
|
|
61
42
|
tokens.concat(capture_list.tokens)
|
62
43
|
tokens.concat(ws.tokens)
|
63
|
-
|
64
|
-
tokens.push({
|
65
|
-
type: 'T_IN',
|
66
|
-
value: 'in'
|
67
|
-
})
|
44
|
+
tokens.push(T_IN)
|
68
45
|
|
69
46
|
tokens
|
70
47
|
end
|
@@ -80,31 +57,13 @@ module Kauri
|
|
80
57
|
def tokens
|
81
58
|
tokens = []
|
82
59
|
|
83
|
-
tokens.push(
|
84
|
-
|
85
|
-
value: '['
|
86
|
-
})
|
87
|
-
|
88
|
-
unless ws1.text_value.empty?
|
89
|
-
tokens.concat(ws1.tokens)
|
90
|
-
end
|
91
|
-
|
60
|
+
tokens.push(T_OPEN_SQUARE_BRACKET)
|
61
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
92
62
|
tokens.concat(capture_specifier.tokens)
|
93
|
-
|
94
|
-
unless ws2.text_value.empty?
|
95
|
-
tokens.concat(ws2.tokens)
|
96
|
-
end
|
97
|
-
|
63
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
98
64
|
tokens.concat(expression.tokens)
|
99
|
-
|
100
|
-
|
101
|
-
tokens.concat(ws3.tokens)
|
102
|
-
end
|
103
|
-
|
104
|
-
tokens.push({
|
105
|
-
type: 'T_CLOSE_SQUARE_BRACKET',
|
106
|
-
value: ']'
|
107
|
-
})
|
65
|
+
tokens.concat(ws3.tokens) unless ws3.text_value.empty?
|
66
|
+
tokens.push(T_CLOSE_SQUARE_BRACKET)
|
108
67
|
|
109
68
|
tokens
|
110
69
|
end
|
@@ -129,10 +88,12 @@ module Kauri
|
|
129
88
|
rule weak_or_unowned_capture_specifier
|
130
89
|
('weak' / 'unowned') {
|
131
90
|
def tokens
|
132
|
-
[
|
133
|
-
|
134
|
-
|
135
|
-
|
91
|
+
[
|
92
|
+
{
|
93
|
+
type: 'T_' + text_value.upcase,
|
94
|
+
value: text_value
|
95
|
+
}
|
96
|
+
]
|
136
97
|
end
|
137
98
|
|
138
99
|
def ast
|
@@ -146,37 +107,18 @@ module Kauri
|
|
146
107
|
def tokens
|
147
108
|
tokens = []
|
148
109
|
|
149
|
-
tokens.push(
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
unless ws1.text_value.empty?
|
155
|
-
tokens.concat(ws1.tokens)
|
156
|
-
end
|
157
|
-
|
158
|
-
tokens.push({
|
159
|
-
type: 'T_OPEN_ROUND_BRACKET',
|
160
|
-
value: '('
|
161
|
-
})
|
162
|
-
|
163
|
-
unless ws2.text_value.empty?
|
164
|
-
tokens.concat(ws2.tokens)
|
165
|
-
end
|
110
|
+
tokens.push(T_UNOWNED)
|
111
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
112
|
+
tokens.push(T_OPEN_ROUND_BRACKET)
|
113
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
166
114
|
|
167
115
|
tokens.push({
|
168
116
|
type: 'T_' + safe_or_unsafe.text_value.upcase,
|
169
117
|
value: safe_or_unsafe.text_value
|
170
118
|
})
|
171
119
|
|
172
|
-
unless ws3.text_value.empty?
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
tokens.push({
|
177
|
-
type: 'T_CLOSE_ROUND_BRACKET',
|
178
|
-
value: ')'
|
179
|
-
})
|
120
|
+
tokens.concat(ws3.tokens) unless ws3.text_value.empty?
|
121
|
+
tokens.push(T_CLOSE_ROUND_BRACKET)
|
180
122
|
|
181
123
|
tokens
|
182
124
|
end
|
@@ -11,21 +11,21 @@ require 'jievro/parser/grammar/expression/closure_expression'
|
|
11
11
|
require 'jievro/parser/grammar/expression/self_expression'
|
12
12
|
require 'jievro/parser/grammar/expression/super_expression'
|
13
13
|
|
14
|
-
module
|
14
|
+
module Jievro
|
15
15
|
grammar Expression
|
16
16
|
|
17
|
-
include
|
18
|
-
include
|
19
|
-
include
|
20
|
-
include
|
21
|
-
include
|
22
|
-
include
|
23
|
-
include
|
24
|
-
include
|
25
|
-
include
|
26
|
-
include
|
27
|
-
include
|
28
|
-
include
|
17
|
+
include Jievro::LiteralExpression
|
18
|
+
include Jievro::PrefixExpression
|
19
|
+
include Jievro::PostfixExpression
|
20
|
+
include Jievro::BinaryExpression
|
21
|
+
include Jievro::RangeExpression
|
22
|
+
include Jievro::PrimaryExpression
|
23
|
+
include Jievro::ParenthesizedExpression
|
24
|
+
include Jievro::WildcardExpression
|
25
|
+
include Jievro::FunctionCallExpression
|
26
|
+
include Jievro::ClosureExpression
|
27
|
+
include Jievro::SelfExpression
|
28
|
+
include Jievro::SuperExpression
|
29
29
|
|
30
30
|
rule expression
|
31
31
|
super_expression
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Jievro
|
2
2
|
grammar FunctionCallExpression
|
3
3
|
|
4
4
|
rule function_call_expression
|
@@ -7,11 +7,7 @@ module Kauri
|
|
7
7
|
tokens = []
|
8
8
|
|
9
9
|
tokens.concat(callee.tokens)
|
10
|
-
|
11
|
-
unless ws.text_value.empty?
|
12
|
-
tokens.concat(ws.tokens)
|
13
|
-
end
|
14
|
-
|
10
|
+
tokens.concat(ws.tokens) unless ws.text_value.empty?
|
15
11
|
tokens.concat(parameters.tokens)
|
16
12
|
|
17
13
|
tokens
|
@@ -1,41 +1,24 @@
|
|
1
|
-
module
|
1
|
+
module Jievro
|
2
2
|
grammar ParenthesizedExpression
|
3
3
|
|
4
4
|
rule parenthesized_expression
|
5
5
|
'(' ws1:_ expression:expression_element_list? ws2:_ ')' {
|
6
6
|
def tokens
|
7
|
-
|
8
7
|
tokens = []
|
9
8
|
|
10
|
-
tokens.push(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
unless ws1.text_value.empty?
|
16
|
-
tokens.concat(ws1.tokens)
|
17
|
-
end
|
18
|
-
|
19
|
-
unless expression.text_value.empty?
|
20
|
-
tokens.concat(expression.tokens)
|
21
|
-
end
|
22
|
-
|
23
|
-
unless ws2.text_value.empty?
|
24
|
-
tokens.concat(ws2.tokens)
|
25
|
-
end
|
26
|
-
|
27
|
-
tokens.push({
|
28
|
-
type: 'T_CLOSE_ROUND_BRACKET',
|
29
|
-
value: ')'
|
30
|
-
})
|
9
|
+
tokens.push(T_OPEN_ROUND_BRACKET)
|
10
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
11
|
+
tokens.concat(expression.tokens) unless expression.text_value.empty?
|
12
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
13
|
+
tokens.push(T_CLOSE_ROUND_BRACKET)
|
31
14
|
|
32
15
|
tokens
|
33
16
|
end
|
34
17
|
|
35
18
|
def ast
|
36
|
-
|
37
|
-
|
38
|
-
|
19
|
+
if expression.text_value.empty?
|
20
|
+
ast = []
|
21
|
+
else
|
39
22
|
ast = expression.ast
|
40
23
|
end
|
41
24
|
|
@@ -51,21 +34,10 @@ module Kauri
|
|
51
34
|
|
52
35
|
unless head.text_value.empty?
|
53
36
|
head.elements.each { |e|
|
54
|
-
|
55
37
|
tokens.concat(e.expression.tokens)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
tokens.push({
|
62
|
-
type: 'T_COMMA',
|
63
|
-
value: ','
|
64
|
-
})
|
65
|
-
|
66
|
-
unless e.ws2.text_value.empty?
|
67
|
-
tokens.concat(e.ws2.tokens)
|
68
|
-
end
|
38
|
+
tokens.concat(e.ws1.tokens) unless e.ws1.text_value.empty?
|
39
|
+
tokens.push(T_COMMA)
|
40
|
+
tokens.concat(e.ws2.tokens) unless e.ws2.text_value.empty?
|
69
41
|
}
|
70
42
|
end
|
71
43
|
|
@@ -112,20 +84,9 @@ module Kauri
|
|
112
84
|
tokens = []
|
113
85
|
|
114
86
|
tokens.concat(identifier.tokens)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
tokens.push({
|
121
|
-
type: 'T_COLON',
|
122
|
-
value: ':'
|
123
|
-
})
|
124
|
-
|
125
|
-
unless ws2.text_value.empty?
|
126
|
-
tokens.concat(ws2.tokens)
|
127
|
-
end
|
128
|
-
|
87
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
88
|
+
tokens.push(T_COLON)
|
89
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
129
90
|
tokens.concat(expression.tokens)
|
130
91
|
|
131
92
|
tokens
|
@@ -1,24 +1,15 @@
|
|
1
|
-
module
|
1
|
+
module Jievro
|
2
2
|
grammar RangeExpression
|
3
3
|
|
4
4
|
rule range_expression
|
5
5
|
left:primary_expression ws1:_ range_operator:range_operator ws2:_ right:primary_expression {
|
6
6
|
def tokens
|
7
|
-
|
8
7
|
tokens = []
|
9
8
|
|
10
9
|
tokens.concat(left.tokens)
|
11
|
-
|
12
|
-
unless ws1.text_value.empty?
|
13
|
-
tokens.concat(ws1.tokens)
|
14
|
-
end
|
15
|
-
|
10
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
16
11
|
tokens.concat(range_operator.tokens)
|
17
|
-
|
18
|
-
unless ws2.text_value.empty?
|
19
|
-
tokens.concat(ws2.tokens)
|
20
|
-
end
|
21
|
-
|
12
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
22
13
|
tokens.concat(right.tokens)
|
23
14
|
|
24
15
|
tokens
|
@@ -40,12 +31,7 @@ module Kauri
|
|
40
31
|
rule range_operator
|
41
32
|
('...' / '..<') {
|
42
33
|
def tokens
|
43
|
-
|
44
|
-
{
|
45
|
-
type: 'T_OPERATOR',
|
46
|
-
value: text_value
|
47
|
-
}
|
48
|
-
]
|
34
|
+
[T_OPERATOR(text_value)]
|
49
35
|
end
|
50
36
|
}
|
51
37
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Jievro
|
2
2
|
grammar GenericArgumentClause
|
3
3
|
|
4
4
|
rule generic_argument_clause
|
@@ -6,25 +6,11 @@ module Kauri
|
|
6
6
|
def tokens
|
7
7
|
tokens = []
|
8
8
|
|
9
|
-
tokens.push(
|
10
|
-
|
11
|
-
value: '<'
|
12
|
-
})
|
13
|
-
|
14
|
-
unless ws1.text_value.empty?
|
15
|
-
tokens.concat(ws1.tokens)
|
16
|
-
end
|
17
|
-
|
9
|
+
tokens.push(T_OPEN_ANGLE_BRACKET)
|
10
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
18
11
|
tokens.concat(generic_argument_list.tokens)
|
19
|
-
|
20
|
-
|
21
|
-
tokens.concat(ws2.tokens)
|
22
|
-
end
|
23
|
-
|
24
|
-
tokens.push({
|
25
|
-
type: 'T_CLOSE_ANGLE_BRACKET',
|
26
|
-
value: '>'
|
27
|
-
})
|
12
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
13
|
+
tokens.push(T_CLOSE_ANGLE_BRACKET)
|
28
14
|
|
29
15
|
tokens
|
30
16
|
end
|
@@ -42,21 +28,10 @@ module Kauri
|
|
42
28
|
|
43
29
|
unless head.text_value.empty?
|
44
30
|
head.elements.each { |e|
|
45
|
-
|
46
31
|
tokens.concat(e.generic_argument.tokens)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
tokens.push({
|
53
|
-
type: 'T_COMMA',
|
54
|
-
value: ','
|
55
|
-
})
|
56
|
-
|
57
|
-
unless e.ws2.text_value.empty?
|
58
|
-
tokens.concat(e.ws2.tokens)
|
59
|
-
end
|
32
|
+
tokens.concat(e.ws1.tokens) unless e.ws1.text_value.empty?
|
33
|
+
tokens.push(T_COMMA)
|
34
|
+
tokens.concat(e.ws2.tokens) unless e.ws2.text_value.empty?
|
60
35
|
}
|
61
36
|
end
|
62
37
|
|
@@ -66,7 +41,6 @@ module Kauri
|
|
66
41
|
end
|
67
42
|
|
68
43
|
def ast
|
69
|
-
|
70
44
|
ast = []
|
71
45
|
|
72
46
|
unless head.text_value.empty?
|