depager 0.3.0.b20160729 → 0.3.0.b20250423
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 +5 -5
- data/.rubocop.yml +44 -0
- data/.simplecov +5 -0
- data/Gemfile +12 -0
- data/LICENSE.gpl +339 -0
- data/Manifest.txt +73 -0
- data/README.en +4 -3
- data/README.ja +4 -47
- data/Rakefile +31 -0
- data/bin/depager +3 -38
- data/examples/action_pl0d/pl0d.action.dr +4 -4
- data/examples/action_pl0d/test.pl0ds +2 -3
- data/examples/c89/c89.dr +4 -4
- data/examples/c89/test.c89 +1 -1
- data/examples/extension/astdf.rb +4 -5
- data/examples/extension/atree.dr +3 -3
- data/examples/extension/calc.atree.dr +4 -4
- data/examples/extension/calc.simple_action.dr +3 -3
- data/examples/extension/paction.dr +3 -3
- data/examples/extension/pactiontest.dr +3 -3
- data/examples/extension/simple_action.rb +26 -24
- data/examples/pl0d/pl0ds.dr +5 -5
- data/examples/pl0d/test.pl0ds +2 -2
- data/examples/rie_calc/calc.rie.dr +4 -4
- data/examples/rie_dcuse/dcuse.rie.dr +4 -4
- data/examples/rie_pl0/pl0.rie.dr +3 -3
- data/examples/slex_test/divreg.slex.dr +5 -5
- data/examples/slex_test/ljoin.slex.dr +5 -5
- data/examples/{sample_calc → tiny_calc}/calc.action.dr +4 -4
- data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +20 -9
- data/examples/{sample_calc → tiny_calc}/calc.ast.dr +19 -7
- data/examples/{sample_calc → tiny_calc}/calc.cst.dr +12 -7
- data/examples/{sample_calc → tiny_calc}/calc.dr +1 -1
- data/examples/{sample_calc → tiny_calc}/calc.lex.dr +2 -2
- data/examples/{sample_calc → tiny_calc}/calc_prec.action.dr +4 -4
- data/lib/depager/cli.rb +44 -0
- data/lib/depager/grammar.rb +72 -75
- data/lib/depager/lr.rb +169 -154
- data/lib/depager/parser.rb +90 -103
- data/lib/depager/plugins/_rie_debug.rb +63 -0
- data/lib/depager/plugins/action.rb +47 -0
- data/lib/depager/{ruby/plugins → plugins}/ast.dr +20 -17
- data/lib/depager/{ruby/plugins → plugins}/ast.rb +266 -304
- data/lib/depager/{ruby/plugins → plugins}/cst.dr +18 -16
- data/lib/depager/{ruby/plugins → plugins}/cst.rb +152 -148
- data/lib/depager/{ruby/plugins → plugins}/lex.dr +7 -7
- data/lib/depager/{ruby/plugins → plugins}/lex.rb +72 -69
- data/lib/depager/{ruby/plugins → plugins}/rie.dr +12 -10
- data/lib/depager/{ruby/plugins → plugins}/rie.rb +224 -263
- data/lib/depager/{ruby/plugins → plugins}/slex.dr +13 -14
- data/lib/depager/{ruby/plugins → plugins}/slex.rb +183 -194
- data/lib/depager/plugins/srp.rb +46 -0
- data/lib/depager/ruby/templates/extension_lalr_master.erb +6 -12
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +31 -17
- data/lib/depager/ruby/templates/single_lalr_parser.erb +35 -26
- data/lib/depager/utils.rb +56 -46
- data/lib/depager/version.rb +1 -2
- data/lib/depager.rb +166 -176
- metadata +38 -33
- data/lib/depager/ruby/plugins/_rie_debug.rb +0 -35
- data/lib/depager/ruby/plugins/action.rb +0 -53
- data/lib/depager/ruby/plugins/srp.rb +0 -56
- /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
###
|
4
2
|
### Depager::ASTBuilderExtension - Depager Extension (master)
|
5
3
|
###
|
@@ -11,6 +9,7 @@ module Depager ; end
|
|
11
9
|
class Depager::ASTBuilderExtension < Depager::Extension
|
12
10
|
|
13
11
|
def initialize
|
12
|
+
super
|
14
13
|
@master = self
|
15
14
|
@slaves = []
|
16
15
|
end
|
@@ -18,13 +17,13 @@ class Depager::ASTBuilderExtension < Depager::Extension
|
|
18
17
|
def extension_registered g_parser
|
19
18
|
super g_parser
|
20
19
|
|
21
|
-
@slaves
|
22
|
-
g_parser.hooks[:pre_rule_list].push [@slaves
|
23
|
-
@slaves
|
24
|
-
g_parser.hooks[:post_rhs].push [@slaves
|
20
|
+
@slaves << Depager::ASTBuilderExtension::PreRuleList0::Parser.new(g_parser, self)
|
21
|
+
g_parser.hooks[:pre_rule_list].push [@slaves.last, :do_parse]
|
22
|
+
@slaves << Depager::ASTBuilderExtension::PostRhs1::Parser.new(g_parser, self)
|
23
|
+
g_parser.hooks[:post_rhs].push [@slaves.last, :do_parse]
|
25
24
|
end
|
26
25
|
|
27
|
-
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/
|
26
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 7
|
28
27
|
attr_accessor :action_code, :on_reduce, :visitors
|
29
28
|
def init_extension
|
30
29
|
@visitors = Hash.new{|hash, key| hash[key] = []}
|
@@ -39,11 +38,11 @@ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 8
|
|
39
38
|
|
40
39
|
def modify_action_code code, nodes=[]
|
41
40
|
code = code.gsub(/\$\.([a-z_])/, 'node.\1')
|
42
|
-
code <<
|
41
|
+
code << <<-CODE
|
43
42
|
rescue
|
44
43
|
warn "raise at src:\#{node.lineno}/\#{node.class.name}"
|
45
44
|
raise
|
46
|
-
|
45
|
+
CODE
|
47
46
|
end
|
48
47
|
|
49
48
|
def gen_accept_code sym
|
@@ -66,16 +65,15 @@ DEPAGER_EXPANDED_CODE
|
|
66
65
|
end
|
67
66
|
|
68
67
|
###
|
69
|
-
### Depager::ASTBuilderExtension::
|
68
|
+
### Depager::ASTBuilderExtension::PreRuleList0 - Part of Depager Extension (slave)
|
70
69
|
###
|
71
70
|
|
72
|
-
module Depager::ASTBuilderExtension::
|
71
|
+
module Depager::ASTBuilderExtension::PreRuleList0 #:nodoc:all
|
73
72
|
class Parser < Depager::LALR::Basis #:nodoc:all
|
74
73
|
include Depager::Utils::ExtensionSlaveMethods
|
75
|
-
|
76
74
|
|
77
75
|
### Reduce Table
|
78
|
-
|
76
|
+
REDUCE_TABLE = [
|
79
77
|
[ -1, 1 ],
|
80
78
|
[ 0, 3 ],
|
81
79
|
[ 1, 0 ],
|
@@ -103,8 +101,10 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
103
101
|
[ 11, 2 ],
|
104
102
|
[ 12, 4 ],
|
105
103
|
]
|
104
|
+
def reduce_table; REDUCE_TABLE; end
|
105
|
+
|
106
106
|
### Term to Int
|
107
|
-
|
107
|
+
TERM_TO_INT = {
|
108
108
|
nil => 0,
|
109
109
|
false => 1,
|
110
110
|
:NODE => 2,
|
@@ -120,8 +120,10 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
120
120
|
"<" => 12,
|
121
121
|
">" => 13,
|
122
122
|
}
|
123
|
+
def term_to_int; TERM_TO_INT; end
|
124
|
+
|
123
125
|
### Int to Term
|
124
|
-
|
126
|
+
INT_TO_TERM = [
|
125
127
|
nil,
|
126
128
|
false,
|
127
129
|
:NODE,
|
@@ -137,8 +139,10 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
137
139
|
"<",
|
138
140
|
">",
|
139
141
|
]
|
142
|
+
def int_to_term; INT_TO_TERM; end
|
143
|
+
|
140
144
|
### Action Table
|
141
|
-
|
145
|
+
ACTION_TABLE = [
|
142
146
|
[ nil, nil, 3, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
143
147
|
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
144
148
|
[ nil, nil, nil, nil, 5, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
@@ -181,8 +185,10 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
181
185
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
182
186
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
183
187
|
]
|
188
|
+
def action_table; ACTION_TABLE; end
|
189
|
+
|
184
190
|
### Default Reduce Table
|
185
|
-
|
191
|
+
DEFRED_TABLE = [
|
186
192
|
-2,
|
187
193
|
nil,
|
188
194
|
-4,
|
@@ -225,7 +231,9 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
225
231
|
-25,
|
226
232
|
-15,
|
227
233
|
]
|
228
|
-
|
234
|
+
def defred_table; DEFRED_TABLE; end
|
235
|
+
|
236
|
+
DEFRED_AFTER_SHIFT_TABLE = [
|
229
237
|
nil,
|
230
238
|
nil,
|
231
239
|
nil,
|
@@ -268,40 +276,46 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
268
276
|
-25,
|
269
277
|
-15,
|
270
278
|
]
|
279
|
+
def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end
|
280
|
+
|
271
281
|
### Nonterm to Int
|
272
|
-
|
273
|
-
:start => 0,
|
274
|
-
:opt_defnode => 1,
|
275
|
-
:opt_defvis => 2,
|
276
|
-
:defnode_list => 3,
|
277
|
-
:opt_attr => 4,
|
278
|
-
:opt_action => 5,
|
279
|
-
:defnode => 6,
|
280
|
-
:defnode_header => 7,
|
281
|
-
:fact_list => 8,
|
282
|
-
:id_list => 9,
|
283
|
-
:fact => 10,
|
284
|
-
:pass_action_list => 11,
|
285
|
-
:pass_action => 12,
|
282
|
+
NONTERM_TO_INT = {
|
283
|
+
:start => 0,
|
284
|
+
:opt_defnode => 1,
|
285
|
+
:opt_defvis => 2,
|
286
|
+
:defnode_list => 3,
|
287
|
+
:opt_attr => 4,
|
288
|
+
:opt_action => 5,
|
289
|
+
:defnode => 6,
|
290
|
+
:defnode_header => 7,
|
291
|
+
:fact_list => 8,
|
292
|
+
:id_list => 9,
|
293
|
+
:fact => 10,
|
294
|
+
:pass_action_list => 11,
|
295
|
+
:pass_action => 12,
|
286
296
|
}
|
297
|
+
def nonterm_to_int; NONTERM_TO_INT; end
|
298
|
+
|
287
299
|
### Int to Nonterm
|
288
|
-
|
289
|
-
:start,
|
290
|
-
:opt_defnode,
|
291
|
-
:opt_defvis,
|
292
|
-
:defnode_list,
|
293
|
-
:opt_attr,
|
294
|
-
:opt_action,
|
295
|
-
:defnode,
|
296
|
-
:defnode_header,
|
297
|
-
:fact_list,
|
298
|
-
:id_list,
|
299
|
-
:fact,
|
300
|
-
:pass_action_list,
|
301
|
-
:pass_action,
|
300
|
+
INT_TO_NONTERM = [
|
301
|
+
:start,
|
302
|
+
:opt_defnode,
|
303
|
+
:opt_defvis,
|
304
|
+
:defnode_list,
|
305
|
+
:opt_attr,
|
306
|
+
:opt_action,
|
307
|
+
:defnode,
|
308
|
+
:defnode_header,
|
309
|
+
:fact_list,
|
310
|
+
:id_list,
|
311
|
+
:fact,
|
312
|
+
:pass_action_list,
|
313
|
+
:pass_action,
|
302
314
|
]
|
315
|
+
def int_to_nonterm; INT_TO_NONTERM; end
|
316
|
+
|
303
317
|
### Goto Table
|
304
|
-
|
318
|
+
GOTO_TABLE = [
|
305
319
|
[ 1, 2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
306
320
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
307
321
|
[ nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
@@ -344,10 +358,7 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
344
358
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
345
359
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
346
360
|
]
|
347
|
-
|
348
|
-
Tables = [ reduce_table, action_table,
|
349
|
-
defred_table, defred_after_shift_table, goto_table,
|
350
|
-
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
361
|
+
def goto_table; GOTO_TABLE; end
|
351
362
|
|
352
363
|
def initialize g_parser, master
|
353
364
|
super()
|
@@ -372,64 +383,54 @@ module Depager::ASTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
372
383
|
"%AST{ ... } / Depager::ASTBuilderExtension"
|
373
384
|
end
|
374
385
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
case @line
|
380
|
-
|
386
|
+
def lex
|
387
|
+
begin
|
388
|
+
until @line.empty?
|
389
|
+
case @line
|
381
390
|
when /\A\s+/, /\A#.*/
|
382
391
|
@line = $'
|
383
392
|
|
384
393
|
|
385
|
-
|
386
394
|
when /\A%\}\s*\Z/
|
387
395
|
@line = $'
|
388
396
|
@line = $'; yield nil,nil
|
389
397
|
|
390
|
-
|
391
398
|
when /\ANode/
|
392
399
|
@line = $'
|
393
400
|
yield token(:NODE, $&)
|
394
401
|
|
395
|
-
|
396
402
|
when /\AVisitor/
|
397
403
|
@line = $'
|
398
404
|
yield token(:VISITOR, $&)
|
399
405
|
|
400
|
-
|
401
406
|
when /\A[a-zA-Z][a-zA-Z0-9_]*/
|
402
407
|
@line = $'
|
403
408
|
yield token(:ID, $&)
|
404
409
|
|
405
|
-
|
406
410
|
when /\A\{/
|
407
411
|
#
|
408
412
|
lineno = file.lineno; yield token(:ACTION, parse_block, lineno)
|
409
413
|
|
410
|
-
|
411
414
|
when /\A./
|
412
415
|
@line = $'
|
413
416
|
yield token($&, $&)
|
414
417
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
end
|
423
|
-
|
424
|
-
end
|
418
|
+
|
419
|
+
else
|
420
|
+
raise RuntimeError, "must not happen #{@line}"
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end while @original_line = @line = file.gets
|
424
|
+
yield nil, nil
|
425
425
|
end
|
426
426
|
|
427
|
+
end
|
428
|
+
end
|
427
429
|
|
428
|
-
class Depager::ASTBuilderExtension::
|
430
|
+
class Depager::ASTBuilderExtension::PreRuleList0::Action < Depager::LALR::Action #:nodoc:all
|
429
431
|
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
430
|
-
|
431
|
-
|
432
|
-
nil,
|
432
|
+
ON_REDUCE = [
|
433
|
+
nil,
|
433
434
|
:_act_1,
|
434
435
|
:_act_2,
|
435
436
|
:_act_3,
|
@@ -456,13 +457,12 @@ class Depager::ASTBuilderExtension::Slave_pre_rule_list::Action < Depager::LALR:
|
|
456
457
|
:_act_24,
|
457
458
|
:_act_25,
|
458
459
|
|
459
|
-
|
460
|
-
|
460
|
+
]
|
461
|
+
def on_reduce; ON_REDUCE; end
|
461
462
|
|
462
|
-
|
463
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 59
|
463
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 58
|
464
464
|
def _act_1 val
|
465
|
-
_opt_defnode, _opt_defvis, _defnode_list, = *val
|
465
|
+
_opt_defnode, _opt_defvis, _defnode_list, = *val
|
466
466
|
|
467
467
|
code = "module #{target_namespace}\n"
|
468
468
|
code << _opt_defnode
|
@@ -482,38 +482,36 @@ def _act_1 val
|
|
482
482
|
|
483
483
|
end
|
484
484
|
DEPAGER_EXPANDED_CODE
|
485
|
-
|
486
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 78
|
485
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 77
|
487
486
|
def _act_2 val
|
487
|
+
# empty rule
|
488
488
|
""
|
489
489
|
|
490
490
|
end
|
491
491
|
DEPAGER_EXPANDED_CODE
|
492
|
-
|
493
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 80
|
492
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 79
|
494
493
|
def _act_3 val
|
495
|
-
_NODE, _opt_attr, _ACTION, = *val
|
494
|
+
_NODE, _opt_attr, _ACTION, = *val
|
496
495
|
|
497
|
-
ini =
|
496
|
+
ini = <<-CODE
|
498
497
|
def initialize
|
499
498
|
#{_ACTION.value}
|
500
499
|
end
|
501
|
-
|
500
|
+
CODE
|
502
501
|
ERB.new(master.class::BASE_NODE_TEMPLATE, nil, '-').result(binding)
|
503
502
|
|
504
503
|
end
|
505
504
|
DEPAGER_EXPANDED_CODE
|
506
|
-
|
507
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 90
|
505
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 89
|
508
506
|
def _act_4 val
|
507
|
+
# empty rule
|
509
508
|
[]
|
510
509
|
|
511
510
|
end
|
512
511
|
DEPAGER_EXPANDED_CODE
|
513
|
-
|
514
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 92
|
512
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 91
|
515
513
|
def _act_5 val
|
516
|
-
_VISITOR, _opt_action, = *val
|
514
|
+
_VISITOR, _opt_action, = *val
|
517
515
|
|
518
516
|
_opt_action[nil] ||= Token.new('', 0)
|
519
517
|
_opt_action.each do |pass, act|
|
@@ -523,26 +521,23 @@ def _act_5 val
|
|
523
521
|
|
524
522
|
end
|
525
523
|
DEPAGER_EXPANDED_CODE
|
526
|
-
|
527
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 101
|
524
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 100
|
528
525
|
def _act_6 val
|
529
|
-
_defnode, = *val
|
526
|
+
_defnode, = *val
|
530
527
|
_defnode
|
531
528
|
|
532
529
|
end
|
533
530
|
DEPAGER_EXPANDED_CODE
|
534
|
-
|
535
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 102
|
531
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 101
|
536
532
|
def _act_7 val
|
537
|
-
_defnode_list, _defnode, = *val
|
533
|
+
_defnode_list, _defnode, = *val
|
538
534
|
_defnode_list << _defnode
|
539
535
|
|
540
536
|
end
|
541
537
|
DEPAGER_EXPANDED_CODE
|
542
|
-
|
543
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 106
|
538
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 105
|
544
539
|
def _act_8 val
|
545
|
-
_defnode_header, _opt_attr, _opt_action, = *val
|
540
|
+
_defnode_header, _opt_attr, _opt_action, = *val
|
546
541
|
|
547
542
|
name, args = _defnode_header
|
548
543
|
nodes, accept, attrs = [], '', _opt_attr
|
@@ -565,156 +560,140 @@ def _act_8 val
|
|
565
560
|
|
566
561
|
end
|
567
562
|
DEPAGER_EXPANDED_CODE
|
568
|
-
|
569
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 128
|
563
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 127
|
570
564
|
def _act_9 val
|
571
|
-
_ID, _, _, = *val
|
565
|
+
_ID, _, _, = *val
|
572
566
|
[_ID.value, []]
|
573
567
|
|
574
568
|
end
|
575
569
|
DEPAGER_EXPANDED_CODE
|
576
|
-
|
577
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 129
|
570
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 128
|
578
571
|
def _act_10 val
|
579
|
-
_ID, _, _fact_list, _, = *val
|
572
|
+
_ID, _, _fact_list, _, = *val
|
580
573
|
[_ID.value, _fact_list]
|
581
574
|
|
582
575
|
end
|
583
576
|
DEPAGER_EXPANDED_CODE
|
584
|
-
|
585
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 132
|
577
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 131
|
586
578
|
def _act_11 val
|
579
|
+
# empty rule
|
587
580
|
[]
|
588
581
|
|
589
582
|
end
|
590
583
|
DEPAGER_EXPANDED_CODE
|
591
|
-
|
592
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 133
|
584
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 132
|
593
585
|
def _act_12 val
|
594
|
-
_, _, = *val
|
586
|
+
_, _, = *val
|
595
587
|
[]
|
596
588
|
|
597
589
|
end
|
598
590
|
DEPAGER_EXPANDED_CODE
|
599
|
-
|
600
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 134
|
591
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 133
|
601
592
|
def _act_13 val
|
602
|
-
_, _id_list, _, = *val
|
593
|
+
_, _id_list, _, = *val
|
603
594
|
_id_list
|
604
595
|
|
605
596
|
end
|
606
597
|
DEPAGER_EXPANDED_CODE
|
607
|
-
|
608
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 137
|
598
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 136
|
609
599
|
def _act_14 val
|
610
|
-
_fact, = *val
|
600
|
+
_fact, = *val
|
611
601
|
[_fact]
|
612
602
|
|
613
603
|
end
|
614
604
|
DEPAGER_EXPANDED_CODE
|
615
|
-
|
616
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 138
|
605
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 137
|
617
606
|
def _act_15 val
|
618
|
-
_fact_list, _, _fact, = *val
|
607
|
+
_fact_list, _, _fact, = *val
|
619
608
|
_fact_list.push _fact
|
620
609
|
|
621
610
|
end
|
622
611
|
DEPAGER_EXPANDED_CODE
|
623
|
-
|
624
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 141
|
612
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 140
|
625
613
|
def _act_16 val
|
626
|
-
_ID, = *val
|
614
|
+
_ID, = *val
|
627
615
|
_ID.value
|
628
616
|
|
629
617
|
end
|
630
618
|
DEPAGER_EXPANDED_CODE
|
631
|
-
|
632
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 142
|
619
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 141
|
633
620
|
def _act_17 val
|
634
|
-
_, _ID, = *val
|
621
|
+
_, _ID, = *val
|
635
622
|
'-' + _ID.value
|
636
623
|
|
637
624
|
end
|
638
625
|
DEPAGER_EXPANDED_CODE
|
639
|
-
|
640
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 145
|
626
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 144
|
641
627
|
def _act_18 val
|
642
|
-
_ID, = *val
|
628
|
+
_ID, = *val
|
643
629
|
[ _ID.value ]
|
644
630
|
|
645
631
|
end
|
646
632
|
DEPAGER_EXPANDED_CODE
|
647
|
-
|
648
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 146
|
633
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 145
|
649
634
|
def _act_19 val
|
650
|
-
_id_list, _, _ID, = *val
|
635
|
+
_id_list, _, _ID, = *val
|
651
636
|
_id_list.push _ID.value
|
652
637
|
|
653
638
|
end
|
654
639
|
DEPAGER_EXPANDED_CODE
|
655
|
-
|
656
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 149
|
640
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 148
|
657
641
|
def _act_20 val
|
642
|
+
# empty rule
|
658
643
|
{nil => Token.new('', 0)}
|
659
644
|
|
660
645
|
end
|
661
646
|
DEPAGER_EXPANDED_CODE
|
662
|
-
|
663
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 150
|
647
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 149
|
664
648
|
def _act_21 val
|
665
|
-
_ACTION, = *val
|
649
|
+
_ACTION, = *val
|
666
650
|
{nil => _ACTION}
|
667
651
|
|
668
652
|
end
|
669
653
|
DEPAGER_EXPANDED_CODE
|
670
|
-
|
671
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 152
|
654
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 151
|
672
655
|
def _act_22 val
|
673
|
-
_pass_action_list, = *val
|
656
|
+
_pass_action_list, = *val
|
674
657
|
|
675
658
|
Hash[ *_pass_action_list.flatten ].merge({nil => Token.new('', 0)})
|
676
659
|
|
677
660
|
end
|
678
661
|
DEPAGER_EXPANDED_CODE
|
679
|
-
|
680
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 157
|
662
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 156
|
681
663
|
def _act_23 val
|
682
|
-
_pass_action, = *val
|
664
|
+
_pass_action, = *val
|
683
665
|
[ _pass_action ]
|
684
666
|
|
685
667
|
end
|
686
668
|
DEPAGER_EXPANDED_CODE
|
687
|
-
|
688
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 158
|
669
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 157
|
689
670
|
def _act_24 val
|
690
|
-
_pass_action_list, _pass_action, = *val
|
671
|
+
_pass_action_list, _pass_action, = *val
|
691
672
|
_pass_action_list << _pass_action
|
692
673
|
|
693
674
|
end
|
694
675
|
DEPAGER_EXPANDED_CODE
|
695
|
-
|
696
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 162
|
676
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 161
|
697
677
|
def _act_25 val
|
698
|
-
_, _ID, _, _ACTION, = *val
|
678
|
+
_, _ID, _, _ACTION, = *val
|
699
679
|
[_ID.value, _ACTION]
|
700
680
|
|
701
681
|
end
|
702
682
|
DEPAGER_EXPANDED_CODE
|
703
|
-
|
704
|
-
|
683
|
+
|
684
|
+
|
705
685
|
end
|
706
|
-
|
686
|
+
|
707
687
|
###
|
708
|
-
### Depager::ASTBuilderExtension::
|
688
|
+
### Depager::ASTBuilderExtension::PostRhs1 - Part of Depager Extension (slave)
|
709
689
|
###
|
710
690
|
|
711
|
-
module Depager::ASTBuilderExtension::
|
691
|
+
module Depager::ASTBuilderExtension::PostRhs1 #:nodoc:all
|
712
692
|
class Parser < Depager::LALR::Basis #:nodoc:all
|
713
693
|
include Depager::Utils::ExtensionSlaveMethods
|
714
|
-
|
715
694
|
|
716
695
|
### Reduce Table
|
717
|
-
|
696
|
+
REDUCE_TABLE = [
|
718
697
|
[ -1, 1 ],
|
719
698
|
[ 0, 1 ],
|
720
699
|
[ 2, 3 ],
|
@@ -738,8 +717,10 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
738
717
|
[ 5, 3 ],
|
739
718
|
[ 5, 3 ],
|
740
719
|
]
|
720
|
+
def reduce_table; REDUCE_TABLE; end
|
721
|
+
|
741
722
|
### Term to Int
|
742
|
-
|
723
|
+
TERM_TO_INT = {
|
743
724
|
nil => 0,
|
744
725
|
false => 1,
|
745
726
|
:ID => 2,
|
@@ -758,8 +739,10 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
758
739
|
:LL => 15,
|
759
740
|
"@" => 16,
|
760
741
|
}
|
742
|
+
def term_to_int; TERM_TO_INT; end
|
743
|
+
|
761
744
|
### Int to Term
|
762
|
-
|
745
|
+
INT_TO_TERM = [
|
763
746
|
nil,
|
764
747
|
false,
|
765
748
|
:ID,
|
@@ -778,15 +761,17 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
778
761
|
:LL,
|
779
762
|
"@",
|
780
763
|
]
|
764
|
+
def int_to_term; INT_TO_TERM; end
|
765
|
+
|
781
766
|
### Action Table
|
782
|
-
|
767
|
+
ACTION_TABLE = [
|
783
768
|
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
784
769
|
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
785
770
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
786
771
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
787
772
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
788
773
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
789
|
-
[ nil, nil, nil,
|
774
|
+
[ nil, nil, nil, 16, nil, nil, nil, nil, nil, nil, nil, nil, 18, nil, nil, nil, nil, ],
|
790
775
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
791
776
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
792
777
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
@@ -796,23 +781,25 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
796
781
|
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, 19, nil, nil, ],
|
797
782
|
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
798
783
|
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
784
|
+
[ nil, nil, 6, nil, 24, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
799
785
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
800
786
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
801
|
-
[ nil, nil, 6, nil, 24, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
802
787
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
803
|
-
[ nil, nil, nil, nil, nil,
|
788
|
+
[ nil, nil, nil, nil, nil, 26, nil, nil, nil, nil, nil, nil, nil, nil, 27, nil, nil, ],
|
804
789
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
805
790
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
806
791
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
807
792
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
808
|
-
[ nil, nil, nil, nil, 28,
|
809
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
793
|
+
[ nil, nil, nil, nil, 28, 26, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
810
794
|
[ nil, nil, 6, nil, nil, nil, 7, 8, 9, 10, 11, 12, nil, 13, nil, nil, nil, ],
|
811
795
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
796
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
812
797
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 15, ],
|
813
798
|
]
|
799
|
+
def action_table; ACTION_TABLE; end
|
800
|
+
|
814
801
|
### Default Reduce Table
|
815
|
-
|
802
|
+
DEFRED_TABLE = [
|
816
803
|
nil,
|
817
804
|
nil,
|
818
805
|
-1,
|
@@ -829,9 +816,9 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
829
816
|
nil,
|
830
817
|
nil,
|
831
818
|
nil,
|
819
|
+
nil,
|
832
820
|
-9,
|
833
821
|
-17,
|
834
|
-
nil,
|
835
822
|
-18,
|
836
823
|
nil,
|
837
824
|
-4,
|
@@ -839,12 +826,14 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
839
826
|
-21,
|
840
827
|
-2,
|
841
828
|
nil,
|
842
|
-
-19,
|
843
829
|
nil,
|
830
|
+
-19,
|
844
831
|
-3,
|
845
832
|
-5,
|
846
833
|
]
|
847
|
-
|
834
|
+
def defred_table; DEFRED_TABLE; end
|
835
|
+
|
836
|
+
DEFRED_AFTER_SHIFT_TABLE = [
|
848
837
|
nil,
|
849
838
|
nil,
|
850
839
|
nil,
|
@@ -861,9 +850,9 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
861
850
|
nil,
|
862
851
|
nil,
|
863
852
|
nil,
|
853
|
+
nil,
|
864
854
|
-9,
|
865
855
|
-17,
|
866
|
-
nil,
|
867
856
|
-18,
|
868
857
|
nil,
|
869
858
|
nil,
|
@@ -871,40 +860,46 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
871
860
|
nil,
|
872
861
|
-2,
|
873
862
|
nil,
|
874
|
-
-19,
|
875
863
|
nil,
|
864
|
+
-19,
|
876
865
|
-3,
|
877
866
|
nil,
|
878
867
|
]
|
868
|
+
def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end
|
869
|
+
|
879
870
|
### Nonterm to Int
|
880
|
-
|
881
|
-
:start => 0,
|
882
|
-
:fnl => 1,
|
883
|
-
:node => 2,
|
884
|
-
:fnlpair => 3,
|
885
|
-
:fact => 4,
|
886
|
-
:list => 5,
|
887
|
-
:opt_embed => 6,
|
871
|
+
NONTERM_TO_INT = {
|
872
|
+
:start => 0,
|
873
|
+
:fnl => 1,
|
874
|
+
:node => 2,
|
875
|
+
:fnlpair => 3,
|
876
|
+
:fact => 4,
|
877
|
+
:list => 5,
|
878
|
+
:opt_embed => 6,
|
888
879
|
}
|
880
|
+
def nonterm_to_int; NONTERM_TO_INT; end
|
881
|
+
|
889
882
|
### Int to Nonterm
|
890
|
-
|
891
|
-
:start,
|
892
|
-
:fnl,
|
893
|
-
:node,
|
894
|
-
:fnlpair,
|
895
|
-
:fact,
|
896
|
-
:list,
|
897
|
-
:opt_embed,
|
883
|
+
INT_TO_NONTERM = [
|
884
|
+
:start,
|
885
|
+
:fnl,
|
886
|
+
:node,
|
887
|
+
:fnlpair,
|
888
|
+
:fact,
|
889
|
+
:list,
|
890
|
+
:opt_embed,
|
898
891
|
]
|
892
|
+
def int_to_nonterm; INT_TO_NONTERM; end
|
893
|
+
|
899
894
|
### Goto Table
|
900
|
-
|
895
|
+
GOTO_TABLE = [
|
901
896
|
[ 1, 2, 4, nil, 3, 5, nil, ],
|
902
897
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
903
898
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
904
899
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
905
900
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
906
901
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
907
|
-
[ nil, nil, nil, nil, nil, nil,
|
902
|
+
[ nil, nil, nil, nil, nil, nil, 17, ],
|
908
903
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
909
904
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
910
905
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
@@ -914,8 +909,6 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
914
909
|
[ nil, 21, 4, 20, 3, 5, nil, ],
|
915
910
|
[ nil, 22, 4, nil, 3, 5, nil, ],
|
916
911
|
[ nil, 23, 4, nil, 3, 5, nil, ],
|
917
|
-
[ nil, nil, nil, nil, nil, nil, nil, ],
|
918
|
-
[ nil, nil, nil, nil, nil, nil, nil, ],
|
919
912
|
[ nil, 21, 4, 25, 3, 5, nil, ],
|
920
913
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
921
914
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
@@ -925,14 +918,13 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
925
918
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
926
919
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
927
920
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
921
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
928
922
|
[ nil, 29, 4, nil, 3, 5, nil, ],
|
929
923
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
930
924
|
[ nil, nil, nil, nil, nil, nil, nil, ],
|
925
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
931
926
|
]
|
932
|
-
|
933
|
-
Tables = [ reduce_table, action_table,
|
934
|
-
defred_table, defred_after_shift_table, goto_table,
|
935
|
-
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
927
|
+
def goto_table; GOTO_TABLE; end
|
936
928
|
|
937
929
|
def initialize g_parser, master
|
938
930
|
super()
|
@@ -957,87 +949,74 @@ module Depager::ASTBuilderExtension::Slave_post_rhs #:nodoc:all
|
|
957
949
|
"=>... / Depager::ASTBuilderExtension"
|
958
950
|
end
|
959
951
|
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
case @line
|
965
|
-
|
952
|
+
def lex
|
953
|
+
begin
|
954
|
+
until @line.empty?
|
955
|
+
case @line
|
966
956
|
when /\A[ \t]+/
|
967
957
|
@line = $'
|
968
958
|
|
969
959
|
|
970
|
-
|
971
960
|
when /\A\r?\n/
|
972
961
|
@line = $'
|
973
962
|
yield nil, nil
|
974
963
|
|
975
|
-
|
976
964
|
when /\A<</
|
977
965
|
@line = $'
|
978
966
|
yield token(:LL, $&)
|
979
967
|
|
980
|
-
|
981
968
|
when /\A%([a-zA-Z0-9_]+)((::[a-zA-Z0-9_]+)*)/
|
982
969
|
@line = $'
|
983
970
|
yield token(:CONST, $1+$2)
|
984
971
|
|
985
|
-
|
986
972
|
when /\A%\((.+)\)%/
|
987
973
|
@line = $'
|
988
974
|
yield token(:EMBED, $1)
|
989
975
|
|
990
|
-
|
991
976
|
when /\Anil/
|
992
977
|
@line = $'
|
993
978
|
yield token(:NIL, $&)
|
994
979
|
|
995
|
-
|
996
980
|
when /\ANilNode/
|
997
981
|
@line = $'
|
998
982
|
yield token(:NILNODE, $&)
|
999
983
|
|
1000
|
-
|
1001
984
|
when /\A[0-9]+/
|
1002
985
|
@line = $'
|
1003
986
|
yield token(:NUMBER, $&.to_i)
|
1004
987
|
|
1005
|
-
|
1006
988
|
when /\A:[a-zA-Z0-9_]+/
|
1007
989
|
@line = $'
|
1008
990
|
yield token(:SYMBOL, $&)
|
1009
991
|
|
1010
|
-
|
1011
992
|
when /\A[a-zA-Z][a-zA-Z0-9_]*/
|
1012
993
|
@line = $'
|
1013
994
|
yield token(:ID, $&)
|
1014
995
|
|
1015
|
-
|
1016
996
|
when /\A'(.+)'/
|
1017
997
|
@line = $'
|
1018
998
|
yield token(:STR, $1)
|
1019
999
|
|
1020
|
-
|
1021
1000
|
when /\A./
|
1022
1001
|
@line = $'
|
1023
1002
|
yield token($&, $&)
|
1024
1003
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1004
|
+
|
1005
|
+
else
|
1006
|
+
raise RuntimeError, "must not happen #{@line}"
|
1007
|
+
end
|
1008
|
+
end
|
1009
|
+
end while @original_line = @line = file.gets
|
1010
|
+
yield nil, nil
|
1011
|
+
end
|
1012
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 173
|
1034
1013
|
def do_default
|
1035
1014
|
n = g_parser.rules.size-1
|
1036
|
-
master.action_code <<
|
1015
|
+
master.action_code << <<~CODE
|
1037
1016
|
def _ast_#{n} val
|
1038
1017
|
NilNode.new(basis.file.lineno)
|
1039
1018
|
end
|
1040
|
-
|
1019
|
+
CODE
|
1041
1020
|
master.on_reduce[n] = ":_ast_#{n}"
|
1042
1021
|
end
|
1043
1022
|
|
@@ -1046,12 +1025,10 @@ DEPAGER_EXPANDED_CODE
|
|
1046
1025
|
end
|
1047
1026
|
end
|
1048
1027
|
|
1049
|
-
|
1050
|
-
class Depager::ASTBuilderExtension::Slave_post_rhs::Action < Depager::LALR::Action #:nodoc:all
|
1028
|
+
class Depager::ASTBuilderExtension::PostRhs1::Action < Depager::LALR::Action #:nodoc:all
|
1051
1029
|
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
1052
|
-
|
1053
|
-
|
1054
|
-
nil,
|
1030
|
+
ON_REDUCE = [
|
1031
|
+
nil,
|
1055
1032
|
:_act_1,
|
1056
1033
|
:_act_2,
|
1057
1034
|
:_act_3,
|
@@ -1074,13 +1051,12 @@ class Depager::ASTBuilderExtension::Slave_post_rhs::Action < Depager::LALR::Acti
|
|
1074
1051
|
:_act_20,
|
1075
1052
|
:_act_21,
|
1076
1053
|
|
1077
|
-
|
1078
|
-
|
1054
|
+
]
|
1055
|
+
def on_reduce; ON_REDUCE; end
|
1079
1056
|
|
1080
|
-
|
1081
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 202
|
1057
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 201
|
1082
1058
|
def _act_1 val
|
1083
|
-
_fnl, = *val
|
1059
|
+
_fnl, = *val
|
1084
1060
|
|
1085
1061
|
n = g_parser.rules.size-1
|
1086
1062
|
master.action_code <<
|
@@ -1089,18 +1065,16 @@ def _act_1 val
|
|
1089
1065
|
|
1090
1066
|
end
|
1091
1067
|
DEPAGER_EXPANDED_CODE
|
1092
|
-
|
1093
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 210
|
1068
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 209
|
1094
1069
|
def _act_2 val
|
1095
|
-
_ID, _, _, = *val
|
1070
|
+
_ID, _, _, = *val
|
1096
1071
|
"#{master.node_name _ID.value}.new(basis.file.lineno)"
|
1097
1072
|
|
1098
1073
|
end
|
1099
1074
|
DEPAGER_EXPANDED_CODE
|
1100
|
-
|
1101
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 212
|
1075
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 211
|
1102
1076
|
def _act_3 val
|
1103
|
-
_ID, _, _fnlpair, _, = *val
|
1077
|
+
_ID, _, _fnlpair, _, = *val
|
1104
1078
|
|
1105
1079
|
if g_parser.rhs.size > 0
|
1106
1080
|
"#{master.node_name _ID.value}.new(val[0].lineno, #{_fnlpair.join(', ')})"
|
@@ -1110,50 +1084,44 @@ def _act_3 val
|
|
1110
1084
|
|
1111
1085
|
end
|
1112
1086
|
DEPAGER_EXPANDED_CODE
|
1113
|
-
|
1114
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 221
|
1087
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 220
|
1115
1088
|
def _act_4 val
|
1116
|
-
_fnl, = *val
|
1089
|
+
_fnl, = *val
|
1117
1090
|
[_fnl]
|
1118
1091
|
|
1119
1092
|
end
|
1120
1093
|
DEPAGER_EXPANDED_CODE
|
1121
|
-
|
1122
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 222
|
1094
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 221
|
1123
1095
|
def _act_5 val
|
1124
|
-
_fnlpair, _, _fnl, = *val
|
1096
|
+
_fnlpair, _, _fnl, = *val
|
1125
1097
|
_fnlpair << _fnl
|
1126
1098
|
|
1127
1099
|
end
|
1128
1100
|
DEPAGER_EXPANDED_CODE
|
1129
|
-
|
1130
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 225
|
1101
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 224
|
1131
1102
|
def _act_6 val
|
1132
|
-
_fact, = *val
|
1103
|
+
_fact, = *val
|
1133
1104
|
_fact
|
1134
1105
|
|
1135
1106
|
end
|
1136
1107
|
DEPAGER_EXPANDED_CODE
|
1137
|
-
|
1138
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 226
|
1108
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 225
|
1139
1109
|
def _act_7 val
|
1140
|
-
_node, = *val
|
1110
|
+
_node, = *val
|
1141
1111
|
_node
|
1142
1112
|
|
1143
1113
|
end
|
1144
1114
|
DEPAGER_EXPANDED_CODE
|
1145
|
-
|
1146
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 227
|
1115
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 226
|
1147
1116
|
def _act_8 val
|
1148
|
-
_list, = *val
|
1117
|
+
_list, = *val
|
1149
1118
|
_list
|
1150
1119
|
|
1151
1120
|
end
|
1152
1121
|
DEPAGER_EXPANDED_CODE
|
1153
|
-
|
1154
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 231
|
1122
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 230
|
1155
1123
|
def _act_9 val
|
1156
|
-
_ID, _opt_embed, = *val
|
1124
|
+
_ID, _opt_embed, = *val
|
1157
1125
|
|
1158
1126
|
unless i = g_parser.name_to_rhs_index(_ID.value)
|
1159
1127
|
warn "#{g_parser.lineno}: ?#{_ID.value}"
|
@@ -1163,81 +1131,72 @@ def _act_9 val
|
|
1163
1131
|
|
1164
1132
|
end
|
1165
1133
|
DEPAGER_EXPANDED_CODE
|
1166
|
-
|
1167
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 238
|
1134
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 237
|
1168
1135
|
def _act_10 val
|
1169
|
-
_CONST, = *val
|
1136
|
+
_CONST, = *val
|
1170
1137
|
"Depager::Token.new(#{_CONST.value})"
|
1171
1138
|
|
1172
1139
|
end
|
1173
1140
|
DEPAGER_EXPANDED_CODE
|
1174
|
-
|
1175
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 239
|
1141
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 238
|
1176
1142
|
def _act_11 val
|
1177
|
-
_SYMBOL, = *val
|
1143
|
+
_SYMBOL, = *val
|
1178
1144
|
"Depager::Token.new(#{_SYMBOL.value})"
|
1179
1145
|
|
1180
1146
|
end
|
1181
1147
|
DEPAGER_EXPANDED_CODE
|
1182
|
-
|
1183
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 240
|
1148
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 239
|
1184
1149
|
def _act_12 val
|
1185
|
-
_STR, = *val
|
1150
|
+
_STR, = *val
|
1186
1151
|
"Depager::Token.new('#{_STR.value}')"
|
1187
1152
|
|
1188
1153
|
end
|
1189
1154
|
DEPAGER_EXPANDED_CODE
|
1190
|
-
|
1191
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 241
|
1155
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 240
|
1192
1156
|
def _act_13 val
|
1193
|
-
_NILNODE, = *val
|
1157
|
+
_NILNODE, = *val
|
1194
1158
|
"NilNode.new(basis.file.lineno)"
|
1195
1159
|
|
1196
1160
|
end
|
1197
1161
|
DEPAGER_EXPANDED_CODE
|
1198
|
-
|
1199
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 242
|
1162
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 241
|
1200
1163
|
def _act_14 val
|
1201
|
-
_NUMBER, = *val
|
1164
|
+
_NUMBER, = *val
|
1202
1165
|
"Depager::Token.new(#{_NUMBER.value})"
|
1203
1166
|
|
1204
1167
|
end
|
1205
1168
|
DEPAGER_EXPANDED_CODE
|
1206
|
-
|
1207
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 243
|
1169
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 242
|
1208
1170
|
def _act_15 val
|
1209
|
-
_NIL, = *val
|
1171
|
+
_NIL, = *val
|
1210
1172
|
"nil"
|
1211
1173
|
|
1212
1174
|
end
|
1213
1175
|
DEPAGER_EXPANDED_CODE
|
1214
|
-
|
1215
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 246
|
1176
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 245
|
1216
1177
|
def _act_16 val
|
1178
|
+
# empty rule
|
1217
1179
|
''
|
1218
1180
|
|
1219
1181
|
end
|
1220
1182
|
DEPAGER_EXPANDED_CODE
|
1221
|
-
|
1222
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 247
|
1183
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 246
|
1223
1184
|
def _act_17 val
|
1224
|
-
_EMBED, = *val
|
1185
|
+
_EMBED, = *val
|
1225
1186
|
_EMBED.value
|
1226
1187
|
|
1227
1188
|
end
|
1228
1189
|
DEPAGER_EXPANDED_CODE
|
1229
|
-
|
1230
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 250
|
1190
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 249
|
1231
1191
|
def _act_18 val
|
1232
|
-
_, _, = *val
|
1192
|
+
_, _, = *val
|
1233
1193
|
"#{master.node_name '@List'}.new(basis.file.lineno, [])"
|
1234
1194
|
|
1235
1195
|
end
|
1236
1196
|
DEPAGER_EXPANDED_CODE
|
1237
|
-
|
1238
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 252
|
1197
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 251
|
1239
1198
|
def _act_19 val
|
1240
|
-
_, _fnlpair, _, = *val
|
1199
|
+
_, _fnlpair, _, = *val
|
1241
1200
|
|
1242
1201
|
if g_parser.rhs.size > 0
|
1243
1202
|
"#{master.node_name '@List'}.new(val[0].lineno, [#{_fnlpair.join(', ')}])"
|
@@ -1247,29 +1206,27 @@ def _act_19 val
|
|
1247
1206
|
|
1248
1207
|
end
|
1249
1208
|
DEPAGER_EXPANDED_CODE
|
1250
|
-
|
1251
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 259
|
1209
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 258
|
1252
1210
|
def _act_20 val
|
1253
|
-
_l, _LL, _r, = *val
|
1211
|
+
_l, _LL, _r, = *val
|
1254
1212
|
"#{_l}.push(#{_r})"
|
1255
1213
|
|
1256
1214
|
end
|
1257
1215
|
DEPAGER_EXPANDED_CODE
|
1258
|
-
|
1259
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/ast.dr', 260
|
1216
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/ast.dr', 259
|
1260
1217
|
def _act_21 val
|
1261
|
-
_l, _, _r, = *val
|
1218
|
+
_l, _, _r, = *val
|
1262
1219
|
"#{_l}.concat(#{_r})"
|
1263
1220
|
|
1264
1221
|
end
|
1265
1222
|
DEPAGER_EXPANDED_CODE
|
1266
|
-
|
1267
|
-
|
1223
|
+
|
1224
|
+
|
1268
1225
|
end
|
1269
|
-
|
1226
|
+
|
1270
1227
|
|
1271
1228
|
class Depager::ASTBuilderExtension
|
1272
|
-
BASE_NODE_TEMPLATE = <<-'
|
1229
|
+
BASE_NODE_TEMPLATE = <<-'CODE'
|
1273
1230
|
class Node
|
1274
1231
|
attr_accessor :lineno
|
1275
1232
|
attr_accessor <%= _opt_attr.map{|i| ":#{i}" }.join(', ') %>
|
@@ -1334,14 +1291,14 @@ class Depager::ASTBuilderExtension
|
|
1334
1291
|
def accept v
|
1335
1292
|
end
|
1336
1293
|
end
|
1337
|
-
|
1294
|
+
CODE
|
1338
1295
|
|
1339
|
-
NODE_TEMPLATE = <<-'
|
1296
|
+
NODE_TEMPLATE = <<-'CODE'
|
1340
1297
|
class Node_<%= name %> < Node
|
1341
1298
|
attr_accessor <%= nodes.map{|i| ":#{i}" }.join(', ') %>
|
1342
1299
|
attr_accessor <%= attrs.map{|i| ":#{i}" }.join(', ') %>
|
1343
1300
|
|
1344
|
-
def initialize <%=
|
1301
|
+
def initialize <%= ['lineno', *nodes].join(', ') %>
|
1345
1302
|
super()
|
1346
1303
|
@lineno = lineno
|
1347
1304
|
<%= nodes.inject(''){|r,i| r << " @#{i} = #{i}\n"} %>
|
@@ -1353,15 +1310,20 @@ class Depager::ASTBuilderExtension
|
|
1353
1310
|
v.visit_Node_<%= name %>(self)
|
1354
1311
|
self
|
1355
1312
|
end
|
1313
|
+
|
1314
|
+
def attributes
|
1315
|
+
{ <%= (nodes + attrs).uniq.map{|i| "#{i}: #{i}" }.join(', ') %>, lineno: lineno }
|
1316
|
+
end
|
1356
1317
|
end
|
1357
|
-
|
1318
|
+
CODE
|
1358
1319
|
|
1359
|
-
VISITOR_TEMPLATE = <<-'
|
1320
|
+
VISITOR_TEMPLATE = <<-'CODE'
|
1360
1321
|
class Visitor<%= name ? '_' + name : '' %>
|
1361
1322
|
def visit node
|
1362
1323
|
node.accept(self)
|
1363
1324
|
end
|
1364
1325
|
<%= body.join %>
|
1365
1326
|
end # Visitor<%= name ? '_' + name : '' %>
|
1366
|
-
|
1327
|
+
CODE
|
1367
1328
|
end
|
1329
|
+
|