lrama 0.6.9 → 0.6.10
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 +19 -0
- data/.gitignore +2 -0
- data/Gemfile +6 -3
- data/NEWS.md +220 -0
- data/README.md +41 -4
- data/Rakefile +2 -0
- data/Steepfile +6 -17
- data/exe/lrama +1 -0
- data/lib/lrama/bitmap.rb +2 -0
- data/lib/lrama/command.rb +8 -14
- data/lib/lrama/context.rb +8 -6
- data/lib/lrama/counterexamples/derivation.rb +2 -0
- data/lib/lrama/counterexamples/example.rb +2 -0
- data/lib/lrama/counterexamples/path.rb +2 -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 +17 -15
- 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 +5 -2
- 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 +5 -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 +51 -30
- 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 +3 -1
- data/lib/lrama/lexer/token.rb +7 -5
- data/lib/lrama/lexer.rb +11 -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 +650 -779
- 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 +3 -0
- 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 +110 -229
- 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 +22 -3
- data/sig/lrama/grammar/type.rbs +2 -2
- data/sig/lrama/grammar/union.rbs +12 -0
- data/sig/lrama/grammar.rbs +91 -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/states/item.rbs +30 -0
- data/template/bison/yacc.c +24 -19
- metadata +17 -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
|
-
"}"
|
58
|
-
{
|
59
|
-
@grammar.add_percent_code(id: val[1], code: val[4])
|
60
|
-
}
|
61
|
-
| "%initial-action" "{"
|
62
|
-
{
|
63
|
-
begin_c_declaration("}")
|
64
|
-
}
|
65
|
-
C_DECLARATION
|
42
|
+
| "%code" IDENTIFIER param
|
66
43
|
{
|
67
|
-
|
44
|
+
@grammar.add_percent_code(id: val[1], code: val[2])
|
68
45
|
}
|
69
|
-
|
46
|
+
| "%initial-action" param
|
70
47
|
{
|
71
|
-
@grammar.initial_action = Grammar::Code::InitialActionCode.new(type: :initial_action, token_code: val[
|
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 generic_symbol+
|
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],
|
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 generic_symbol+
|
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],
|
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 generic_symbol+
|
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],
|
84
|
+
token_code: val[1],
|
85
|
+
lineno: val[1].line
|
138
86
|
)
|
139
87
|
}
|
140
88
|
| "%after-shift" IDENTIFIER
|
@@ -208,41 +156,43 @@ rule
|
|
208
156
|
@precedence_number += 1
|
209
157
|
}
|
210
158
|
|
211
|
-
token_declarations:
|
159
|
+
token_declarations: token_declaration+
|
212
160
|
{
|
213
161
|
val[0].each {|token_declaration|
|
214
162
|
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: nil, replace: true)
|
215
163
|
}
|
216
164
|
}
|
217
|
-
| TAG
|
165
|
+
| TAG token_declaration+
|
218
166
|
{
|
219
167
|
val[1].each {|token_declaration|
|
220
168
|
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[0], replace: true)
|
221
169
|
}
|
222
170
|
}
|
223
|
-
| token_declarations TAG
|
171
|
+
| token_declarations TAG token_declaration+
|
224
172
|
{
|
225
173
|
val[2].each {|token_declaration|
|
226
174
|
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[1], replace: true)
|
227
175
|
}
|
228
176
|
}
|
229
177
|
|
230
|
-
|
231
|
-
| token_declaration_list token_declaration { result = val[0].append(val[1]) }
|
232
|
-
|
233
|
-
token_declaration: id int_opt alias { result = val }
|
178
|
+
token_declaration: id INTEGER? alias { result = val }
|
234
179
|
|
235
|
-
rule_declaration: "%rule" IDENTIFIER "(" rule_args ")"
|
180
|
+
rule_declaration: "%rule" IDENTIFIER "(" rule_args ")" TAG? ":" rule_rhs_list
|
236
181
|
{
|
237
182
|
rule = Grammar::ParameterizingRule::Rule.new(val[1].s_value, val[3], val[7], tag: val[5])
|
238
183
|
@grammar.add_parameterizing_rule(rule)
|
239
184
|
}
|
240
185
|
|
241
|
-
inline_declaration: "%rule" "%inline"
|
186
|
+
inline_declaration: "%rule" "%inline" IDENT_COLON ":" rule_rhs_list
|
242
187
|
{
|
243
188
|
rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, [], val[4], is_inline: true)
|
244
189
|
@grammar.add_parameterizing_rule(rule)
|
245
190
|
}
|
191
|
+
| "%rule" "%inline" IDENTIFIER "(" rule_args ")" ":" rule_rhs_list
|
192
|
+
{
|
193
|
+
rule = Grammar::ParameterizingRule::Rule.new(val[2].s_value, val[4], val[7], is_inline: true)
|
194
|
+
@grammar.add_parameterizing_rule(rule)
|
195
|
+
}
|
246
196
|
|
247
197
|
rule_args: IDENTIFIER { result = [val[0]] }
|
248
198
|
| rule_args "," IDENTIFIER { result = val[0].append(val[2]) }
|
@@ -258,17 +208,12 @@ rule
|
|
258
208
|
result = val[0].append(builder)
|
259
209
|
}
|
260
210
|
|
261
|
-
rule_rhs:
|
211
|
+
rule_rhs: empty
|
262
212
|
{
|
263
213
|
reset_precs
|
264
214
|
result = Grammar::ParameterizingRule::Rhs.new
|
265
215
|
}
|
266
|
-
|
|
267
|
-
{
|
268
|
-
reset_precs
|
269
|
-
result = Grammar::ParameterizingRule::Rhs.new
|
270
|
-
}
|
271
|
-
| rule_rhs symbol named_ref_opt
|
216
|
+
| rule_rhs symbol named_ref?
|
272
217
|
{
|
273
218
|
token = val[1]
|
274
219
|
token.alias_name = val[2]
|
@@ -282,28 +227,16 @@ rule
|
|
282
227
|
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]])
|
283
228
|
result = builder
|
284
229
|
}
|
285
|
-
| rule_rhs IDENTIFIER "(" parameterizing_args ")"
|
230
|
+
| rule_rhs IDENTIFIER "(" parameterizing_args ")" TAG?
|
286
231
|
{
|
287
232
|
builder = val[0]
|
288
233
|
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5])
|
289
234
|
result = builder
|
290
235
|
}
|
291
|
-
| rule_rhs
|
236
|
+
| rule_rhs midrule_action named_ref?
|
292
237
|
{
|
293
|
-
|
294
|
-
|
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
|
304
|
-
{
|
305
|
-
user_code = val[3]
|
306
|
-
user_code.alias_name = val[6]
|
238
|
+
user_code = val[1]
|
239
|
+
user_code.alias_name = val[2]
|
307
240
|
builder = val[0]
|
308
241
|
builder.user_code = user_code
|
309
242
|
result = builder
|
@@ -317,84 +250,40 @@ rule
|
|
317
250
|
result = builder
|
318
251
|
}
|
319
252
|
|
320
|
-
int_opt: # empty
|
321
|
-
| INTEGER
|
322
|
-
|
323
253
|
alias: # empty
|
324
|
-
|
|
254
|
+
| string_as_id { result = val[0].s_value }
|
325
255
|
|
326
|
-
symbol_declarations:
|
327
|
-
|
328
|
-
|
329
|
-
}
|
330
|
-
| TAG symbol_declaration_list
|
331
|
-
{
|
332
|
-
result = [{tag: val[0], tokens: val[1]}]
|
333
|
-
}
|
334
|
-
| symbol_declarations TAG symbol_declaration_list
|
335
|
-
{
|
336
|
-
result = val[0].append({tag: val[1], tokens: val[2]})
|
337
|
-
}
|
338
|
-
|
339
|
-
symbol_declaration_list: symbol { result = [val[0]] }
|
340
|
-
| symbol_declaration_list symbol { result = val[0].append(val[1]) }
|
256
|
+
symbol_declarations: symbol+ { result = [{tag: nil, tokens: val[0]}] }
|
257
|
+
| TAG symbol+ { result = [{tag: val[0], tokens: val[1]}] }
|
258
|
+
| symbol_declarations TAG symbol+ { result = val[0].append({tag: val[1], tokens: val[2]}) }
|
341
259
|
|
342
260
|
symbol: id
|
343
261
|
| string_as_id
|
344
262
|
|
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
|
263
|
+
param: "{" {
|
264
|
+
begin_c_declaration("}")
|
265
|
+
}
|
266
|
+
C_DECLARATION
|
267
|
+
{
|
268
|
+
end_c_declaration
|
269
|
+
}
|
270
|
+
"}"
|
271
|
+
{
|
272
|
+
result = val[2]
|
273
|
+
}
|
274
|
+
|
275
|
+
token_declarations_for_precedence: id+ { result = [{tag: nil, tokens: val[0]}] }
|
276
|
+
| TAG id+ { result = [{tag: val[0], tokens: val[1]}] }
|
277
|
+
| id TAG id+ { result = val[0].append({tag: val[1], tokens: val[2]}) }
|
387
278
|
|
388
279
|
id: IDENTIFIER { on_action_error("ident after %prec", val[0]) if @prec_seen }
|
389
280
|
| CHARACTER { on_action_error("char after %prec", val[0]) if @prec_seen }
|
390
281
|
|
391
|
-
grammar: rules_or_grammar_declaration
|
392
|
-
| grammar rules_or_grammar_declaration
|
393
282
|
|
394
|
-
rules_or_grammar_declaration: rules
|
283
|
+
rules_or_grammar_declaration: rules ";"?
|
395
284
|
| grammar_declaration ";"
|
396
285
|
|
397
|
-
rules:
|
286
|
+
rules: IDENT_COLON named_ref? ":" rhs_list
|
398
287
|
{
|
399
288
|
lhs = val[0]
|
400
289
|
lhs.alias_name = val[1]
|
@@ -421,19 +310,13 @@ rule
|
|
421
310
|
end
|
422
311
|
result = val[0].append(builder)
|
423
312
|
}
|
424
|
-
| rhs_list ";"
|
425
313
|
|
426
|
-
rhs:
|
427
|
-
{
|
428
|
-
reset_precs
|
429
|
-
result = Grammar::RuleBuilder.new(@rule_counter, @midrule_action_counter)
|
430
|
-
}
|
431
|
-
| "%empty"
|
314
|
+
rhs: empty
|
432
315
|
{
|
433
316
|
reset_precs
|
434
|
-
result =
|
317
|
+
result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter)
|
435
318
|
}
|
436
|
-
| rhs symbol
|
319
|
+
| rhs symbol named_ref?
|
437
320
|
{
|
438
321
|
token = val[1]
|
439
322
|
token.alias_name = val[2]
|
@@ -441,39 +324,27 @@ rule
|
|
441
324
|
builder.add_rhs(token)
|
442
325
|
result = builder
|
443
326
|
}
|
444
|
-
| rhs symbol parameterizing_suffix
|
327
|
+
| rhs symbol parameterizing_suffix named_ref? TAG?
|
445
328
|
{
|
446
|
-
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]], lhs_tag: val[
|
329
|
+
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
330
|
builder = val[0]
|
448
331
|
builder.add_rhs(token)
|
449
332
|
builder.line = val[1].first_line
|
450
333
|
result = builder
|
451
334
|
}
|
452
|
-
| rhs IDENTIFIER "(" parameterizing_args ")"
|
335
|
+
| rhs IDENTIFIER "(" parameterizing_args ")" named_ref? TAG?
|
453
336
|
{
|
454
|
-
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[
|
337
|
+
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
338
|
builder = val[0]
|
456
339
|
builder.add_rhs(token)
|
457
340
|
builder.line = val[1].first_line
|
458
341
|
result = builder
|
459
342
|
}
|
460
|
-
| rhs
|
461
|
-
{
|
462
|
-
if @prec_seen
|
463
|
-
on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec
|
464
|
-
@code_after_prec = true
|
465
|
-
end
|
466
|
-
begin_c_declaration("}")
|
467
|
-
}
|
468
|
-
C_DECLARATION
|
469
|
-
{
|
470
|
-
end_c_declaration
|
471
|
-
}
|
472
|
-
"}" named_ref_opt tag_opt
|
343
|
+
| rhs midrule_action named_ref? TAG?
|
473
344
|
{
|
474
|
-
user_code = val[
|
475
|
-
user_code.alias_name = val[
|
476
|
-
user_code.tag = val[
|
345
|
+
user_code = val[1]
|
346
|
+
user_code.alias_name = val[2]
|
347
|
+
user_code.tag = val[3]
|
477
348
|
builder = val[0]
|
478
349
|
builder.user_code = user_code
|
479
350
|
result = builder
|
@@ -496,22 +367,35 @@ rule
|
|
496
367
|
| symbol parameterizing_suffix { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] }
|
497
368
|
| IDENTIFIER "(" parameterizing_args ")" { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] }
|
498
369
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
370
|
+
midrule_action: "{"
|
371
|
+
{
|
372
|
+
if @prec_seen
|
373
|
+
on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec
|
374
|
+
@code_after_prec = true
|
375
|
+
end
|
376
|
+
begin_c_declaration("}")
|
377
|
+
}
|
378
|
+
C_DECLARATION
|
379
|
+
{
|
380
|
+
end_c_declaration
|
381
|
+
}
|
382
|
+
"}"
|
383
|
+
{
|
384
|
+
result = val[2]
|
385
|
+
}
|
386
|
+
|
387
|
+
named_ref: '[' IDENTIFIER ']' { result = val[1].s_value }
|
388
|
+
|
389
|
+
epilogue_declaration: "%%"
|
390
|
+
{
|
391
|
+
begin_c_declaration('\Z')
|
392
|
+
@grammar.epilogue_first_lineno = @lexer.line + 1
|
393
|
+
}
|
394
|
+
C_DECLARATION
|
395
|
+
{
|
396
|
+
end_c_declaration
|
397
|
+
@grammar.epilogue = val[2].s_value
|
398
|
+
}
|
515
399
|
|
516
400
|
variable: id
|
517
401
|
|
@@ -520,16 +404,13 @@ rule
|
|
520
404
|
| STRING
|
521
405
|
| "{...}"
|
522
406
|
|
523
|
-
|
524
|
-
|
407
|
+
generic_symbol: symbol
|
408
|
+
| TAG
|
525
409
|
|
526
|
-
|
527
|
-
|
410
|
+
empty: /* empty */
|
411
|
+
| "%empty"
|
528
412
|
|
529
413
|
string_as_id: STRING { result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) }
|
530
|
-
|
531
|
-
tag_opt: # empty
|
532
|
-
| TAG
|
533
414
|
end
|
534
415
|
|
535
416
|
---- inner
|
@@ -10,6 +10,10 @@ module Lrama
|
|
10
10
|
|
11
11
|
def initialize: (Grammar::ParameterizingRule::Rule parameterizing_rule, Array[Lexer::Token] actual_args) -> void
|
12
12
|
def resolve_symbol: (Lexer::Token symbol) -> Lexer::Token
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def parameter_to_arg: (Lexer::Token symbol) -> Lexer::Token?
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -2,13 +2,12 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class Code
|
4
4
|
class DestructorCode < Code
|
5
|
-
@tag:
|
6
|
-
def initialize: (type:
|
5
|
+
@tag: Lexer::Token::Tag
|
6
|
+
def initialize: (type: ::Symbol, token_code: Grammar::Code, tag: Lexer::Token::Tag) -> void
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
|
11
|
-
def reference_to_c: (untyped ref) -> untyped
|
10
|
+
def reference_to_c: (Reference ref) -> (String | bot)
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
@@ -2,13 +2,12 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class Code
|
4
4
|
class PrinterCode < Code
|
5
|
-
@tag:
|
6
|
-
def initialize: (type:
|
5
|
+
@tag: Lexer::Token::Tag
|
6
|
+
def initialize: (type: ::Symbol, token_code: Grammar::Code, tag: Lexer::Token::Tag) -> void
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
|
11
|
-
def reference_to_c: (untyped ref) -> untyped
|
10
|
+
def reference_to_c: (Reference ref) -> (String | bot)
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class Code
|
4
|
+
class RuleAction < Code
|
5
|
+
@rule: Rule
|
6
|
+
|
7
|
+
def initialize: (type: ::Symbol, token_code: Grammar::Code, rule: Rule) -> void
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def reference_to_c: (Reference ref) -> String
|
12
|
+
def position_in_rhs: () -> Integer
|
13
|
+
def rhs: () -> Array[Grammar::Symbol]
|
14
|
+
def lhs: () -> Grammar::Symbol
|
15
|
+
def raise_tag_not_found_error: (Reference ref) -> bot
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/sig/lrama/grammar/code.rbs
CHANGED
@@ -3,8 +3,8 @@ module Lrama
|
|
3
3
|
class Code
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
-
attr_accessor type: Symbol
|
7
|
-
attr_accessor token_code:
|
6
|
+
attr_accessor type: ::Symbol
|
7
|
+
attr_accessor token_code: Grammar::Code
|
8
8
|
|
9
9
|
# delegated
|
10
10
|
def s_value: -> String
|
@@ -12,7 +12,7 @@ module Lrama
|
|
12
12
|
def column: -> Integer
|
13
13
|
def references: -> Array[Lrama::Grammar::Reference]
|
14
14
|
|
15
|
-
def initialize: (type: Symbol, token_code:
|
15
|
+
def initialize: (type: ::Symbol, token_code: Grammar::Code) -> void
|
16
16
|
|
17
17
|
def translated_code: () -> String
|
18
18
|
|
@@ -5,7 +5,9 @@ module Lrama
|
|
5
5
|
attr_accessor token_code: Grammar::Code
|
6
6
|
attr_accessor lineno: Integer
|
7
7
|
|
8
|
-
def
|
8
|
+
def initialize: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Grammar::Code, lineno: Integer) -> void
|
9
|
+
|
10
|
+
def translated_code: (Lexer::Token::Tag tag) -> String
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -2,10 +2,12 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class ErrorToken
|
4
4
|
attr_accessor ident_or_tags: Array[Lexer::Token::Ident | Lexer::Token::Tag]
|
5
|
-
attr_accessor token_code:
|
5
|
+
attr_accessor token_code: Grammar::Code
|
6
6
|
attr_accessor lineno: Integer
|
7
7
|
|
8
|
-
def
|
8
|
+
def initialize: (?ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], ?token_code: Grammar::Code, ?lineno: Integer) -> void
|
9
|
+
|
10
|
+
def translated_code: (Lexer::Token::Tag tag) -> String
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|