depager 0.2.3 → 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 +7 -0
- 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 +7 -21
- data/README.ja +19 -99
- data/Rakefile +31 -0
- data/bin/depager +7 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +48 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +9 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/{sample_calc/calc.action.dr → extension/calc.simple_action.dr} +33 -33
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +46 -0
- data/examples/pl0d/pl0ds.dr +337 -334
- data/examples/pl0d/test.pl0ds +33 -33
- data/examples/rie_calc/calc.rie.dr +57 -0
- data/examples/rie_calc/test.calc +4 -0
- data/examples/rie_dcuse/dcuse.rie.dr +71 -0
- data/examples/rie_dcuse/test.dcuse +1 -0
- data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
- data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
- data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
- data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
- data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
- data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
- data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
- data/examples/rie_pl0/pl0.rie.dr +450 -0
- data/examples/rie_pl0/test.pl0 +10 -0
- data/examples/slex_test/divreg.slex.dr +29 -29
- data/examples/slex_test/ljoin.slex.dr +36 -36
- data/examples/slex_test/test.divreg +1 -1
- data/examples/slex_test/test.ljoin +3 -3
- data/examples/{sample_calc/calc.nvaction.dr → tiny_calc/calc.action.dr} +33 -33
- data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +76 -66
- data/examples/{sample_calc → tiny_calc}/calc.ast.dr +67 -55
- data/examples/tiny_calc/calc.cst.dr +50 -0
- data/examples/{sample_calc → tiny_calc}/calc.dr +43 -43
- data/examples/{sample_calc → tiny_calc}/calc.lex.dr +29 -29
- data/examples/{sample_calc/calc_prec.nvaction.dr → tiny_calc/calc_prec.action.dr} +31 -31
- data/lib/depager/cli.rb +44 -0
- data/lib/depager/grammar.rb +253 -291
- data/lib/depager/lr.rb +589 -579
- data/lib/depager/parser.rb +269 -277
- data/lib/depager/plugins/_rie_debug.rb +63 -0
- data/lib/depager/plugins/action.rb +47 -0
- data/lib/depager/plugins/ast.dr +367 -0
- data/lib/depager/plugins/ast.rb +1329 -0
- data/lib/depager/{ruby/plugins → plugins}/cst.dr +174 -180
- data/lib/depager/plugins/cst.rb +591 -0
- data/lib/depager/{ruby/plugins → plugins}/lex.dr +85 -89
- data/lib/depager/plugins/lex.rb +313 -0
- data/lib/depager/plugins/rie.dr +725 -0
- data/lib/depager/plugins/rie.rb +1614 -0
- data/lib/depager/{ruby/plugins → plugins}/slex.dr +201 -200
- data/lib/depager/plugins/slex.rb +769 -0
- data/lib/depager/plugins/srp.rb +46 -0
- data/lib/depager/ruby/templates/extension_lalr_master.erb +40 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +113 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +124 -117
- data/lib/depager/utils.rb +158 -318
- data/lib/depager/version.rb +3 -3
- data/lib/depager.rb +572 -670
- metadata +77 -80
- data/ChangeLog +0 -16
- data/data/depager/pre-setup.rb +0 -3
- data/examples/c89/c89.tab.rb +0 -7127
- data/examples/pl0d/pl0ds.tab.rb +0 -2698
- data/examples/sample_calc/calc.action.tab.rb +0 -457
- data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
- data/examples/sample_calc/calc.ast.tab.rb +0 -665
- data/examples/sample_calc/calc.astdf.dr +0 -54
- data/examples/sample_calc/calc.astdf.tab.rb +0 -672
- data/examples/sample_calc/calc.atree.tab.rb +0 -451
- data/examples/sample_calc/calc.cst.dr +0 -45
- data/examples/sample_calc/calc.cst.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
- data/examples/sample_calc/calc.tab.rb +0 -365
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
- data/examples/slex_test/divreg.slex.tab.rb +0 -303
- data/examples/slex_test/ljoin.slex.tab.rb +0 -370
- data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
- data/lib/depager/ruby/plugins/action.rb +0 -43
- data/lib/depager/ruby/plugins/ast.dr +0 -269
- data/lib/depager/ruby/plugins/ast.rb +0 -1308
- data/lib/depager/ruby/plugins/astdf.rb +0 -6
- data/lib/depager/ruby/plugins/atree.dr +0 -55
- data/lib/depager/ruby/plugins/atree.rb +0 -347
- data/lib/depager/ruby/plugins/cst.rb +0 -626
- data/lib/depager/ruby/plugins/lex.rb +0 -336
- data/lib/depager/ruby/plugins/nvaction.rb +0 -19
- data/lib/depager/ruby/plugins/slex.rb +0 -817
- data/lib/depager/ruby/plugins/srp.rb +0 -51
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
- /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
@@ -1,370 +0,0 @@
|
|
1
|
-
|
2
|
-
begin; require 'rubygems'; rescue Exception; end
|
3
|
-
require 'depager/parser.rb'
|
4
|
-
|
5
|
-
|
6
|
-
module Depager::DecoratorUtils; end
|
7
|
-
module D4StatefulLexerTest2; end
|
8
|
-
|
9
|
-
class StatefulLexerTest2 < Depager::LALR::Basis
|
10
|
-
|
11
|
-
|
12
|
-
### Reduce Table
|
13
|
-
reduce_table = [
|
14
|
-
[ -1, 1 ], # ( 0) $start : stmts
|
15
|
-
[ 0, 0 ], # ( 1) stmts :
|
16
|
-
[ 0, 3 ], # ( 2) stmts : stmts expr EOL
|
17
|
-
[ 1, 4 ], # ( 3) expr : expr '+' __expr_0_2__ fact
|
18
|
-
[ 1, 1 ], # ( 4) expr : fact
|
19
|
-
[ 3, 0 ], # ( 5) __expr_0_2__ :
|
20
|
-
[ 2, 1 ], # ( 6) fact : ID
|
21
|
-
]
|
22
|
-
### Extension Params
|
23
|
-
nparams = {
|
24
|
-
'NVAction' => 3,
|
25
|
-
'StatefulLexer' => 2,
|
26
|
-
}
|
27
|
-
### Term to Int
|
28
|
-
t2i = {
|
29
|
-
nil => 0,
|
30
|
-
false => 1,
|
31
|
-
:EOL => 2,
|
32
|
-
"+" => 3,
|
33
|
-
:ID => 4,
|
34
|
-
}
|
35
|
-
### Int to Term
|
36
|
-
i2t = [
|
37
|
-
nil,
|
38
|
-
false,
|
39
|
-
:EOL,
|
40
|
-
"+",
|
41
|
-
:ID,
|
42
|
-
]
|
43
|
-
### Action Table
|
44
|
-
action_table = [
|
45
|
-
[ nil, nil, nil, nil, nil, ],
|
46
|
-
[ ACC, nil, nil, nil, 4, ],
|
47
|
-
[ nil, nil, 5, 6, nil, ],
|
48
|
-
[ nil, nil, nil, nil, nil, ],
|
49
|
-
[ nil, nil, nil, nil, nil, ],
|
50
|
-
[ nil, nil, nil, nil, nil, ],
|
51
|
-
[ nil, nil, nil, nil, nil, ],
|
52
|
-
[ nil, nil, nil, nil, 4, ],
|
53
|
-
[ nil, nil, nil, nil, nil, ],
|
54
|
-
]
|
55
|
-
### Default Reduce Table
|
56
|
-
defred_table = [
|
57
|
-
-1,
|
58
|
-
nil,
|
59
|
-
nil,
|
60
|
-
-4,
|
61
|
-
-6,
|
62
|
-
-2,
|
63
|
-
-5,
|
64
|
-
nil,
|
65
|
-
-3,
|
66
|
-
]
|
67
|
-
defred_after_shift_table = [
|
68
|
-
-1,
|
69
|
-
nil,
|
70
|
-
nil,
|
71
|
-
-4,
|
72
|
-
-6,
|
73
|
-
-2,
|
74
|
-
-5,
|
75
|
-
nil,
|
76
|
-
-3,
|
77
|
-
]
|
78
|
-
### Nonterm to Int
|
79
|
-
nt2i = {
|
80
|
-
:stmts => 0,
|
81
|
-
:expr => 1,
|
82
|
-
:fact => 2,
|
83
|
-
:__expr_0_2__ => 3,
|
84
|
-
}
|
85
|
-
### Int to Nonterm
|
86
|
-
i2nt = [
|
87
|
-
:stmts,
|
88
|
-
:expr,
|
89
|
-
:fact,
|
90
|
-
:__expr_0_2__,
|
91
|
-
]
|
92
|
-
### Goto Table
|
93
|
-
goto_table = [
|
94
|
-
[ 1, nil, nil, nil, ],
|
95
|
-
[ nil, 2, 3, nil, ],
|
96
|
-
[ nil, nil, nil, nil, ],
|
97
|
-
[ nil, nil, nil, nil, ],
|
98
|
-
[ nil, nil, nil, nil, ],
|
99
|
-
[ nil, nil, nil, nil, ],
|
100
|
-
[ nil, nil, nil, 7, ],
|
101
|
-
[ nil, nil, 8, nil, ],
|
102
|
-
[ nil, nil, nil, nil, ],
|
103
|
-
]
|
104
|
-
|
105
|
-
|
106
|
-
alias orig_error error
|
107
|
-
def error
|
108
|
-
orig_error
|
109
|
-
warn "current state: #{StateInfo[@stack.last]}"
|
110
|
-
end
|
111
|
-
|
112
|
-
### States
|
113
|
-
StateInfo = [
|
114
|
-
<<'----------',
|
115
|
-
I000 =
|
116
|
-
( 0) $start : _ stmts
|
117
|
-
|
118
|
-
|
119
|
-
$default reduce using rule 1 (stmts) [after shift]
|
120
|
-
|
121
|
-
----------
|
122
|
-
|
123
|
-
<<'----------',
|
124
|
-
I001 =
|
125
|
-
( 0) $start : stmts _
|
126
|
-
( 2) stmts : stmts _ expr EOL
|
127
|
-
|
128
|
-
ID shift, and goto to state 4
|
129
|
-
|
130
|
-
|
131
|
-
$end accept
|
132
|
-
|
133
|
-
----------
|
134
|
-
|
135
|
-
<<'----------',
|
136
|
-
I002 =
|
137
|
-
( 2) stmts : stmts expr _ EOL
|
138
|
-
( 3) expr : expr _ '+' __expr_0_2__ fact
|
139
|
-
|
140
|
-
EOL shift, and goto to state 5
|
141
|
-
'+' shift, and goto to state 6
|
142
|
-
|
143
|
-
|
144
|
-
----------
|
145
|
-
|
146
|
-
<<'----------',
|
147
|
-
I003 =
|
148
|
-
( 4) expr : fact _
|
149
|
-
|
150
|
-
|
151
|
-
$default reduce using rule 4 (expr) [after shift]
|
152
|
-
|
153
|
-
----------
|
154
|
-
|
155
|
-
<<'----------',
|
156
|
-
I004 =
|
157
|
-
( 6) fact : ID _
|
158
|
-
|
159
|
-
|
160
|
-
$default reduce using rule 6 (fact) [after shift]
|
161
|
-
|
162
|
-
----------
|
163
|
-
|
164
|
-
<<'----------',
|
165
|
-
I005 =
|
166
|
-
( 2) stmts : stmts expr EOL _
|
167
|
-
|
168
|
-
|
169
|
-
$default reduce using rule 2 (stmts) [after shift]
|
170
|
-
|
171
|
-
----------
|
172
|
-
|
173
|
-
<<'----------',
|
174
|
-
I006 =
|
175
|
-
( 3) expr : expr '+' _ __expr_0_2__ fact
|
176
|
-
|
177
|
-
|
178
|
-
$default reduce using rule 5 (__expr_0_2__) [after shift]
|
179
|
-
|
180
|
-
----------
|
181
|
-
|
182
|
-
<<'----------',
|
183
|
-
I007 =
|
184
|
-
( 3) expr : expr '+' __expr_0_2__ _ fact
|
185
|
-
|
186
|
-
ID shift, and goto to state 4
|
187
|
-
|
188
|
-
|
189
|
-
----------
|
190
|
-
|
191
|
-
<<'----------',
|
192
|
-
I008 =
|
193
|
-
( 3) expr : expr '+' __expr_0_2__ fact _
|
194
|
-
|
195
|
-
|
196
|
-
$default reduce using rule 3 (expr) [after shift]
|
197
|
-
|
198
|
-
----------
|
199
|
-
]
|
200
|
-
|
201
|
-
|
202
|
-
Tables = [ reduce_table, nparams, action_table,
|
203
|
-
defred_table, defred_after_shift_table, goto_table,
|
204
|
-
t2i, i2t, nt2i, i2nt ]
|
205
|
-
|
206
|
-
def self.createDecoratedParser
|
207
|
-
D4StatefulLexerTest2::StatefulLexer.new(D4StatefulLexerTest2::NVAction.new(StatefulLexerTest2.new()))
|
208
|
-
end
|
209
|
-
|
210
|
-
### Inner Code
|
211
|
-
|
212
|
-
def lex_START(&block)
|
213
|
-
case @line
|
214
|
-
|
215
|
-
when /\A[ \t]+/
|
216
|
-
@oldline = @line; @line = $'
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
when /\A\n/
|
221
|
-
@oldline = @line; @line = $'
|
222
|
-
yield token(:EOL, $&)
|
223
|
-
|
224
|
-
|
225
|
-
when /\A\w+/
|
226
|
-
@oldline = @line; @line = $'
|
227
|
-
yield token(:ID, $&)
|
228
|
-
|
229
|
-
|
230
|
-
when /\A./
|
231
|
-
@oldline = @line; @line = $'
|
232
|
-
yield token($&, $&)
|
233
|
-
|
234
|
-
|
235
|
-
else
|
236
|
-
raise RuntimeError, "must not happen #{@line}"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def lex_LCONT(&block)
|
241
|
-
case @line
|
242
|
-
|
243
|
-
when /\A\r?\n/
|
244
|
-
@oldline = @line; @line = $'
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
else
|
249
|
-
lex_START(&block)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
attr_accessor :lex_state, :lex_context
|
254
|
-
def lex(&block)
|
255
|
-
@lex_state ||= :START
|
256
|
-
@lex_context ||= {}
|
257
|
-
begin
|
258
|
-
until @line.empty?
|
259
|
-
self.send "lex_#{@lex_state}", &block
|
260
|
-
end
|
261
|
-
end while @line0 = @line = getline
|
262
|
-
yield nil, nil
|
263
|
-
end
|
264
|
-
|
265
|
-
end
|
266
|
-
|
267
|
-
### Outer Code
|
268
|
-
|
269
|
-
class D4StatefulLexerTest2::StatefulLexer < Depager::LALR::Action #:nodoc:all
|
270
|
-
include Depager::DecoratorUtils
|
271
|
-
|
272
|
-
on_reduce = [
|
273
|
-
nil,
|
274
|
-
nil,
|
275
|
-
nil,
|
276
|
-
nil,
|
277
|
-
nil,
|
278
|
-
:_lex_expr_0_2,
|
279
|
-
:_lex_fact_0_1,
|
280
|
-
|
281
|
-
]
|
282
|
-
Tables = [on_reduce]
|
283
|
-
def initialize inside
|
284
|
-
super inside, 'StatefulLexer'
|
285
|
-
@on_reduce, = self.class::Tables
|
286
|
-
init_parser
|
287
|
-
end
|
288
|
-
|
289
|
-
|
290
|
-
def _lex_expr_0_2 val
|
291
|
-
@basis.lex_state = :LCONT
|
292
|
-
end
|
293
|
-
|
294
|
-
def _lex_fact_0_1 val
|
295
|
-
@basis.lex_state = :START
|
296
|
-
end
|
297
|
-
|
298
|
-
def afterError
|
299
|
-
warn "StatefulLex: lex_state==#{@basis.lex_state}" if $MP_DEBUG
|
300
|
-
end
|
301
|
-
|
302
|
-
end
|
303
|
-
|
304
|
-
class D4StatefulLexerTest2::NVAction < Depager::LALR::Action #:nodoc:all
|
305
|
-
include Depager::DecoratorUtils
|
306
|
-
|
307
|
-
on_reduce = [
|
308
|
-
nil,
|
309
|
-
nil,
|
310
|
-
:_act_1,
|
311
|
-
:_act_2,
|
312
|
-
:_act_3,
|
313
|
-
nil,
|
314
|
-
:_act_5,
|
315
|
-
|
316
|
-
]
|
317
|
-
Tables = [on_reduce]
|
318
|
-
def initialize inside
|
319
|
-
super inside, 'NVAction'
|
320
|
-
@on_reduce, = self.class::Tables
|
321
|
-
init_parser
|
322
|
-
end
|
323
|
-
|
324
|
-
|
325
|
-
module_eval <<-'.,.,12274580401395.,.,', 'slex_test/ljoin.slex.dr', 19
|
326
|
-
def _act_1 val
|
327
|
-
_stmts, _expr, _EOL, = *val
|
328
|
-
warn "#{_expr} <EOL>:#{@lexstate}"
|
329
|
-
|
330
|
-
end
|
331
|
-
.,.,12274580401395.,.,
|
332
|
-
|
333
|
-
module_eval <<-'.,.,1227458040182.,.,', 'slex_test/ljoin.slex.dr', 23
|
334
|
-
def _act_2 val
|
335
|
-
_expr, _, ___expr_0_2__, _fact, = *val
|
336
|
-
"#{_expr} + #{_fact}"
|
337
|
-
|
338
|
-
end
|
339
|
-
.,.,1227458040182.,.,
|
340
|
-
|
341
|
-
module_eval <<-'.,.,122745804061311.,.,', 'slex_test/ljoin.slex.dr', 25
|
342
|
-
def _act_3 val
|
343
|
-
_fact, = *val
|
344
|
-
_fact
|
345
|
-
|
346
|
-
end
|
347
|
-
.,.,122745804061311.,.,
|
348
|
-
|
349
|
-
module_eval <<-'.,.,122745804033944.,.,', 'slex_test/ljoin.slex.dr', 29
|
350
|
-
def _act_5 val
|
351
|
-
_ID, = *val
|
352
|
-
_ID.value
|
353
|
-
|
354
|
-
end
|
355
|
-
.,.,122745804033944.,.,
|
356
|
-
|
357
|
-
end
|
358
|
-
|
359
|
-
|
360
|
-
def createDecoratedStatefulLexerTest2
|
361
|
-
D4StatefulLexerTest2::StatefulLexer.new(D4StatefulLexerTest2::NVAction.new(StatefulLexerTest2.new()))
|
362
|
-
end
|
363
|
-
|
364
|
-
### main
|
365
|
-
if __FILE__ == $0
|
366
|
-
### Main Code
|
367
|
-
p = createDecoratedStatefulLexerTest2
|
368
|
-
p.parse(STDIN)
|
369
|
-
|
370
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
class ASTBuilderExtension
|
2
|
-
TMPL_NODE_BASE = <<EOS
|
3
|
-
class Node
|
4
|
-
attr_accessor :lineno
|
5
|
-
attr_accessor <%= _opt_attr.map{|i| ":\#{i}" }.join(', ') %>
|
6
|
-
<%= ini %>
|
7
|
-
def self.[] lineno, *args
|
8
|
-
self.new lineno, *args
|
9
|
-
end
|
10
|
-
def accept v
|
11
|
-
end
|
12
|
-
end
|
13
|
-
class NodeList < Node
|
14
|
-
attr_accessor :lineno
|
15
|
-
def initialize(lineno, lst=[])
|
16
|
-
@lineno = lineno
|
17
|
-
@lst = lst.to_a.select{|i| ! i.is_a?(NilNode)}
|
18
|
-
end
|
19
|
-
<% _opt_attr.each do |i| %>
|
20
|
-
def all_<%= i %>
|
21
|
-
@lst.map{|i| i.<%= i %>}
|
22
|
-
end
|
23
|
-
<% end %>
|
24
|
-
def size
|
25
|
-
@lst.size
|
26
|
-
end
|
27
|
-
alias length size
|
28
|
-
def push(i)
|
29
|
-
@lst.push i unless i.is_a? NilNode
|
30
|
-
self
|
31
|
-
end
|
32
|
-
def concat(i)
|
33
|
-
@lst.concat i
|
34
|
-
self
|
35
|
-
end
|
36
|
-
def to_ary()
|
37
|
-
@lst
|
38
|
-
end
|
39
|
-
alias to_a to_ary
|
40
|
-
alias list to_ary
|
41
|
-
def accept(v)
|
42
|
-
@lst.each{|i| i.accept(v) }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
class NilNode
|
46
|
-
attr_accessor :lineno
|
47
|
-
attr_accessor <%= _opt_attr.map{|i| ":\#{i}" }.join(', ') %>
|
48
|
-
def initialize(lineno, *args)
|
49
|
-
@lineno = lineno
|
50
|
-
end
|
51
|
-
def accept v
|
52
|
-
end
|
53
|
-
end
|
54
|
-
EOS
|
55
|
-
|
56
|
-
TMPL_NODE = <<EOS
|
57
|
-
class Node_<%= name %> < Node
|
58
|
-
attr_accessor <%= nodes.map{|i| ":\#{i}" }.join(', ') %>
|
59
|
-
attr_accessor <%= attrs.map{|i| ":\#{i}" }.join(', ') %>
|
60
|
-
def initialize <%= nodes.unshift('lineno').join(', ') %>
|
61
|
-
super()
|
62
|
-
@lineno = lineno
|
63
|
-
<%= nodes.inject(''){|r,i| r << " @\#{i} = \#{i}\n"} %>
|
64
|
-
end
|
65
|
-
def accept v
|
66
|
-
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
67
|
-
<%= accept %>
|
68
|
-
v.visit_Node_<%= name %>(self)
|
69
|
-
self
|
70
|
-
end
|
71
|
-
end
|
72
|
-
EOS
|
73
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'depager/parser.rb'
|
2
|
-
|
3
|
-
class ActionExtension #:nodoc:all
|
4
|
-
include Depager::ExtensionUtils
|
5
|
-
def initialize
|
6
|
-
@line0 = @line = @oldline = ''
|
7
|
-
@optouter = []
|
8
|
-
@on_reduce = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def modify_action_code code
|
12
|
-
return code, 0
|
13
|
-
end
|
14
|
-
|
15
|
-
def pre_rule_list
|
16
|
-
if g_parser.line0 =~ /^%ACTION\{\s*$/
|
17
|
-
while line = getline
|
18
|
-
break if line =~ /^%\}\s*$/
|
19
|
-
@optouter.push line
|
20
|
-
end
|
21
|
-
g_parser.update_context ''
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def post_rhs
|
26
|
-
if g_parser.line =~ /\s*\{/
|
27
|
-
@line0, @line = g_parser.line0, g_parser.line
|
28
|
-
lineno = g_parser.lineno
|
29
|
-
code, d = modify_action_code(parse_action)
|
30
|
-
@optouter <<
|
31
|
-
gen_defm_code("_act_#{nrules} val", code, lineno, d)
|
32
|
-
g_parser.update_context @line
|
33
|
-
@on_reduce[nrules] = ":_act_#{nrules}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def post_rule_list
|
38
|
-
g_parser.optouter <<
|
39
|
-
gen_action_decorator_code(
|
40
|
-
target_name, paramkey,
|
41
|
-
@on_reduce, @optouter, g_parser.mixin)
|
42
|
-
end
|
43
|
-
end
|