depager 0.2.2 → 0.2.3
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.
- data/ChangeLog +4 -0
- data/README.ja +27 -28
- data/examples/c89/c89.dr +34 -34
- data/examples/c89/c89.tab.rb +3074 -3074
- data/examples/extension/paction.dr +4 -4
- data/examples/extension/pactiontest.dr +1 -1
- data/examples/pl0d/pl0ds.dr +27 -27
- data/examples/pl0d/pl0ds.tab.rb +626 -643
- data/examples/sample_calc/calc.action.dr +6 -6
- data/examples/sample_calc/calc.action.tab.rb +90 -90
- data/examples/sample_calc/calc.ast.action.dr +7 -7
- data/examples/sample_calc/calc.ast.action.tab.rb +121 -127
- data/examples/sample_calc/calc.ast.dr +6 -6
- data/examples/sample_calc/calc.ast.tab.rb +102 -109
- data/examples/sample_calc/calc.astdf.dr +6 -6
- data/examples/sample_calc/calc.astdf.tab.rb +102 -109
- data/examples/sample_calc/calc.atree.dr +6 -6
- data/examples/sample_calc/calc.atree.tab.rb +90 -90
- data/examples/sample_calc/calc.cst.dr +5 -5
- data/examples/sample_calc/calc.cst.tab.rb +106 -106
- data/examples/sample_calc/calc.dr +1 -1
- data/examples/sample_calc/calc.lex.dr +4 -4
- data/examples/sample_calc/calc.lex.tab.rb +73 -73
- data/examples/sample_calc/calc.nvaction.dr +6 -6
- data/examples/sample_calc/calc.nvaction.tab.rb +90 -90
- data/examples/sample_calc/calc.tab.rb +71 -71
- data/examples/sample_calc/calc_prec.nvaction.dr +6 -6
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +46 -46
- data/examples/slex_test/divreg.slex.dr +7 -7
- data/examples/slex_test/divreg.slex.tab.rb +20 -20
- data/examples/slex_test/ljoin.slex.dr +7 -7
- data/examples/slex_test/ljoin.slex.tab.rb +15 -15
- data/lib/depager.rb +45 -83
- data/lib/depager/grammar.rb +3 -7
- data/lib/depager/lr.rb +123 -1
- data/lib/depager/parser.rb +29 -48
- data/lib/depager/{template/ast.erbs → ruby/plugins/_ast_tmpl.rb} +11 -7
- data/lib/depager/{action.rb → ruby/plugins/action.rb} +7 -11
- data/lib/depager/{ast.dr → ruby/plugins/ast.dr} +24 -25
- data/lib/depager/{ast.rb → ruby/plugins/ast.rb} +241 -243
- data/lib/depager/{astdf.rb → ruby/plugins/astdf.rb} +1 -2
- data/lib/depager/{atree.dr → ruby/plugins/atree.dr} +5 -5
- data/lib/depager/{atree.rb → ruby/plugins/atree.rb} +39 -39
- data/lib/depager/{cst.dr → ruby/plugins/cst.dr} +17 -21
- data/lib/depager/{cst.rb → ruby/plugins/cst.rb} +62 -68
- data/lib/depager/{lex.dr → ruby/plugins/lex.dr} +3 -4
- data/lib/depager/{lex.rb → ruby/plugins/lex.rb} +29 -31
- data/lib/depager/{nvaction.rb → ruby/plugins/nvaction.rb} +1 -3
- data/lib/depager/{slex.dr → ruby/plugins/slex.dr} +16 -17
- data/lib/depager/{slex.rb → ruby/plugins/slex.rb} +115 -117
- data/lib/depager/{srp.rb → ruby/plugins/srp.rb} +4 -4
- data/lib/depager/{template → ruby/templates}/extension_lalr_master.erb +6 -6
- data/lib/depager/{template → ruby/templates}/extension_lalr_slave.erb +0 -0
- data/lib/depager/{template → ruby/templates}/simple.erb +0 -0
- data/lib/depager/{template → ruby/templates}/single_lalr_parser.erb +0 -0
- data/lib/depager/utils.rb +30 -69
- data/lib/depager/version.rb +1 -1
- metadata +59 -56
- data/examples/Rakefile +0 -36
- data/lib/depager/Rakefile +0 -34
- data/lib/depager/lr_put_table.rb +0 -116
- data/lib/depager/parse_action.rb +0 -24
data/lib/depager/grammar.rb
CHANGED
@@ -2,8 +2,8 @@ module Depager::ParsingMethod
|
|
2
2
|
class Grammar
|
3
3
|
attr_accessor :rulelist, :lhs_to_rule, :syms, :nonterms, :terms
|
4
4
|
attr_accessor :precs, :f0e, :first1
|
5
|
-
Eps = 0x3fffffff #epsilon
|
6
|
-
#
|
5
|
+
Eps = 0x3fffffff #epsilon #Eps = []
|
6
|
+
def initialize_depend ; end # template method for inheritance
|
7
7
|
def initialize rulelist, terms, nonterms, precs = nil
|
8
8
|
@precs = precs
|
9
9
|
@nonterms = nonterms.invert
|
@@ -26,9 +26,6 @@ module Depager::ParsingMethod
|
|
26
26
|
initialize_depend
|
27
27
|
end
|
28
28
|
|
29
|
-
def initialize_depend
|
30
|
-
end
|
31
|
-
|
32
29
|
def make_sym_mask
|
33
30
|
@sym_mask, @mask_sym = {}, []
|
34
31
|
@terms.sort_by{|a, b| a}.each_with_index do |i,x|
|
@@ -90,8 +87,8 @@ module Depager::ParsingMethod
|
|
90
87
|
end
|
91
88
|
end while changed
|
92
89
|
|
93
|
-
old_make_sym_first
|
94
90
|
=begin
|
91
|
+
old_make_sym_first
|
95
92
|
warn "check.."
|
96
93
|
@first1.each do |k,v|
|
97
94
|
old = @old_first1[k].sort
|
@@ -256,7 +253,6 @@ module Depager::ParsingMethod
|
|
256
253
|
end
|
257
254
|
end
|
258
255
|
end
|
259
|
-
G = Grammar
|
260
256
|
|
261
257
|
class Rule
|
262
258
|
def self.[] l, r, prec = nil
|
data/lib/depager/lr.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'pp'
|
2
2
|
require 'depager/grammar.rb'
|
3
|
+
|
4
|
+
module Depager::ParsingMethod
|
5
|
+
class Grammar
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
module Depager::LALR
|
4
10
|
class SingleParserGenerator < Simple::SingleGenerator
|
5
11
|
Tmplfile = 'single_lalr_parser.erb'
|
@@ -420,7 +426,6 @@ module Depager::LALR
|
|
420
426
|
@warning_list.each{|i| dp.warning i }
|
421
427
|
|
422
428
|
if $MP_DEBUG
|
423
|
-
require 'depager/lr_put_table.rb'
|
424
429
|
gen_state_info
|
425
430
|
verbose dp if $MP_VERBOSE
|
426
431
|
end
|
@@ -455,3 +460,120 @@ module Depager::LALR
|
|
455
460
|
end
|
456
461
|
end
|
457
462
|
end
|
463
|
+
|
464
|
+
class Depager::LALR::Table
|
465
|
+
def state_info
|
466
|
+
@state_info
|
467
|
+
end
|
468
|
+
|
469
|
+
#puts grammar.closure.values.join("\n")
|
470
|
+
#puts "-----"
|
471
|
+
#puts grammar.memo_closure1.sort_by{|k,v| k}.map{|k,v| "#{k.inspect}:\n#{v.join("\n")}"}
|
472
|
+
#puts 'mk'; mk.each{|k, v| p "#{k}=>#{v}"}
|
473
|
+
#trn = trn.uniq
|
474
|
+
#puts 'trn',trn.map{|a| "<#{a[2].n}>#{a[0]} => <#{a[3].n}>#{a[1]}"}
|
475
|
+
|
476
|
+
def gen_state_info
|
477
|
+
g = grammar
|
478
|
+
@state_info = []
|
479
|
+
@action_table.each_with_index {|s,x|
|
480
|
+
shi, red, acc = "", "", ""
|
481
|
+
s.each_with_index {|t, y|
|
482
|
+
next unless t
|
483
|
+
hd = (" %-15s" % g.symname(y + g.nonterms.size))
|
484
|
+
if t == 'ACC'
|
485
|
+
acc = "#{hd} accept\n\n"
|
486
|
+
elsif t < 0
|
487
|
+
red << "#{hd} reduce using rule #{-t} (#{g.symname g[-t].lhs})\n"
|
488
|
+
else
|
489
|
+
shi << "#{hd} shift, and goto to state #{t}\n"
|
490
|
+
end
|
491
|
+
}
|
492
|
+
if t = @defred_table[x]
|
493
|
+
as = @defred_after_shift_table[x] ? " [after shift]" : ""
|
494
|
+
red << (" %-15s" % '$default') <<
|
495
|
+
"reduce using rule #{-t} (#{g.symname g[-t].lhs}) #{as}\n"
|
496
|
+
end
|
497
|
+
|
498
|
+
@state_info << (@states[x].to_s << "\n\n#{shi}\n#{red}\n#{acc}")
|
499
|
+
}
|
500
|
+
end
|
501
|
+
|
502
|
+
def verbose dp
|
503
|
+
g, output = grammar, []
|
504
|
+
|
505
|
+
if $MP_DEBUG.match(/f/)
|
506
|
+
output << "** FIRST1 **"
|
507
|
+
str = g.first1.map{|k, v|
|
508
|
+
"#{g.symname k} => #{v.map{|i| g.symname i}.join(' ')}"
|
509
|
+
}.join("\n")
|
510
|
+
output << "#{str}\n\n"
|
511
|
+
end
|
512
|
+
|
513
|
+
if $MP_DEBUG.match(/e/)
|
514
|
+
output << "** Empty Reduction **"
|
515
|
+
str = g.f0e.map {|k, v|
|
516
|
+
"#{g.symname k} =>\n" << v.map{|n, f|
|
517
|
+
" #{rulelist[n]} ? #{f.map{|i| g.symname i}.join(' ')}"
|
518
|
+
}.join("\n")
|
519
|
+
}.join("\n")
|
520
|
+
output << "#{str}\n\n"
|
521
|
+
end
|
522
|
+
|
523
|
+
if $MP_DEBUG.match(/s/)
|
524
|
+
output << "** SYMBOLS **"
|
525
|
+
str = g.syms.map{|k,_| "#{"%03i" % k} #{ g.symname k}"}.sort.join("\n")
|
526
|
+
output << "#{str}\n\n"
|
527
|
+
end
|
528
|
+
|
529
|
+
if $MP_DEBUG.match(/g/)
|
530
|
+
output << "*** Grammar ***"
|
531
|
+
str = g.rulelist.join("\n")
|
532
|
+
output << "#{str}\n\n"
|
533
|
+
end
|
534
|
+
|
535
|
+
if $MP_DEBUG.match(/c/)
|
536
|
+
output << "*** States ***"
|
537
|
+
output << @state_info.to_s
|
538
|
+
end
|
539
|
+
|
540
|
+
nssize = g.nonterms.size
|
541
|
+
if $MP_DEBUG.match(/t/)
|
542
|
+
output << "*** Action Table ***"
|
543
|
+
ws = (nssize...g.syms.size).map{|i| j = g.symname(i).size; j < 6 ? 6 : j}
|
544
|
+
str = " |"
|
545
|
+
(nssize...g.syms.size).each_with_index{|i, x|
|
546
|
+
str << ("%0#{ws[x]}s|" % g.symname(i))
|
547
|
+
}; str << " $default|\n"
|
548
|
+
|
549
|
+
@action_table.each_with_index{|i,x|
|
550
|
+
str << ("%03i|" % x)
|
551
|
+
i.each_with_index{|j, y|
|
552
|
+
str << ("%0#{ws[y]}s|" % j)
|
553
|
+
}
|
554
|
+
str << ("%04s,%04s|\n" % [@defred_table[x], @defred_after_shift_table[x]])
|
555
|
+
}
|
556
|
+
output << "#{str}\n\n"
|
557
|
+
|
558
|
+
output << "*** Goto Table ***"
|
559
|
+
ws = (1...nssize).map{|i| j = g.symname(i).size; j < 6 ? 6 : j}
|
560
|
+
str = " |"
|
561
|
+
(1...nssize).each_with_index{|i, x|
|
562
|
+
str << ("%0#{ws[x]}s|" % g.symname(i))
|
563
|
+
}; str << "\n"
|
564
|
+
|
565
|
+
@goto_table.each_with_index{|i,x|
|
566
|
+
str << ("%03i|" % x)
|
567
|
+
i.each_with_index{|j, y|
|
568
|
+
str << ("%0#{ws[y]}s|" % j)
|
569
|
+
}
|
570
|
+
str << "\n"
|
571
|
+
}
|
572
|
+
output << "#{str}\n\n"
|
573
|
+
end
|
574
|
+
|
575
|
+
File.open("#{File.basename(dp.files.fname, '.dr')}.output", "w"){|f|
|
576
|
+
f.write output.join("\n")
|
577
|
+
}
|
578
|
+
end
|
579
|
+
end
|
data/lib/depager/parser.rb
CHANGED
@@ -40,19 +40,10 @@ module Depager::LALR
|
|
40
40
|
# [0, [la0, v0], s0, [la1, v1], s1, .....]
|
41
41
|
#
|
42
42
|
class Parser
|
43
|
-
def initialize
|
44
|
-
end
|
45
|
-
|
46
43
|
ACC = 0x03ffffff
|
47
44
|
|
48
|
-
#
|
49
|
-
# lexer
|
50
|
-
#
|
51
|
-
def lex
|
52
|
-
end
|
53
|
-
|
54
45
|
# parse method
|
55
|
-
def
|
46
|
+
def parse f
|
56
47
|
@basis.file = f
|
57
48
|
@basis.la = [0, nil]
|
58
49
|
@basis.lex do |sym, val|
|
@@ -63,9 +54,6 @@ module Depager::LALR
|
|
63
54
|
end
|
64
55
|
|
65
56
|
protected
|
66
|
-
def init_parser
|
67
|
-
end
|
68
|
-
|
69
57
|
# driver method
|
70
58
|
def driver
|
71
59
|
while true
|
@@ -95,14 +83,6 @@ module Depager::LALR
|
|
95
83
|
end
|
96
84
|
end
|
97
85
|
end
|
98
|
-
def accept
|
99
|
-
end
|
100
|
-
def error
|
101
|
-
end
|
102
|
-
def shift
|
103
|
-
end
|
104
|
-
def reduce
|
105
|
-
end
|
106
86
|
|
107
87
|
def enable?(act, sym)
|
108
88
|
case act
|
@@ -125,6 +105,14 @@ module Depager::LALR
|
|
125
105
|
else
|
126
106
|
end
|
127
107
|
end
|
108
|
+
|
109
|
+
# template methods
|
110
|
+
def init_parser ; end
|
111
|
+
def lex ; end
|
112
|
+
def accept ; end
|
113
|
+
def error ; end
|
114
|
+
def shift ; end
|
115
|
+
def reduce ; end
|
128
116
|
end
|
129
117
|
|
130
118
|
class Basis < Parser
|
@@ -153,7 +141,7 @@ module Depager::LALR
|
|
153
141
|
@t2i, @i2t, @nt2i, @i2nt = self.class::Tables
|
154
142
|
end
|
155
143
|
|
156
|
-
def
|
144
|
+
def token sym, val=nil, lineno=nil
|
157
145
|
lineno ||= file.lineno
|
158
146
|
return sym, Depager::Token[val, lineno, file.path]
|
159
147
|
end
|
@@ -227,42 +215,35 @@ module Depager::LALR
|
|
227
215
|
end
|
228
216
|
|
229
217
|
def accept
|
230
|
-
|
218
|
+
before_accept
|
231
219
|
@inside.accept
|
232
|
-
|
220
|
+
after_accept
|
233
221
|
end
|
234
222
|
def error
|
235
|
-
|
223
|
+
before_error
|
236
224
|
@inside.error
|
237
|
-
|
225
|
+
after_error
|
238
226
|
end
|
239
227
|
def shift
|
240
|
-
|
228
|
+
before_shift
|
241
229
|
@inside.shift
|
242
|
-
|
230
|
+
after_shift
|
243
231
|
end
|
244
232
|
def reduce
|
245
|
-
|
233
|
+
before_reduce
|
246
234
|
@inside.reduce
|
247
|
-
|
235
|
+
after_reduce
|
248
236
|
end
|
249
237
|
|
250
|
-
|
251
|
-
end
|
252
|
-
def
|
253
|
-
end
|
254
|
-
def
|
255
|
-
end
|
256
|
-
def
|
257
|
-
end
|
258
|
-
def
|
259
|
-
end
|
260
|
-
def afterShift
|
261
|
-
end
|
262
|
-
def beforeReduce
|
263
|
-
end
|
264
|
-
def afterReduce
|
265
|
-
end
|
238
|
+
# template methods
|
239
|
+
def before_accept ; end
|
240
|
+
def after_accept ; end
|
241
|
+
def before_error ; end
|
242
|
+
def after_error ; end
|
243
|
+
def before_shift ; end
|
244
|
+
def after_shift ; end
|
245
|
+
def before_reduce ; end
|
246
|
+
def after_reduce ; end
|
266
247
|
end
|
267
248
|
|
268
249
|
#
|
@@ -273,7 +254,7 @@ module Depager::LALR
|
|
273
254
|
super inside, nparamkey
|
274
255
|
@_yy_val_ = []
|
275
256
|
end
|
276
|
-
def
|
257
|
+
def before_reduce
|
277
258
|
@_yy_val_ = []
|
278
259
|
n = @reduce_table[-_actvalue][1]
|
279
260
|
n.times do |i|
|
@@ -281,7 +262,7 @@ module Depager::LALR
|
|
281
262
|
@_yy_val_[n-i-1] = x[1] == :NT ? x[@nparam] : x[1]
|
282
263
|
end
|
283
264
|
end
|
284
|
-
def
|
265
|
+
def after_reduce
|
285
266
|
mes = @on_reduce[-_actvalue]
|
286
267
|
r = mes ? self.send(mes, @_yy_val_) : nil
|
287
268
|
_stack[_stack.size-2][@nparam] = r
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
1
|
+
class ASTBuilderExtension
|
2
|
+
TMPL_NODE_BASE = <<EOS
|
2
3
|
class Node
|
3
4
|
attr_accessor :lineno
|
4
|
-
attr_accessor <%= _opt_attr.map{|i| "
|
5
|
+
attr_accessor <%= _opt_attr.map{|i| ":\#{i}" }.join(', ') %>
|
5
6
|
<%= ini %>
|
6
7
|
def self.[] lineno, *args
|
7
8
|
self.new lineno, *args
|
@@ -43,22 +44,23 @@ class NodeList < Node
|
|
43
44
|
end
|
44
45
|
class NilNode
|
45
46
|
attr_accessor :lineno
|
46
|
-
attr_accessor <%= _opt_attr.map{|i| "
|
47
|
+
attr_accessor <%= _opt_attr.map{|i| ":\#{i}" }.join(', ') %>
|
47
48
|
def initialize(lineno, *args)
|
48
49
|
@lineno = lineno
|
49
50
|
end
|
50
51
|
def accept v
|
51
52
|
end
|
52
53
|
end
|
54
|
+
EOS
|
53
55
|
|
54
|
-
|
56
|
+
TMPL_NODE = <<EOS
|
55
57
|
class Node_<%= name %> < Node
|
56
|
-
attr_accessor <%= nodes.map{|i| "
|
57
|
-
attr_accessor <%= attrs.map{|i| "
|
58
|
+
attr_accessor <%= nodes.map{|i| ":\#{i}" }.join(', ') %>
|
59
|
+
attr_accessor <%= attrs.map{|i| ":\#{i}" }.join(', ') %>
|
58
60
|
def initialize <%= nodes.unshift('lineno').join(', ') %>
|
59
61
|
super()
|
60
62
|
@lineno = lineno
|
61
|
-
<%= nodes.inject(''){|r,i| r << "
|
63
|
+
<%= nodes.inject(''){|r,i| r << " @\#{i} = \#{i}\n"} %>
|
62
64
|
end
|
63
65
|
def accept v
|
64
66
|
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
@@ -67,3 +69,5 @@ class Node_<%= name %> < Node
|
|
67
69
|
self
|
68
70
|
end
|
69
71
|
end
|
72
|
+
EOS
|
73
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'depager/parser.rb'
|
2
|
-
require 'depager/parse_action.rb'
|
3
2
|
|
4
3
|
class ActionExtension #:nodoc:all
|
5
4
|
include Depager::ExtensionUtils
|
6
|
-
include Depager::ActionParser
|
7
5
|
def initialize
|
8
6
|
@line0 = @line = @oldline = ''
|
9
7
|
@optouter = []
|
@@ -14,31 +12,29 @@ class ActionExtension #:nodoc:all
|
|
14
12
|
return code, 0
|
15
13
|
end
|
16
14
|
|
17
|
-
def
|
15
|
+
def pre_rule_list
|
18
16
|
if g_parser.line0 =~ /^%ACTION\{\s*$/
|
19
17
|
while line = getline
|
20
18
|
break if line =~ /^%\}\s*$/
|
21
19
|
@optouter.push line
|
22
20
|
end
|
23
|
-
|
24
|
-
gettoken
|
21
|
+
g_parser.update_context ''
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
def
|
29
|
-
if
|
30
|
-
@line0, @line = g_parser.line0, g_parser.
|
25
|
+
def post_rhs
|
26
|
+
if g_parser.line =~ /\s*\{/
|
27
|
+
@line0, @line = g_parser.line0, g_parser.line
|
31
28
|
lineno = g_parser.lineno
|
32
29
|
code, d = modify_action_code(parse_action)
|
33
30
|
@optouter <<
|
34
31
|
gen_defm_code("_act_#{nrules} val", code, lineno, d)
|
35
|
-
|
36
|
-
gettoken
|
32
|
+
g_parser.update_context @line
|
37
33
|
@on_reduce[nrules] = ":_act_#{nrules}"
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
|
-
def
|
37
|
+
def post_rule_list
|
42
38
|
g_parser.optouter <<
|
43
39
|
gen_action_decorator_code(
|
44
40
|
target_name, paramkey,
|
@@ -1,9 +1,10 @@
|
|
1
1
|
%defext ASTBuilderExtension
|
2
|
-
%extend Lexer ('
|
3
|
-
%extend NVAction ('
|
2
|
+
%extend Lexer ('plugins/lex.rb')
|
3
|
+
%extend NVAction ('plugins/nvaction.rb')
|
4
4
|
%decorate @NVAction
|
5
|
-
#%decorate ShiftReducePrinter ('
|
5
|
+
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
6
6
|
%inner{
|
7
|
+
require 'plugins/_ast_tmpl'
|
7
8
|
attr_accessor :optouter, :on_reduce, :visitor
|
8
9
|
def init_parser
|
9
10
|
super
|
@@ -12,13 +13,12 @@
|
|
12
13
|
@on_reduce = []
|
13
14
|
@output_file_name = nil
|
14
15
|
end
|
15
|
-
def
|
16
|
+
def post_rule_list
|
16
17
|
g_parser.optouter <<
|
17
18
|
gen_action_decorator_code(target_name, paramkey,
|
18
19
|
@on_reduce, @optouter)
|
19
20
|
end
|
20
21
|
|
21
|
-
Template = CodeUtils::make_tmpl("#{Depager::Tmpldir}/ast.erbs")
|
22
22
|
def modify_action_code code, nodes=[]
|
23
23
|
code = code.gsub(/\$\.([a-z_])/, 'node.\1')
|
24
24
|
code << %{
|
@@ -37,19 +37,18 @@
|
|
37
37
|
@output_file_name = ofname
|
38
38
|
end
|
39
39
|
%}
|
40
|
-
%hook
|
40
|
+
%hook pre_rule_list /%AST\{\s*\Z/ skip
|
41
41
|
%banner '%AST{ ... }'
|
42
|
-
%mixin ActionParser ('depager/parse_action')
|
43
42
|
%%
|
44
43
|
|
45
44
|
%LEX{
|
46
45
|
/\s+/, /#.*/ { }
|
47
46
|
/%\}\s*\Z/ { @line = $'; yield nil,nil }
|
48
|
-
'Node' { yield
|
49
|
-
'Visitor' { yield
|
50
|
-
/[a-zA-Z][a-zA-Z0-9_]*/ { yield
|
51
|
-
'{' ! { ln = lineno; yield
|
52
|
-
/./ { yield
|
47
|
+
'Node' { yield token(:NODE, $&) }
|
48
|
+
'Visitor' { yield token(:VISITOR, $&) }
|
49
|
+
/[a-zA-Z][a-zA-Z0-9_]*/ { yield token(:ID, $&) }
|
50
|
+
'{' ! { ln = lineno; yield token(:ACTION, parse_action, ln) }
|
51
|
+
/./ { yield token($&, $&) }
|
53
52
|
%}
|
54
53
|
|
55
54
|
#begin-rule
|
@@ -92,7 +91,7 @@
|
|
92
91
|
#{_ACTION.value}
|
93
92
|
end
|
94
93
|
};#code
|
95
|
-
master.
|
94
|
+
ERB.new(master.class::TMPL_NODE_BASE).result(binding)
|
96
95
|
}
|
97
96
|
;
|
98
97
|
opt_defvis:
|
@@ -131,7 +130,7 @@
|
|
131
130
|
master.gen_defm_code("visit_Node_#{name} node",
|
132
131
|
vis_code, act.lineno)
|
133
132
|
end
|
134
|
-
master.
|
133
|
+
ERB.new(master.class::TMPL_NODE).result(binding)
|
135
134
|
}
|
136
135
|
;
|
137
136
|
defnode_header:
|
@@ -173,7 +172,7 @@
|
|
173
172
|
;
|
174
173
|
#end-rule
|
175
174
|
%%
|
176
|
-
%hook
|
175
|
+
%hook post_rhs /=>/ skip
|
177
176
|
%banner '=>...'
|
178
177
|
%prec{
|
179
178
|
left LL '@'
|
@@ -191,17 +190,17 @@
|
|
191
190
|
%LEX{
|
192
191
|
/[ \t]+/ { }
|
193
192
|
/\r?\n/ { yield nil, nil }
|
194
|
-
/<</ { yield
|
193
|
+
/<</ { yield token(:LL, $&) }
|
195
194
|
/%([a-zA-Z0-9_]+)((::[a-zA-Z0-9_]+)*)/
|
196
|
-
{ yield
|
197
|
-
/%\((.+)\)%/ { yield
|
198
|
-
'nil' { yield
|
199
|
-
'NilNode' { yield
|
200
|
-
/[0-9]+/ { yield
|
201
|
-
/:[a-zA-Z0-9_]+/ { yield
|
202
|
-
/[a-zA-Z][a-zA-Z0-9_]*/ { yield
|
203
|
-
/'(.+)'/ { yield
|
204
|
-
/./ { yield
|
195
|
+
{ yield token(:CONST, $1+$2) }
|
196
|
+
/%\((.+)\)%/ { yield token(:EMBED, $1) }
|
197
|
+
'nil' { yield token(:NIL, $&) }
|
198
|
+
'NilNode' { yield token(:NILNODE, $&) }
|
199
|
+
/[0-9]+/ { yield token(:NUMBER, $&.to_i) }
|
200
|
+
/:[a-zA-Z0-9_]+/ { yield token(:SYMBOL, $&) }
|
201
|
+
/[a-zA-Z][a-zA-Z0-9_]*/ { yield token(:ID, $&) }
|
202
|
+
/'(.+)'/ { yield token(:STR, $1) }
|
203
|
+
/./ { yield token($&, $&) }
|
205
204
|
%}
|
206
205
|
#begin-rule
|
207
206
|
start:
|