jievro-parser 0.8.0 → 0.9.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 +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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aada9eec4d85adbc32e3a819a1a6a65d89e08786
|
4
|
+
data.tar.gz: 4d40c2a82ba9259b0fef4a059709c4faf5c6dadc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a0bc03018a89e087b2b247419323b2e4ab9f81e43ec4fabea34a5b1e86b14a9a68b8760a7ce5ac887ea5d10c12963f64cba4750f236ddb4c30980e1ca92139
|
7
|
+
data.tar.gz: 930f50adb765c6e68d8dddf929a3c1815b34f0d37847246396939e95a86d4f6cca87b290228f4976013764e0eb5e9ec1fba560c6b6b01fdee95fda59e2ce6d47
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jievro-parser (0.
|
5
|
-
jievro-ast (~> 0.
|
4
|
+
jievro-parser (0.9.0)
|
5
|
+
jievro-ast (~> 0.7)
|
6
6
|
treetop (~> 1.6)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
diff-lcs (1.2.5)
|
12
|
-
jievro-ast (0.
|
12
|
+
jievro-ast (0.8.1)
|
13
13
|
polyglot (0.3.5)
|
14
14
|
rake (10.4.2)
|
15
15
|
rspec (3.2.0)
|
data/Rakefile
CHANGED
data/jievro-parser.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.required_ruby_version = '~> 2.0'
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'jievro-ast', '~> 0.
|
21
|
+
spec.add_runtime_dependency 'jievro-ast', '~> 0.7'
|
22
22
|
spec.add_runtime_dependency 'treetop', '~> 1.6'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.9'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Jievro
|
2
2
|
module Parser
|
3
3
|
class BinaryOperator
|
4
|
+
attr_reader :sign, :associativity, :precedence
|
4
5
|
|
5
6
|
def initialize(sign, associativity, precedence)
|
6
7
|
@sign = sign
|
@@ -8,54 +9,42 @@ module Jievro
|
|
8
9
|
@precedence = precedence
|
9
10
|
end
|
10
11
|
|
11
|
-
def sign
|
12
|
-
@sign
|
13
|
-
end
|
14
|
-
|
15
|
-
def associativity
|
16
|
-
@associativity
|
17
|
-
end
|
18
|
-
|
19
|
-
def precedence
|
20
|
-
@precedence
|
21
|
-
end
|
22
|
-
|
23
12
|
def self.get(sign)
|
24
13
|
case sign
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
14
|
+
when '<<', '>>'
|
15
|
+
operator = BinaryOperator.new(sign, :none, 160)
|
16
|
+
when '*', '/', '%', '&*', '&/', '&%', '&'
|
17
|
+
operator = BinaryOperator.new(sign, :left, 150)
|
18
|
+
when '+', '-', '&+', '&-', '|', '^'
|
19
|
+
operator = BinaryOperator.new(sign, :left, 140)
|
20
|
+
when '..<', '...'
|
21
|
+
operator = BinaryOperator.new(sign, :none, 135)
|
22
|
+
when 'is', 'as'
|
23
|
+
operator = BinaryOperator.new(sign, :none, 132)
|
24
|
+
when '<', '<=', '>', '>=', '==', '!=', '===', '!==', '~='
|
25
|
+
operator = BinaryOperator.new(sign, :left, 130)
|
26
|
+
when '&&'
|
27
|
+
operator = BinaryOperator.new(sign, :left, 120)
|
28
|
+
when '||'
|
29
|
+
operator = BinaryOperator.new(sign, :left, 110)
|
30
|
+
when '??'
|
31
|
+
operator = BinaryOperator.new(sign, :right, 110)
|
32
|
+
when '?:'
|
33
|
+
operator = BinaryOperator.new(sign, :right, 100)
|
34
|
+
when '=', '*=', '/=', '%=', '+=', '-=', '<<=', '>>=', '&=', '^=', '|=', '&&=', '||='
|
35
|
+
operator = BinaryOperator.new(sign, :right, 90)
|
36
|
+
else
|
37
|
+
fail "sign #{sign} not managed"
|
49
38
|
end
|
50
39
|
|
51
40
|
operator
|
52
41
|
end
|
53
42
|
|
54
|
-
def self.
|
43
|
+
def self.operator?(sign)
|
55
44
|
begin
|
56
45
|
self.get(sign)
|
57
46
|
is_operator = true
|
58
|
-
rescue
|
47
|
+
rescue StandardError
|
59
48
|
is_operator = false
|
60
49
|
end
|
61
50
|
|
@@ -1,17 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module Jievro
|
2
2
|
grammar ConstantDeclaration
|
3
3
|
|
4
4
|
rule constant_declaration
|
5
5
|
'let' whitespaces:whitespaces pattern_initializer_list:pattern_initializer_list {
|
6
6
|
def tokens
|
7
|
-
|
8
7
|
tokens = []
|
9
8
|
|
10
|
-
tokens.push(
|
11
|
-
type: 'T_LET',
|
12
|
-
value: 'let'
|
13
|
-
})
|
14
|
-
|
9
|
+
tokens.push(T_LET)
|
15
10
|
tokens.concat(whitespaces.tokens)
|
16
11
|
tokens.concat(pattern_initializer_list.tokens)
|
17
12
|
|
@@ -19,7 +14,6 @@ module Kauri
|
|
19
14
|
end
|
20
15
|
|
21
16
|
def ast
|
22
|
-
|
23
17
|
ast = []
|
24
18
|
|
25
19
|
pattern_initializer_list.ast.each { |e|
|
@@ -1,16 +1,58 @@
|
|
1
1
|
require 'jievro/parser/grammar/declaration/constant_declaration'
|
2
2
|
require 'jievro/parser/grammar/declaration/variable_declaration'
|
3
3
|
require 'jievro/parser/grammar/declaration/function_declaration'
|
4
|
+
require 'jievro/parser/grammar/declaration/struct_declaration'
|
5
|
+
require 'jievro/parser/grammar/declaration/protocol_declaration'
|
6
|
+
require 'jievro/parser/grammar/declaration/initializer_declaration'
|
7
|
+
require 'jievro/parser/grammar/declaration/typealias_declaration'
|
4
8
|
|
5
|
-
module
|
9
|
+
module Jievro
|
6
10
|
grammar Declaration
|
7
11
|
|
8
|
-
include
|
9
|
-
include
|
10
|
-
include
|
12
|
+
include Jievro::ConstantDeclaration
|
13
|
+
include Jievro::VariableDeclaration
|
14
|
+
include Jievro::FunctionDeclaration
|
15
|
+
include Jievro::StructDeclaration
|
16
|
+
include Jievro::ProtocolDeclaration
|
17
|
+
include Jievro::InitializerDeclaration
|
18
|
+
include Jievro::TypealiasDeclaration
|
11
19
|
|
12
20
|
rule declaration
|
13
|
-
constant_declaration
|
21
|
+
constant_declaration
|
22
|
+
/
|
23
|
+
variable_declaration
|
24
|
+
/
|
25
|
+
function_declaration
|
26
|
+
/
|
27
|
+
struct_declaration
|
28
|
+
/
|
29
|
+
protocol_declaration
|
30
|
+
/
|
31
|
+
typealias_declaration
|
32
|
+
end
|
33
|
+
|
34
|
+
rule declarations
|
35
|
+
declaration+ {
|
36
|
+
def tokens
|
37
|
+
tokens = []
|
38
|
+
|
39
|
+
elements.each { |e|
|
40
|
+
tokens.concat(e.tokens)
|
41
|
+
}
|
42
|
+
|
43
|
+
tokens
|
44
|
+
end
|
45
|
+
|
46
|
+
def ast
|
47
|
+
ast = []
|
48
|
+
|
49
|
+
elements.each { |e|
|
50
|
+
ast.concat(e.ast)
|
51
|
+
}
|
52
|
+
|
53
|
+
ast
|
54
|
+
end
|
55
|
+
}
|
14
56
|
end
|
15
57
|
end
|
16
58
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Jievro
|
2
2
|
grammar FunctionDeclaration
|
3
3
|
|
4
4
|
rule function_declaration
|
@@ -7,30 +7,17 @@ module Kauri
|
|
7
7
|
tokens = []
|
8
8
|
|
9
9
|
tokens.concat(function_head.tokens)
|
10
|
-
|
11
|
-
unless ws1.text_value.empty?
|
12
|
-
tokens.concat(ws1.tokens)
|
13
|
-
end
|
14
|
-
|
10
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
15
11
|
tokens.concat(function_name.tokens)
|
16
|
-
|
17
|
-
unless ws2.text_value.empty?
|
18
|
-
tokens.concat(ws2.tokens)
|
19
|
-
end
|
20
|
-
|
12
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
21
13
|
tokens.concat(function_signature.tokens)
|
22
|
-
|
23
|
-
unless ws3.text_value.empty?
|
24
|
-
tokens.concat(ws3.tokens)
|
25
|
-
end
|
26
|
-
|
14
|
+
tokens.concat(ws3.tokens) unless ws3.text_value.empty?
|
27
15
|
tokens.concat(function_body.tokens)
|
28
16
|
|
29
17
|
tokens
|
30
18
|
end
|
31
19
|
|
32
20
|
def ast
|
33
|
-
|
34
21
|
signature = function_signature.ast
|
35
22
|
|
36
23
|
name = function_name.ast.first
|
@@ -54,12 +41,7 @@ module Kauri
|
|
54
41
|
rule function_head
|
55
42
|
'func' {
|
56
43
|
def tokens
|
57
|
-
[
|
58
|
-
{
|
59
|
-
type: 'T_FUNCTION',
|
60
|
-
value: 'func'
|
61
|
-
}
|
62
|
-
]
|
44
|
+
[T_FUNCTION]
|
63
45
|
end
|
64
46
|
}
|
65
47
|
end
|
@@ -74,25 +56,15 @@ module Kauri
|
|
74
56
|
tokens = []
|
75
57
|
|
76
58
|
tokens.concat(parameter_clause.tokens)
|
77
|
-
|
78
|
-
unless
|
79
|
-
tokens.concat(ws.tokens)
|
80
|
-
end
|
81
|
-
|
82
|
-
unless return_type.text_value.empty?
|
83
|
-
tokens.concat(return_type.tokens)
|
84
|
-
end
|
59
|
+
tokens.concat(ws.tokens) unless ws.text_value.empty?
|
60
|
+
tokens.concat(return_type.tokens) unless return_type.text_value.empty?
|
85
61
|
|
86
62
|
tokens
|
87
63
|
end
|
88
64
|
|
89
65
|
def ast
|
90
|
-
|
91
66
|
parameters = parameter_clause.ast
|
92
|
-
|
93
|
-
unless return_type.text_value.empty?
|
94
|
-
type = return_type.ast
|
95
|
-
end
|
67
|
+
type = return_type.ast unless return_type.text_value.empty?
|
96
68
|
|
97
69
|
{
|
98
70
|
parameters: parameters,
|
@@ -111,19 +83,9 @@ module Kauri
|
|
111
83
|
def tokens
|
112
84
|
tokens = []
|
113
85
|
|
114
|
-
tokens.push(
|
115
|
-
|
116
|
-
|
117
|
-
})
|
118
|
-
|
119
|
-
unless ws.text_value.empty?
|
120
|
-
tokens.concat(ws.tokens)
|
121
|
-
end
|
122
|
-
|
123
|
-
tokens.push({
|
124
|
-
type: 'T_CLOSE_ROUND_BRACKET',
|
125
|
-
value: ')'
|
126
|
-
})
|
86
|
+
tokens.push(T_OPEN_ROUND_BRACKET)
|
87
|
+
tokens.concat(ws.tokens) unless ws.text_value.empty?
|
88
|
+
tokens.push(T_CLOSE_ROUND_BRACKET)
|
127
89
|
|
128
90
|
tokens
|
129
91
|
end
|
@@ -139,25 +101,11 @@ module Kauri
|
|
139
101
|
def tokens
|
140
102
|
tokens = []
|
141
103
|
|
142
|
-
tokens.push(
|
143
|
-
|
144
|
-
value: '('
|
145
|
-
})
|
146
|
-
|
147
|
-
unless ws1.text_value.empty?
|
148
|
-
tokens.concat(ws1.tokens)
|
149
|
-
end
|
150
|
-
|
104
|
+
tokens.push(T_OPEN_ROUND_BRACKET)
|
105
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
151
106
|
tokens.concat(parameter_list.tokens)
|
152
|
-
|
153
|
-
|
154
|
-
tokens.concat(ws2.tokens)
|
155
|
-
end
|
156
|
-
|
157
|
-
tokens.push({
|
158
|
-
type: 'T_CLOSE_ROUND_BRACKET',
|
159
|
-
value: ')'
|
160
|
-
})
|
107
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
108
|
+
tokens.push(T_CLOSE_ROUND_BRACKET)
|
161
109
|
|
162
110
|
tokens
|
163
111
|
end
|
@@ -176,19 +124,9 @@ module Kauri
|
|
176
124
|
unless head.text_value.empty?
|
177
125
|
head.elements.each { |e|
|
178
126
|
tokens.concat(e.parameter.tokens)
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
tokens.push({
|
185
|
-
type: 'T_COMMA',
|
186
|
-
value: ','
|
187
|
-
})
|
188
|
-
|
189
|
-
unless e.ws2.text_value.empty?
|
190
|
-
tokens.concat(e.ws2.tokens)
|
191
|
-
end
|
127
|
+
tokens.concat(e.ws1.tokens) unless e.ws1.text_value.empty?
|
128
|
+
tokens.push(T_COMMA)
|
129
|
+
tokens.concat(e.ws2.tokens) unless e.ws2.text_value.empty?
|
192
130
|
}
|
193
131
|
end
|
194
132
|
|
@@ -222,35 +160,25 @@ module Kauri
|
|
222
160
|
def tokens
|
223
161
|
tokens = []
|
224
162
|
|
225
|
-
|
226
|
-
|
227
|
-
end
|
163
|
+
tokens.concat(external_parameter_name.tokens) \
|
164
|
+
if defined? external_parameter_name
|
228
165
|
|
229
166
|
if defined? ws1
|
230
|
-
unless ws1.text_value.empty?
|
231
|
-
tokens.concat(ws1.tokens)
|
232
|
-
end
|
167
|
+
tokens.concat(ws1.tokens) unless ws1.text_value.empty?
|
233
168
|
end
|
234
169
|
|
235
170
|
tokens.concat(local_parameter_name.tokens)
|
236
|
-
|
237
|
-
unless ws2.text_value.empty?
|
238
|
-
tokens.concat(ws2.tokens)
|
239
|
-
end
|
240
|
-
|
171
|
+
tokens.concat(ws2.tokens) unless ws2.text_value.empty?
|
241
172
|
tokens.concat(type_annotation.tokens)
|
242
173
|
|
243
174
|
tokens
|
244
175
|
end
|
245
176
|
|
246
177
|
def ast
|
247
|
-
|
248
178
|
type = type_annotation.ast.first
|
249
179
|
local = local_parameter_name.ast.first
|
250
|
-
|
251
|
-
|
252
|
-
external = external_parameter_name.ast.first
|
253
|
-
end
|
180
|
+
external = external_parameter_name.ast.first \
|
181
|
+
if defined? external_parameter_name
|
254
182
|
|
255
183
|
{
|
256
184
|
__type: 'function-declaration-parameter',
|
@@ -276,15 +204,8 @@ module Kauri
|
|
276
204
|
def tokens
|
277
205
|
tokens = []
|
278
206
|
|
279
|
-
tokens.push(
|
280
|
-
|
281
|
-
value: '->'
|
282
|
-
})
|
283
|
-
|
284
|
-
unless ws.text_value.empty?
|
285
|
-
tokens.concat(ws.tokens)
|
286
|
-
end
|
287
|
-
|
207
|
+
tokens.push(T_RETURN_TYPE_ARROW)
|
208
|
+
tokens.concat(ws.tokens) unless ws.text_value.empty?
|
288
209
|
tokens.concat(type.tokens)
|
289
210
|
|
290
211
|
tokens
|