lrama 0.6.9 → 0.6.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yaml +24 -1
- data/.gitignore +2 -0
- data/Gemfile +6 -3
- data/NEWS.md +269 -14
- data/README.md +41 -4
- data/Rakefile +2 -0
- data/Steepfile +9 -17
- data/doc/development/compressed_state_table/main.md +635 -0
- data/doc/development/compressed_state_table/parse.output +174 -0
- data/doc/development/compressed_state_table/parse.y +22 -0
- data/doc/development/compressed_state_table/parser.rb +282 -0
- data/exe/lrama +1 -0
- data/lib/lrama/bitmap.rb +3 -1
- data/lib/lrama/command.rb +8 -14
- data/lib/lrama/context.rb +11 -9
- data/lib/lrama/counterexamples/derivation.rb +8 -5
- data/lib/lrama/counterexamples/example.rb +9 -4
- data/lib/lrama/counterexamples/path.rb +6 -0
- data/lib/lrama/counterexamples/production_path.rb +2 -0
- data/lib/lrama/counterexamples/start_path.rb +2 -0
- data/lib/lrama/counterexamples/state_item.rb +2 -0
- data/lib/lrama/counterexamples/transition_path.rb +2 -0
- data/lib/lrama/counterexamples/triple.rb +2 -0
- data/lib/lrama/counterexamples.rb +36 -24
- data/lib/lrama/diagnostics.rb +36 -0
- data/lib/lrama/digraph.rb +2 -0
- data/lib/lrama/grammar/auxiliary.rb +2 -0
- data/lib/lrama/grammar/binding.rb +12 -1
- data/lib/lrama/grammar/code/destructor_code.rb +2 -0
- data/lib/lrama/grammar/code/initial_action_code.rb +2 -0
- data/lib/lrama/grammar/code/no_reference_code.rb +2 -0
- data/lib/lrama/grammar/code/printer_code.rb +2 -0
- data/lib/lrama/grammar/code/rule_action.rb +7 -3
- data/lib/lrama/grammar/code.rb +7 -5
- data/lib/lrama/grammar/counter.rb +2 -0
- data/lib/lrama/grammar/destructor.rb +2 -0
- data/lib/lrama/grammar/error_token.rb +2 -0
- data/lib/lrama/grammar/parameterizing_rule/resolver.rb +7 -1
- data/lib/lrama/grammar/parameterizing_rule/rhs.rb +6 -3
- data/lib/lrama/grammar/parameterizing_rule/rule.rb +6 -0
- data/lib/lrama/grammar/parameterizing_rule.rb +2 -0
- data/lib/lrama/grammar/percent_code.rb +2 -0
- data/lib/lrama/grammar/precedence.rb +2 -0
- data/lib/lrama/grammar/printer.rb +2 -0
- data/lib/lrama/grammar/reference.rb +2 -0
- data/lib/lrama/grammar/rule.rb +10 -3
- data/lib/lrama/grammar/rule_builder.rb +64 -65
- data/lib/lrama/grammar/symbol.rb +2 -0
- data/lib/lrama/grammar/symbols/resolver.rb +9 -1
- data/lib/lrama/grammar/symbols.rb +2 -0
- data/lib/lrama/grammar/type.rb +2 -0
- data/lib/lrama/grammar/union.rb +2 -0
- data/lib/lrama/grammar.rb +53 -32
- data/lib/lrama/grammar_validator.rb +37 -0
- data/lib/lrama/lexer/grammar_file.rb +2 -0
- data/lib/lrama/lexer/location.rb +2 -0
- data/lib/lrama/lexer/token/char.rb +2 -0
- data/lib/lrama/lexer/token/ident.rb +2 -0
- data/lib/lrama/lexer/token/instantiate_rule.rb +2 -0
- data/lib/lrama/lexer/token/tag.rb +2 -0
- data/lib/lrama/lexer/token/user_code.rb +4 -2
- data/lib/lrama/lexer/token.rb +7 -5
- data/lib/lrama/lexer.rb +12 -8
- data/lib/lrama/{warning.rb → logger.rb} +5 -13
- data/lib/lrama/option_parser.rb +58 -33
- data/lib/lrama/options.rb +5 -2
- data/lib/lrama/output.rb +38 -69
- data/lib/lrama/parser.rb +677 -773
- data/lib/lrama/report/duration.rb +2 -0
- data/lib/lrama/report/profile.rb +2 -0
- data/lib/lrama/report.rb +4 -2
- data/lib/lrama/state/reduce.rb +4 -2
- data/lib/lrama/state/reduce_reduce_conflict.rb +2 -0
- data/lib/lrama/state/resolved_conflict.rb +3 -1
- data/lib/lrama/state/shift.rb +2 -0
- data/lib/lrama/state/shift_reduce_conflict.rb +2 -0
- data/lib/lrama/state.rb +7 -5
- data/lib/lrama/states/item.rb +5 -3
- data/lib/lrama/states.rb +18 -46
- data/lib/lrama/states_reporter.rb +60 -19
- data/lib/lrama/trace_reporter.rb +30 -0
- data/lib/lrama/version.rb +3 -1
- data/lib/lrama.rb +22 -17
- data/lrama.gemspec +3 -1
- data/parser.y +129 -237
- data/rbs_collection.lock.yaml +10 -2
- data/sig/lrama/counterexamples/derivation.rbs +33 -0
- data/sig/lrama/counterexamples/example.rbs +45 -0
- data/sig/lrama/counterexamples/path.rbs +21 -0
- data/sig/lrama/counterexamples/production_path.rbs +11 -0
- data/sig/lrama/counterexamples/start_path.rbs +13 -0
- data/sig/lrama/counterexamples/state_item.rbs +10 -0
- data/sig/lrama/counterexamples/transition_path.rbs +11 -0
- data/sig/lrama/counterexamples/triple.rbs +20 -0
- data/sig/lrama/counterexamples.rbs +29 -0
- data/sig/lrama/grammar/auxiliary.rbs +10 -0
- data/sig/lrama/grammar/binding.rbs +4 -0
- data/sig/lrama/grammar/code/destructor_code.rbs +3 -4
- data/sig/lrama/grammar/code/initial_action_code.rbs +15 -0
- data/sig/lrama/grammar/code/no_reference_code.rbs +15 -0
- data/sig/lrama/grammar/code/printer_code.rbs +3 -4
- data/sig/lrama/grammar/code/rule_action.rbs +19 -0
- data/sig/lrama/grammar/code.rbs +3 -3
- data/sig/lrama/grammar/destructor.rbs +3 -1
- data/sig/lrama/grammar/error_token.rbs +4 -2
- data/sig/lrama/grammar/parameterizing_rule/resolver.rbs +2 -1
- data/sig/lrama/grammar/parameterizing_rule/rhs.rbs +1 -1
- data/sig/lrama/grammar/precedence.rbs +3 -1
- data/sig/lrama/grammar/printer.rbs +3 -1
- data/sig/lrama/grammar/rule.rbs +35 -3
- data/sig/lrama/grammar/rule_builder.rbs +10 -9
- data/sig/lrama/grammar/symbol.rbs +6 -6
- data/sig/lrama/grammar/symbols/resolver.rbs +24 -5
- data/sig/lrama/grammar/type.rbs +2 -2
- data/sig/lrama/grammar/union.rbs +12 -0
- data/sig/lrama/grammar.rbs +104 -1
- data/sig/lrama/options.rbs +3 -2
- data/sig/lrama/state/reduce.rbs +20 -0
- data/sig/lrama/state/reduce_reduce_conflict.rbs +13 -0
- data/sig/lrama/state/resolved_conflict.rbs +14 -0
- data/sig/lrama/state/shift.rbs +14 -0
- data/sig/lrama/state/shift_reduce_conflict.rbs +13 -0
- data/sig/lrama/state.rbs +79 -0
- data/sig/lrama/states/item.rbs +30 -0
- data/sig/lrama/states.rbs +101 -0
- data/template/bison/yacc.c +24 -19
- metadata +32 -6
- data/sample/calc.output +0 -263
- data/sample/calc.y +0 -101
- data/sample/parse.y +0 -59
data/parser.y
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
class Lrama::Parser
|
2
2
|
expect 0
|
3
|
+
error_on_expect_mismatch
|
3
4
|
|
4
5
|
token C_DECLARATION CHARACTER IDENT_COLON IDENTIFIER INTEGER STRING TAG
|
5
6
|
|
6
7
|
rule
|
7
8
|
|
8
|
-
input:
|
9
|
-
|
10
|
-
prologue_declarations: # empty
|
11
|
-
| prologue_declarations prologue_declaration
|
9
|
+
input: prologue_declaration* bison_declaration* "%%" rules_or_grammar_declaration+ epilogue_declaration?
|
12
10
|
|
13
11
|
prologue_declaration: "%{"
|
14
12
|
{
|
@@ -25,116 +23,66 @@ rule
|
|
25
23
|
}
|
26
24
|
| "%require" STRING
|
27
25
|
|
28
|
-
bison_declarations: /* empty */ { result = "" }
|
29
|
-
| bison_declarations bison_declaration
|
30
|
-
|
31
26
|
bison_declaration: grammar_declaration
|
32
|
-
| rule_declaration
|
33
|
-
| inline_declaration
|
34
27
|
| "%expect" INTEGER { @grammar.expect = val[1] }
|
35
28
|
| "%define" variable value
|
36
|
-
| "%param"
|
37
|
-
| "%lex-param"
|
29
|
+
| "%param" param+
|
30
|
+
| "%lex-param" param+
|
38
31
|
{
|
39
32
|
val[1].each {|token|
|
40
33
|
@grammar.lex_param = Grammar::Code::NoReferenceCode.new(type: :lex_param, token_code: token).token_code.s_value
|
41
34
|
}
|
42
35
|
}
|
43
|
-
| "%parse-param"
|
36
|
+
| "%parse-param" param+
|
44
37
|
{
|
45
38
|
val[1].each {|token|
|
46
39
|
@grammar.parse_param = Grammar::Code::NoReferenceCode.new(type: :parse_param, token_code: token).token_code.s_value
|
47
40
|
}
|
48
41
|
}
|
49
|
-
| "%code" IDENTIFIER
|
50
|
-
{
|
51
|
-
begin_c_declaration("}")
|
52
|
-
}
|
53
|
-
C_DECLARATION
|
54
|
-
{
|
55
|
-
end_c_declaration
|
56
|
-
}
|
57
|
-
"}"
|
42
|
+
| "%code" IDENTIFIER param
|
58
43
|
{
|
59
|
-
@grammar.add_percent_code(id: val[1], code: val[
|
44
|
+
@grammar.add_percent_code(id: val[1], code: val[2])
|
60
45
|
}
|
61
|
-
| "%initial-action"
|
46
|
+
| "%initial-action" param
|
62
47
|
{
|
63
|
-
|
64
|
-
}
|
65
|
-
C_DECLARATION
|
66
|
-
{
|
67
|
-
end_c_declaration
|
68
|
-
}
|
69
|
-
"}"
|
70
|
-
{
|
71
|
-
@grammar.initial_action = Grammar::Code::InitialActionCode.new(type: :initial_action, token_code: val[3])
|
48
|
+
@grammar.initial_action = Grammar::Code::InitialActionCode.new(type: :initial_action, token_code: val[1])
|
72
49
|
}
|
73
50
|
| "%no-stdlib" { @grammar.no_stdlib = true }
|
74
|
-
| "
|
51
|
+
| "%locations" { @grammar.locations = true }
|
52
|
+
| bison_declaration ";"
|
75
53
|
|
76
|
-
grammar_declaration: "%union"
|
77
|
-
{
|
78
|
-
begin_c_declaration("}")
|
79
|
-
}
|
80
|
-
C_DECLARATION
|
81
|
-
{
|
82
|
-
end_c_declaration
|
83
|
-
}
|
84
|
-
"}"
|
54
|
+
grammar_declaration: "%union" param
|
85
55
|
{
|
86
56
|
@grammar.set_union(
|
87
|
-
Grammar::Code::NoReferenceCode.new(type: :union, token_code: val[
|
88
|
-
val[
|
57
|
+
Grammar::Code::NoReferenceCode.new(type: :union, token_code: val[1]),
|
58
|
+
val[1].line
|
89
59
|
)
|
90
60
|
}
|
91
61
|
| symbol_declaration
|
92
|
-
|
|
93
|
-
|
94
|
-
|
95
|
-
}
|
96
|
-
C_DECLARATION
|
97
|
-
{
|
98
|
-
end_c_declaration
|
99
|
-
}
|
100
|
-
"}" generic_symlist
|
62
|
+
| rule_declaration
|
63
|
+
| inline_declaration
|
64
|
+
| "%destructor" param (symbol | TAG)+
|
101
65
|
{
|
102
66
|
@grammar.add_destructor(
|
103
|
-
ident_or_tags: val[
|
104
|
-
token_code: val[
|
105
|
-
lineno: val[
|
67
|
+
ident_or_tags: val[2].flatten,
|
68
|
+
token_code: val[1],
|
69
|
+
lineno: val[1].line
|
106
70
|
)
|
107
71
|
}
|
108
|
-
| "%printer"
|
109
|
-
{
|
110
|
-
begin_c_declaration("}")
|
111
|
-
}
|
112
|
-
C_DECLARATION
|
113
|
-
{
|
114
|
-
end_c_declaration
|
115
|
-
}
|
116
|
-
"}" generic_symlist
|
72
|
+
| "%printer" param (symbol | TAG)+
|
117
73
|
{
|
118
74
|
@grammar.add_printer(
|
119
|
-
ident_or_tags: val[
|
120
|
-
token_code: val[
|
121
|
-
lineno: val[
|
75
|
+
ident_or_tags: val[2].flatten,
|
76
|
+
token_code: val[1],
|
77
|
+
lineno: val[1].line
|
122
78
|
)
|
123
79
|
}
|
124
|
-
| "%error-token"
|
125
|
-
{
|
126
|
-
begin_c_declaration("}")
|
127
|
-
}
|
128
|
-
C_DECLARATION
|
129
|
-
{
|
130
|
-
end_c_declaration
|
131
|
-
}
|
132
|
-
"}" generic_symlist
|
80
|
+
| "%error-token" param (symbol | TAG)+
|
133
81
|
{
|
134
82
|
@grammar.add_error_token(
|
135
|
-
ident_or_tags: val[
|
136
|
-
token_code: val[
|
137
|
-
lineno: val[
|
83
|
+
ident_or_tags: val[2].flatten,
|
84
|
+
token_code: val[1],
|
85
|
+
lineno: val[1].line
|
138
86
|
)
|
139
87
|
}
|
140
88
|
| "%after-shift" IDENTIFIER
|
@@ -167,6 +115,18 @@ rule
|
|
167
115
|
}
|
168
116
|
}
|
169
117
|
}
|
118
|
+
| "%nterm" symbol_declarations
|
119
|
+
{
|
120
|
+
val[1].each {|hash|
|
121
|
+
hash[:tokens].each {|id|
|
122
|
+
if @grammar.find_term_by_s_value(id.s_value)
|
123
|
+
on_action_error("symbol #{id.s_value} redeclared as a nonterminal", id)
|
124
|
+
else
|
125
|
+
@grammar.add_type(id: id, tag: hash[:tag])
|
126
|
+
end
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
170
130
|
| "%left" token_declarations_for_precedence
|
171
131
|
{
|
172
132
|
val[1].each {|hash|
|
@@ -208,41 +168,37 @@ rule
|
|
208
168
|
@precedence_number += 1
|
209
169
|
}
|
210
170
|
|
211
|
-
token_declarations:
|
212
|
-
{
|
213
|
-
val[0].each {|token_declaration|
|
214
|
-
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: nil, replace: true)
|
215
|
-
}
|
216
|
-
}
|
217
|
-
| TAG token_declaration_list
|
171
|
+
token_declarations: TAG? token_declaration+
|
218
172
|
{
|
219
173
|
val[1].each {|token_declaration|
|
220
174
|
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[0], replace: true)
|
221
175
|
}
|
222
176
|
}
|
223
|
-
| token_declarations TAG
|
177
|
+
| token_declarations TAG token_declaration+
|
224
178
|
{
|
225
179
|
val[2].each {|token_declaration|
|
226
180
|
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[1], replace: true)
|
227
181
|
}
|
228
182
|
}
|
229
183
|
|
230
|
-
|
231
|
-
| token_declaration_list token_declaration { result = val[0].append(val[1]) }
|
232
|
-
|
233
|
-
token_declaration: id int_opt alias { result = val }
|
184
|
+
token_declaration: id INTEGER? alias { result = val }
|
234
185
|
|
235
|
-
rule_declaration: "%rule" IDENTIFIER "(" rule_args ")"
|
186
|
+
rule_declaration: "%rule" IDENTIFIER "(" rule_args ")" TAG? ":" rule_rhs_list
|
236
187
|
{
|
237
188
|
rule = Grammar::ParameterizingRule::Rule.new(val[1].s_value, val[3], val[7], tag: val[5])
|
238
189
|
@grammar.add_parameterizing_rule(rule)
|
239
190
|
}
|
240
191
|
|
241
|
-
inline_declaration: "%rule" "%inline"
|
192
|
+
inline_declaration: "%rule" "%inline" IDENT_COLON ":" rule_rhs_list
|
242
193
|
{
|
243
194
|
rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, [], val[4], is_inline: true)
|
244
195
|
@grammar.add_parameterizing_rule(rule)
|
245
196
|
}
|
197
|
+
| "%rule" "%inline" IDENTIFIER "(" rule_args ")" ":" rule_rhs_list
|
198
|
+
{
|
199
|
+
rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, val[4], val[7], is_inline: true)
|
200
|
+
@grammar.add_parameterizing_rule(rule)
|
201
|
+
}
|
246
202
|
|
247
203
|
rule_args: IDENTIFIER { result = [val[0]] }
|
248
204
|
| rule_args "," IDENTIFIER { result = val[0].append(val[2]) }
|
@@ -258,17 +214,12 @@ rule
|
|
258
214
|
result = val[0].append(builder)
|
259
215
|
}
|
260
216
|
|
261
|
-
rule_rhs:
|
217
|
+
rule_rhs: "%empty"?
|
262
218
|
{
|
263
219
|
reset_precs
|
264
220
|
result = Grammar::ParameterizingRule::Rhs.new
|
265
221
|
}
|
266
|
-
|
|
267
|
-
{
|
268
|
-
reset_precs
|
269
|
-
result = Grammar::ParameterizingRule::Rhs.new
|
270
|
-
}
|
271
|
-
| rule_rhs symbol named_ref_opt
|
222
|
+
| rule_rhs symbol named_ref?
|
272
223
|
{
|
273
224
|
token = val[1]
|
274
225
|
token.alias_name = val[2]
|
@@ -282,28 +233,16 @@ rule
|
|
282
233
|
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]])
|
283
234
|
result = builder
|
284
235
|
}
|
285
|
-
| rule_rhs IDENTIFIER "(" parameterizing_args ")"
|
236
|
+
| rule_rhs IDENTIFIER "(" parameterizing_args ")" TAG?
|
286
237
|
{
|
287
238
|
builder = val[0]
|
288
239
|
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5])
|
289
240
|
result = builder
|
290
241
|
}
|
291
|
-
| rule_rhs
|
292
|
-
{
|
293
|
-
if @prec_seen
|
294
|
-
on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec
|
295
|
-
@code_after_prec = true
|
296
|
-
end
|
297
|
-
begin_c_declaration("}")
|
298
|
-
}
|
299
|
-
C_DECLARATION
|
300
|
-
{
|
301
|
-
end_c_declaration
|
302
|
-
}
|
303
|
-
"}" named_ref_opt
|
242
|
+
| rule_rhs midrule_action named_ref?
|
304
243
|
{
|
305
|
-
user_code = val[
|
306
|
-
user_code.alias_name = val[
|
244
|
+
user_code = val[1]
|
245
|
+
user_code.alias_name = val[2]
|
307
246
|
builder = val[0]
|
308
247
|
builder.user_code = user_code
|
309
248
|
result = builder
|
@@ -317,84 +256,45 @@ rule
|
|
317
256
|
result = builder
|
318
257
|
}
|
319
258
|
|
320
|
-
|
321
|
-
| INTEGER
|
259
|
+
alias: string_as_id? { result = val[0].s_value if val[0] }
|
322
260
|
|
323
|
-
|
324
|
-
| STRING # TODO: change this to string_as_id
|
325
|
-
|
326
|
-
symbol_declarations: symbol_declaration_list
|
327
|
-
{
|
328
|
-
result = [{tag: nil, tokens: val[0]}]
|
329
|
-
}
|
330
|
-
| TAG symbol_declaration_list
|
331
|
-
{
|
332
|
-
result = [{tag: val[0], tokens: val[1]}]
|
333
|
-
}
|
334
|
-
| symbol_declarations TAG symbol_declaration_list
|
261
|
+
symbol_declarations: TAG? symbol+
|
335
262
|
{
|
336
|
-
|
263
|
+
result = if val[0]
|
264
|
+
[{tag: val[0], tokens: val[1]}]
|
265
|
+
else
|
266
|
+
[{tag: nil, tokens: val[1]}]
|
267
|
+
end
|
337
268
|
}
|
338
|
-
|
339
|
-
symbol_declaration_list: symbol { result = [val[0]] }
|
340
|
-
| symbol_declaration_list symbol { result = val[0].append(val[1]) }
|
269
|
+
| symbol_declarations TAG symbol+ { result = val[0].append({tag: val[1], tokens: val[2]}) }
|
341
270
|
|
342
271
|
symbol: id
|
343
272
|
| string_as_id
|
344
273
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
}
|
361
|
-
C_DECLARATION
|
362
|
-
{
|
363
|
-
end_c_declaration
|
364
|
-
}
|
365
|
-
"}"
|
366
|
-
{
|
367
|
-
result = [val[2]]
|
368
|
-
}
|
369
|
-
|
370
|
-
token_declarations_for_precedence: token_declaration_list_for_precedence
|
371
|
-
{
|
372
|
-
result = [{tag: nil, tokens: val[0]}]
|
373
|
-
}
|
374
|
-
| TAG token_declaration_list_for_precedence
|
375
|
-
{
|
376
|
-
result = [{tag: val[0], tokens: val[1]}]
|
377
|
-
}
|
378
|
-
| token_declarations_for_precedence TAG token_declaration_list_for_precedence
|
379
|
-
{
|
380
|
-
result = val[0].append({tag: val[1], tokens: val[2]})
|
381
|
-
}
|
382
|
-
|
383
|
-
token_declaration_list_for_precedence: token_declaration_for_precedence { result = [val[0]] }
|
384
|
-
| token_declaration_list_for_precedence token_declaration_for_precedence { result = val[0].append(val[1]) }
|
385
|
-
|
386
|
-
token_declaration_for_precedence: id
|
274
|
+
param: "{" {
|
275
|
+
begin_c_declaration("}")
|
276
|
+
}
|
277
|
+
C_DECLARATION
|
278
|
+
{
|
279
|
+
end_c_declaration
|
280
|
+
}
|
281
|
+
"}"
|
282
|
+
{
|
283
|
+
result = val[2]
|
284
|
+
}
|
285
|
+
|
286
|
+
token_declarations_for_precedence: id+ { result = [{tag: nil, tokens: val[0]}] }
|
287
|
+
| TAG id+ { result = [{tag: val[0], tokens: val[1]}] }
|
288
|
+
| id TAG id+ { result = val[0].append({tag: val[1], tokens: val[2]}) }
|
387
289
|
|
388
290
|
id: IDENTIFIER { on_action_error("ident after %prec", val[0]) if @prec_seen }
|
389
291
|
| CHARACTER { on_action_error("char after %prec", val[0]) if @prec_seen }
|
390
292
|
|
391
|
-
grammar: rules_or_grammar_declaration
|
392
|
-
| grammar rules_or_grammar_declaration
|
393
293
|
|
394
|
-
rules_or_grammar_declaration: rules
|
294
|
+
rules_or_grammar_declaration: rules ";"?
|
395
295
|
| grammar_declaration ";"
|
396
296
|
|
397
|
-
rules:
|
297
|
+
rules: IDENT_COLON named_ref? ":" rhs_list
|
398
298
|
{
|
399
299
|
lhs = val[0]
|
400
300
|
lhs.alias_name = val[1]
|
@@ -421,19 +321,13 @@ rule
|
|
421
321
|
end
|
422
322
|
result = val[0].append(builder)
|
423
323
|
}
|
424
|
-
| rhs_list ";"
|
425
324
|
|
426
|
-
rhs:
|
427
|
-
{
|
428
|
-
reset_precs
|
429
|
-
result = Grammar::RuleBuilder.new(@rule_counter, @midrule_action_counter)
|
430
|
-
}
|
431
|
-
| "%empty"
|
325
|
+
rhs: "%empty"?
|
432
326
|
{
|
433
327
|
reset_precs
|
434
|
-
result =
|
328
|
+
result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter)
|
435
329
|
}
|
436
|
-
| rhs symbol
|
330
|
+
| rhs symbol named_ref?
|
437
331
|
{
|
438
332
|
token = val[1]
|
439
333
|
token.alias_name = val[2]
|
@@ -441,39 +335,27 @@ rule
|
|
441
335
|
builder.add_rhs(token)
|
442
336
|
result = builder
|
443
337
|
}
|
444
|
-
| rhs symbol parameterizing_suffix
|
338
|
+
| rhs symbol parameterizing_suffix named_ref? TAG?
|
445
339
|
{
|
446
|
-
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]], lhs_tag: val[
|
340
|
+
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], alias_name: val[3], location: @lexer.location, args: [val[1]], lhs_tag: val[4])
|
447
341
|
builder = val[0]
|
448
342
|
builder.add_rhs(token)
|
449
343
|
builder.line = val[1].first_line
|
450
344
|
result = builder
|
451
345
|
}
|
452
|
-
| rhs IDENTIFIER "(" parameterizing_args ")"
|
346
|
+
| rhs IDENTIFIER "(" parameterizing_args ")" named_ref? TAG?
|
453
347
|
{
|
454
|
-
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[
|
348
|
+
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6])
|
455
349
|
builder = val[0]
|
456
350
|
builder.add_rhs(token)
|
457
351
|
builder.line = val[1].first_line
|
458
352
|
result = builder
|
459
353
|
}
|
460
|
-
| rhs
|
354
|
+
| rhs midrule_action named_ref? TAG?
|
461
355
|
{
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
end
|
466
|
-
begin_c_declaration("}")
|
467
|
-
}
|
468
|
-
C_DECLARATION
|
469
|
-
{
|
470
|
-
end_c_declaration
|
471
|
-
}
|
472
|
-
"}" named_ref_opt tag_opt
|
473
|
-
{
|
474
|
-
user_code = val[3]
|
475
|
-
user_code.alias_name = val[6]
|
476
|
-
user_code.tag = val[7]
|
356
|
+
user_code = val[1]
|
357
|
+
user_code.alias_name = val[2]
|
358
|
+
user_code.tag = val[3]
|
477
359
|
builder = val[0]
|
478
360
|
builder.user_code = user_code
|
479
361
|
result = builder
|
@@ -491,27 +373,46 @@ rule
|
|
491
373
|
| "+" { result = "nonempty_list" }
|
492
374
|
| "*" { result = "list" }
|
493
375
|
|
494
|
-
parameterizing_args: symbol
|
376
|
+
parameterizing_args: symbol parameterizing_suffix?
|
377
|
+
{
|
378
|
+
result = if val[1]
|
379
|
+
[Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])]
|
380
|
+
else
|
381
|
+
[val[0]]
|
382
|
+
end
|
383
|
+
}
|
495
384
|
| parameterizing_args ',' symbol { result = val[0].append(val[2]) }
|
496
|
-
| symbol parameterizing_suffix { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] }
|
497
385
|
| IDENTIFIER "(" parameterizing_args ")" { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] }
|
498
386
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
387
|
+
midrule_action: "{"
|
388
|
+
{
|
389
|
+
if @prec_seen
|
390
|
+
on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec
|
391
|
+
@code_after_prec = true
|
392
|
+
end
|
393
|
+
begin_c_declaration("}")
|
394
|
+
}
|
395
|
+
C_DECLARATION
|
396
|
+
{
|
397
|
+
end_c_declaration
|
398
|
+
}
|
399
|
+
"}"
|
400
|
+
{
|
401
|
+
result = val[2]
|
402
|
+
}
|
403
|
+
|
404
|
+
named_ref: '[' IDENTIFIER ']' { result = val[1].s_value }
|
405
|
+
|
406
|
+
epilogue_declaration: "%%"
|
407
|
+
{
|
408
|
+
begin_c_declaration('\Z')
|
409
|
+
@grammar.epilogue_first_lineno = @lexer.line + 1
|
410
|
+
}
|
411
|
+
C_DECLARATION
|
412
|
+
{
|
413
|
+
end_c_declaration
|
414
|
+
@grammar.epilogue = val[2].s_value
|
415
|
+
}
|
515
416
|
|
516
417
|
variable: id
|
517
418
|
|
@@ -520,16 +421,7 @@ rule
|
|
520
421
|
| STRING
|
521
422
|
| "{...}"
|
522
423
|
|
523
|
-
generic_symlist: generic_symlist_item { result = [val[0]] }
|
524
|
-
| generic_symlist generic_symlist_item { result = val[0].append(val[1]) }
|
525
|
-
|
526
|
-
generic_symlist_item: symbol
|
527
|
-
| TAG
|
528
|
-
|
529
424
|
string_as_id: STRING { result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) }
|
530
|
-
|
531
|
-
tag_opt: # empty
|
532
|
-
| TAG
|
533
425
|
end
|
534
426
|
|
535
427
|
---- inner
|
data/rbs_collection.lock.yaml
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
---
|
2
2
|
path: ".gem_rbs_collection"
|
3
3
|
gems:
|
4
|
+
- name: diff-lcs
|
5
|
+
version: '1.5'
|
6
|
+
source:
|
7
|
+
type: git
|
8
|
+
name: ruby/gem_rbs_collection
|
9
|
+
revision: 71fb7ae83789ae150bdee1cd8a7cd3035b5d79e2
|
10
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
11
|
+
repo_dir: gems
|
4
12
|
- name: erb
|
5
13
|
version: '0'
|
6
14
|
source:
|
@@ -18,7 +26,7 @@ gems:
|
|
18
26
|
source:
|
19
27
|
type: git
|
20
28
|
name: ruby/gem_rbs_collection
|
21
|
-
revision:
|
29
|
+
revision: 71fb7ae83789ae150bdee1cd8a7cd3035b5d79e2
|
22
30
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
23
31
|
repo_dir: gems
|
24
32
|
- name: stackprof
|
@@ -26,7 +34,7 @@ gems:
|
|
26
34
|
source:
|
27
35
|
type: git
|
28
36
|
name: ruby/gem_rbs_collection
|
29
|
-
revision:
|
37
|
+
revision: 71fb7ae83789ae150bdee1cd8a7cd3035b5d79e2
|
30
38
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
31
39
|
repo_dir: gems
|
32
40
|
- name: strscan
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Counterexamples
|
3
|
+
class Derivation
|
4
|
+
@item: States::Item
|
5
|
+
|
6
|
+
@left: Derivation?
|
7
|
+
|
8
|
+
@right: Derivation?
|
9
|
+
|
10
|
+
attr_reader item: States::Item
|
11
|
+
|
12
|
+
attr_reader left: Derivation?
|
13
|
+
|
14
|
+
attr_reader right: Derivation?
|
15
|
+
|
16
|
+
attr_writer right: Derivation?
|
17
|
+
|
18
|
+
def initialize: (States::Item item, Derivation? left, ?Derivation? right) -> void
|
19
|
+
|
20
|
+
def to_s: () -> ::String
|
21
|
+
|
22
|
+
alias inspect to_s
|
23
|
+
|
24
|
+
def render_strings_for_report: () -> Array[String]
|
25
|
+
|
26
|
+
def render_for_report: () -> String
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def _render_for_report: (Derivation derivation, Integer offset, Array[String] strings, Integer index) -> Integer
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Counterexamples
|
3
|
+
class Example
|
4
|
+
@path1: ::Array[StartPath | TransitionPath | ProductionPath]
|
5
|
+
|
6
|
+
@path2: ::Array[StartPath | TransitionPath | ProductionPath]
|
7
|
+
|
8
|
+
@conflict: (State::ShiftReduceConflict | State::ReduceReduceConflict)
|
9
|
+
|
10
|
+
@conflict_symbol: Grammar::Symbol
|
11
|
+
|
12
|
+
@counterexamples: Counterexamples
|
13
|
+
|
14
|
+
@derivations1: Derivation
|
15
|
+
|
16
|
+
@derivations2: Derivation
|
17
|
+
|
18
|
+
attr_reader path1: ::Array[StartPath | TransitionPath | ProductionPath]
|
19
|
+
|
20
|
+
attr_reader path2: ::Array[StartPath | TransitionPath | ProductionPath]
|
21
|
+
|
22
|
+
attr_reader conflict: (State::ShiftReduceConflict | State::ReduceReduceConflict)
|
23
|
+
|
24
|
+
attr_reader conflict_symbol: Grammar::Symbol
|
25
|
+
|
26
|
+
def initialize: (::Array[StartPath | TransitionPath | ProductionPath]? path1, ::Array[StartPath | TransitionPath | ProductionPath]? path2, (State::ShiftReduceConflict | State::ReduceReduceConflict) conflict, Grammar::Symbol conflict_symbol, Counterexamples counterexamples) -> void
|
27
|
+
|
28
|
+
def type: () -> (:shift_reduce | :reduce_reduce)
|
29
|
+
|
30
|
+
def path1_item: () -> States::Item
|
31
|
+
|
32
|
+
def path2_item: () -> States::Item
|
33
|
+
|
34
|
+
def derivations1: () -> Derivation
|
35
|
+
|
36
|
+
def derivations2: () -> Derivation
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def _derivations: (::Array[StartPath | TransitionPath | ProductionPath] paths) -> Derivation
|
41
|
+
|
42
|
+
def find_derivation_for_symbol: (StateItem state_item, Grammar::Symbol sym) -> Derivation?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Counterexamples
|
3
|
+
class Path
|
4
|
+
@from_state_item: StateItem?
|
5
|
+
|
6
|
+
@to_state_item: StateItem
|
7
|
+
|
8
|
+
def initialize: (StateItem? from_state_item, StateItem to_state_item) -> void
|
9
|
+
|
10
|
+
def from: () -> StateItem?
|
11
|
+
|
12
|
+
def to: () -> StateItem
|
13
|
+
|
14
|
+
def to_s: () -> ::String
|
15
|
+
|
16
|
+
alias inspect to_s
|
17
|
+
|
18
|
+
def type: -> bot
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|