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::StatefulLexerExtension - Depager Extension (master)
|
5
3
|
###
|
@@ -11,6 +9,7 @@ module Depager ; end
|
|
11
9
|
class Depager::StatefulLexerExtension < Depager::Extension
|
12
10
|
|
13
11
|
def initialize
|
12
|
+
super
|
14
13
|
@master = self
|
15
14
|
@slaves = []
|
16
15
|
end
|
@@ -18,15 +17,14 @@ class Depager::StatefulLexerExtension < 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[:pre_rhs].push [@slaves
|
25
|
-
|
26
|
-
g_parser.hooks[:post_symbol].push [@slaves[1], :do_parse]
|
20
|
+
@slaves << Depager::StatefulLexerExtension::PreRuleList0::Parser.new(g_parser, self)
|
21
|
+
g_parser.hooks[:pre_rule_list].push [@slaves.last, :do_parse]
|
22
|
+
@slaves << Depager::StatefulLexerExtension::PreRhsPostSymbol1::Parser.new(g_parser, self)
|
23
|
+
g_parser.hooks[:pre_rhs].push [@slaves.last, :do_parse]
|
24
|
+
g_parser.hooks[:post_symbol].push [@slaves.last, :do_parse]
|
27
25
|
end
|
28
26
|
|
29
|
-
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/
|
27
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 7
|
30
28
|
attr_accessor :ins, :code, :optval
|
31
29
|
def init_extension
|
32
30
|
@ins = []
|
@@ -36,11 +34,11 @@ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 8
|
|
36
34
|
end
|
37
35
|
|
38
36
|
def term_extension
|
39
|
-
@action_code <<
|
37
|
+
@action_code << <<-CODE
|
40
38
|
def after_error
|
41
39
|
warn "StatefulLex: lex_state==\#{@basis.lex_state}" if Depager.debug_mode?
|
42
40
|
end
|
43
|
-
|
41
|
+
CODE
|
44
42
|
g_parser.outer_code <<
|
45
43
|
generate_action_decorator_code(@on_reduce, @action_code)
|
46
44
|
end
|
@@ -75,11 +73,11 @@ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 8
|
|
75
73
|
else
|
76
74
|
end
|
77
75
|
end
|
78
|
-
@action_code <<
|
76
|
+
@action_code << <<-CODE
|
79
77
|
def #{m_name} val
|
80
78
|
#{codes.join("\n ")}
|
81
79
|
end
|
82
|
-
|
80
|
+
CODE
|
83
81
|
end
|
84
82
|
@ins.clear
|
85
83
|
end
|
@@ -97,16 +95,15 @@ DEPAGER_EXPANDED_CODE
|
|
97
95
|
end
|
98
96
|
|
99
97
|
###
|
100
|
-
### Depager::StatefulLexerExtension::
|
98
|
+
### Depager::StatefulLexerExtension::PreRuleList0 - Part of Depager Extension (slave)
|
101
99
|
###
|
102
100
|
|
103
|
-
module Depager::StatefulLexerExtension::
|
101
|
+
module Depager::StatefulLexerExtension::PreRuleList0 #:nodoc:all
|
104
102
|
class Parser < Depager::LALR::Basis #:nodoc:all
|
105
103
|
include Depager::Utils::ExtensionSlaveMethods
|
106
|
-
|
107
104
|
|
108
105
|
### Reduce Table
|
109
|
-
|
106
|
+
REDUCE_TABLE = [
|
110
107
|
[ -1, 1 ],
|
111
108
|
[ 0, 1 ],
|
112
109
|
[ 1, 0 ],
|
@@ -122,8 +119,10 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
122
119
|
[ 6, 1 ],
|
123
120
|
[ 6, 3 ],
|
124
121
|
]
|
122
|
+
def reduce_table; REDUCE_TABLE; end
|
123
|
+
|
125
124
|
### Term to Int
|
126
|
-
|
125
|
+
TERM_TO_INT = {
|
127
126
|
nil => 0,
|
128
127
|
false => 1,
|
129
128
|
"<" => 2,
|
@@ -135,8 +134,10 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
135
134
|
:LEX => 8,
|
136
135
|
"," => 9,
|
137
136
|
}
|
137
|
+
def term_to_int; TERM_TO_INT; end
|
138
|
+
|
138
139
|
### Int to Term
|
139
|
-
|
140
|
+
INT_TO_TERM = [
|
140
141
|
nil,
|
141
142
|
false,
|
142
143
|
"<",
|
@@ -148,8 +149,10 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
148
149
|
:LEX,
|
149
150
|
",",
|
150
151
|
]
|
152
|
+
def int_to_term; INT_TO_TERM; end
|
153
|
+
|
151
154
|
### Action Table
|
152
|
-
|
155
|
+
ACTION_TABLE = [
|
153
156
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
154
157
|
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
155
158
|
[ nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, ],
|
@@ -171,8 +174,10 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
171
174
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
172
175
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
173
176
|
]
|
177
|
+
def action_table; ACTION_TABLE; end
|
178
|
+
|
174
179
|
### Default Reduce Table
|
175
|
-
|
180
|
+
DEFRED_TABLE = [
|
176
181
|
-2,
|
177
182
|
nil,
|
178
183
|
-1,
|
@@ -194,7 +199,9 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
194
199
|
-4,
|
195
200
|
-6,
|
196
201
|
]
|
197
|
-
|
202
|
+
def defred_table; DEFRED_TABLE; end
|
203
|
+
|
204
|
+
DEFRED_AFTER_SHIFT_TABLE = [
|
198
205
|
-2,
|
199
206
|
nil,
|
200
207
|
nil,
|
@@ -216,30 +223,36 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
216
223
|
-4,
|
217
224
|
-6,
|
218
225
|
]
|
226
|
+
def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end
|
227
|
+
|
219
228
|
### Nonterm to Int
|
220
|
-
|
221
|
-
:start => 0,
|
222
|
-
:mode_list => 1,
|
223
|
-
:mode => 2,
|
224
|
-
:lexactlist => 3,
|
225
|
-
:opt_super => 4,
|
226
|
-
:lexact => 5,
|
227
|
-
:lexlist => 6,
|
228
|
-
:opt_noskip => 7,
|
229
|
+
NONTERM_TO_INT = {
|
230
|
+
:start => 0,
|
231
|
+
:mode_list => 1,
|
232
|
+
:mode => 2,
|
233
|
+
:lexactlist => 3,
|
234
|
+
:opt_super => 4,
|
235
|
+
:lexact => 5,
|
236
|
+
:lexlist => 6,
|
237
|
+
:opt_noskip => 7,
|
229
238
|
}
|
239
|
+
def nonterm_to_int; NONTERM_TO_INT; end
|
240
|
+
|
230
241
|
### Int to Nonterm
|
231
|
-
|
232
|
-
:start,
|
233
|
-
:mode_list,
|
234
|
-
:mode,
|
235
|
-
:lexactlist,
|
236
|
-
:opt_super,
|
237
|
-
:lexact,
|
238
|
-
:lexlist,
|
239
|
-
:opt_noskip,
|
242
|
+
INT_TO_NONTERM = [
|
243
|
+
:start,
|
244
|
+
:mode_list,
|
245
|
+
:mode,
|
246
|
+
:lexactlist,
|
247
|
+
:opt_super,
|
248
|
+
:lexact,
|
249
|
+
:lexlist,
|
250
|
+
:opt_noskip,
|
240
251
|
]
|
252
|
+
def int_to_nonterm; INT_TO_NONTERM; end
|
253
|
+
|
241
254
|
### Goto Table
|
242
|
-
|
255
|
+
GOTO_TABLE = [
|
243
256
|
[ 1, 2, nil, nil, nil, nil, nil, nil, ],
|
244
257
|
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
245
258
|
[ nil, nil, 3, nil, nil, nil, nil, nil, ],
|
@@ -261,10 +274,7 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
261
274
|
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
262
275
|
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
263
276
|
]
|
264
|
-
|
265
|
-
Tables = [ reduce_table, action_table,
|
266
|
-
defred_table, defred_after_shift_table, goto_table,
|
267
|
-
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
277
|
+
def goto_table; GOTO_TABLE; end
|
268
278
|
|
269
279
|
def initialize g_parser, master
|
270
280
|
super()
|
@@ -289,67 +299,57 @@ module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
289
299
|
"%LEX{ ... } / Depager::StatefulLexerExtension"
|
290
300
|
end
|
291
301
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
case @line
|
297
|
-
|
302
|
+
def lex
|
303
|
+
begin
|
304
|
+
until @line.empty?
|
305
|
+
case @line
|
298
306
|
when /\A\s+/, /\A#.*\Z/
|
299
307
|
@line = $'
|
300
308
|
|
301
309
|
|
302
|
-
|
303
310
|
when /\A[A-Z]+/
|
304
311
|
@line = $'
|
305
312
|
yield token(:ID, $&)
|
306
313
|
|
307
|
-
|
308
314
|
when /\A\%\}\s*\Z/
|
309
315
|
@line = $'
|
310
316
|
yield nil,nil
|
311
317
|
|
312
|
-
|
313
318
|
when /\A\/(([^\/\\]+|\\.)*)\//
|
314
319
|
@line = $'
|
315
320
|
yield token(:LEX, "/\\A#{$1}/")
|
316
321
|
|
317
|
-
|
318
322
|
when /\A'([^'\\]+|\\.)*'/, /\A"([^"\\]+|\\.)*"/
|
319
323
|
@line = $'
|
320
324
|
|
321
325
|
yield token(:LEX, "/\\A#{Regexp.escape($1).gsub('/', '\/')}/")
|
322
326
|
|
323
|
-
|
324
327
|
when /\A\{/
|
325
328
|
#
|
326
329
|
|
327
330
|
lineno = file.lineno
|
328
331
|
yield token(:ACTION, parse_block, lineno)
|
329
332
|
|
330
|
-
|
331
333
|
when /\A./
|
332
334
|
@line = $'
|
333
335
|
yield token($&, $&)
|
334
336
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
end
|
343
|
-
|
344
|
-
end
|
337
|
+
|
338
|
+
else
|
339
|
+
raise RuntimeError, "must not happen #{@line}"
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end while @original_line = @line = file.gets
|
343
|
+
yield nil, nil
|
345
344
|
end
|
346
345
|
|
346
|
+
end
|
347
|
+
end
|
347
348
|
|
348
|
-
class Depager::StatefulLexerExtension::
|
349
|
+
class Depager::StatefulLexerExtension::PreRuleList0::Action < Depager::LALR::Action #:nodoc:all
|
349
350
|
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
350
|
-
|
351
|
-
|
352
|
-
nil,
|
351
|
+
ON_REDUCE = [
|
352
|
+
nil,
|
353
353
|
:_act_1,
|
354
354
|
:_act_2,
|
355
355
|
:_act_3,
|
@@ -364,13 +364,12 @@ class Depager::StatefulLexerExtension::Slave_pre_rule_list::Action < Depager::LA
|
|
364
364
|
:_act_12,
|
365
365
|
:_act_13,
|
366
366
|
|
367
|
-
|
368
|
-
|
367
|
+
]
|
368
|
+
def on_reduce; ON_REDUCE; end
|
369
369
|
|
370
|
-
|
371
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 97
|
370
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 96
|
372
371
|
def _act_1 val
|
373
|
-
_mode_list, = *val
|
372
|
+
_mode_list, = *val
|
374
373
|
|
375
374
|
ll = ''
|
376
375
|
_mode_list.each do |m, s, l|
|
@@ -379,7 +378,7 @@ def _act_1 val
|
|
379
378
|
else
|
380
379
|
'raise RuntimeError, "must not happen #{@line}"'
|
381
380
|
end
|
382
|
-
ll <<
|
381
|
+
ll << <<-CODE
|
383
382
|
def lex_#{m}(&block)
|
384
383
|
case @line
|
385
384
|
#{l}
|
@@ -387,9 +386,9 @@ def _act_1 val
|
|
387
386
|
#{else_code}
|
388
387
|
end
|
389
388
|
end
|
390
|
-
|
389
|
+
CODE
|
391
390
|
end
|
392
|
-
g_parser.inner_code << ll <<
|
391
|
+
g_parser.inner_code << ll << <<-CODE
|
393
392
|
attr_accessor :lex_state, :lex_context
|
394
393
|
def lex(&block)
|
395
394
|
@lex_state ||= :START
|
@@ -401,123 +400,113 @@ def _act_1 val
|
|
401
400
|
end while @original_line = @line = file.gets
|
402
401
|
yield nil, nil
|
403
402
|
end
|
404
|
-
|
403
|
+
CODE
|
405
404
|
|
406
405
|
end
|
407
406
|
DEPAGER_EXPANDED_CODE
|
408
|
-
|
409
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 131
|
407
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 130
|
410
408
|
def _act_2 val
|
409
|
+
# empty rule
|
411
410
|
[ ]
|
412
411
|
|
413
412
|
end
|
414
413
|
DEPAGER_EXPANDED_CODE
|
415
|
-
|
416
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 132
|
414
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 131
|
417
415
|
def _act_3 val
|
418
|
-
_mode_list, _mode, _lexactlist, = *val
|
416
|
+
_mode_list, _mode, _lexactlist, = *val
|
419
417
|
_mode_list << [_mode[0], _mode[1], _lexactlist]
|
420
418
|
|
421
419
|
end
|
422
420
|
DEPAGER_EXPANDED_CODE
|
423
|
-
|
424
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 135
|
421
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 134
|
425
422
|
def _act_4 val
|
426
|
-
_, _ID, _opt_super, _, = *val
|
423
|
+
_, _ID, _opt_super, _, = *val
|
427
424
|
[ _ID.value, _opt_super ]
|
428
425
|
|
429
426
|
end
|
430
427
|
DEPAGER_EXPANDED_CODE
|
431
|
-
|
432
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 138
|
428
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 137
|
433
429
|
def _act_5 val
|
430
|
+
# empty rule
|
434
431
|
nil
|
435
432
|
|
436
433
|
end
|
437
434
|
DEPAGER_EXPANDED_CODE
|
438
|
-
|
439
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 139
|
435
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 138
|
440
436
|
def _act_6 val
|
441
|
-
_, _ID, = *val
|
437
|
+
_, _ID, = *val
|
442
438
|
_ID.value
|
443
439
|
|
444
440
|
end
|
445
441
|
DEPAGER_EXPANDED_CODE
|
446
|
-
|
447
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 142
|
442
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 141
|
448
443
|
def _act_7 val
|
449
|
-
_lexact, = *val
|
444
|
+
_lexact, = *val
|
450
445
|
_lexact
|
451
446
|
|
452
447
|
end
|
453
448
|
DEPAGER_EXPANDED_CODE
|
454
|
-
|
455
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 143
|
449
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 142
|
456
450
|
def _act_8 val
|
457
|
-
_lexactlist, _lexact, = *val
|
451
|
+
_lexactlist, _lexact, = *val
|
458
452
|
_lexactlist << _lexact
|
459
453
|
|
460
454
|
end
|
461
455
|
DEPAGER_EXPANDED_CODE
|
462
|
-
|
463
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 147
|
456
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 146
|
464
457
|
def _act_9 val
|
465
|
-
_lexlist, _opt_noskip, _ACTION, = *val
|
458
|
+
_lexlist, _opt_noskip, _ACTION, = *val
|
466
459
|
|
467
|
-
|
460
|
+
<<-CODE
|
468
461
|
when #{_lexlist.join(', ')}
|
469
462
|
#{ _opt_noskip ? '#' : "@line = $'" }
|
470
463
|
#{ _ACTION.value }
|
471
|
-
|
464
|
+
CODE
|
472
465
|
|
473
466
|
end
|
474
467
|
DEPAGER_EXPANDED_CODE
|
475
|
-
|
476
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 156
|
468
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 155
|
477
469
|
def _act_10 val
|
470
|
+
# empty rule
|
478
471
|
false
|
479
472
|
|
480
473
|
end
|
481
474
|
DEPAGER_EXPANDED_CODE
|
482
|
-
|
483
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 157
|
475
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 156
|
484
476
|
def _act_11 val
|
485
|
-
_, = *val
|
477
|
+
_, = *val
|
486
478
|
true
|
487
479
|
|
488
480
|
end
|
489
481
|
DEPAGER_EXPANDED_CODE
|
490
|
-
|
491
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 160
|
482
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 159
|
492
483
|
def _act_12 val
|
493
|
-
_LEX, = *val
|
484
|
+
_LEX, = *val
|
494
485
|
[ _LEX.value ]
|
495
486
|
|
496
487
|
end
|
497
488
|
DEPAGER_EXPANDED_CODE
|
498
|
-
|
499
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 161
|
489
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 160
|
500
490
|
def _act_13 val
|
501
|
-
_lexlist, _, _LEX, = *val
|
491
|
+
_lexlist, _, _LEX, = *val
|
502
492
|
_lexlist.push _LEX.value
|
503
493
|
|
504
494
|
end
|
505
495
|
DEPAGER_EXPANDED_CODE
|
506
|
-
|
507
|
-
|
496
|
+
|
497
|
+
|
508
498
|
end
|
509
|
-
|
499
|
+
|
510
500
|
###
|
511
|
-
### Depager::StatefulLexerExtension::
|
501
|
+
### Depager::StatefulLexerExtension::PreRhsPostSymbol1 - Part of Depager Extension (slave)
|
512
502
|
###
|
513
503
|
|
514
|
-
module Depager::StatefulLexerExtension::
|
504
|
+
module Depager::StatefulLexerExtension::PreRhsPostSymbol1 #:nodoc:all
|
515
505
|
class Parser < Depager::LALR::Basis #:nodoc:all
|
516
506
|
include Depager::Utils::ExtensionSlaveMethods
|
517
|
-
|
518
507
|
|
519
508
|
### Reduce Table
|
520
|
-
|
509
|
+
REDUCE_TABLE = [
|
521
510
|
[ -1, 1 ],
|
522
511
|
[ 0, 3 ],
|
523
512
|
[ 0, 4 ],
|
@@ -527,8 +516,10 @@ module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
|
527
516
|
[ 2, 2 ],
|
528
517
|
[ 2, 2 ],
|
529
518
|
]
|
519
|
+
def reduce_table; REDUCE_TABLE; end
|
520
|
+
|
530
521
|
### Term to Int
|
531
|
-
|
522
|
+
TERM_TO_INT = {
|
532
523
|
nil => 0,
|
533
524
|
false => 1,
|
534
525
|
"[" => 2,
|
@@ -539,8 +530,10 @@ module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
|
539
530
|
"+" => 7,
|
540
531
|
"-" => 8,
|
541
532
|
}
|
533
|
+
def term_to_int; TERM_TO_INT; end
|
534
|
+
|
542
535
|
### Int to Term
|
543
|
-
|
536
|
+
INT_TO_TERM = [
|
544
537
|
nil,
|
545
538
|
false,
|
546
539
|
"[",
|
@@ -551,26 +544,30 @@ module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
|
551
544
|
"+",
|
552
545
|
"-",
|
553
546
|
]
|
547
|
+
def int_to_term; INT_TO_TERM; end
|
548
|
+
|
554
549
|
### Action Table
|
555
|
-
|
550
|
+
ACTION_TABLE = [
|
556
551
|
[ nil, nil, 2, nil, nil, nil, nil, nil, nil, ],
|
557
552
|
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
558
553
|
[ nil, nil, nil, nil, nil, 5, nil, 6, 7, ],
|
559
|
-
[ nil, nil, nil, 8,
|
554
|
+
[ nil, nil, nil, 8, 9, 5, nil, 6, 7, ],
|
560
555
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
561
556
|
[ nil, nil, nil, nil, nil, nil, 11, nil, nil, ],
|
562
557
|
[ nil, nil, nil, nil, nil, nil, 12, nil, nil, ],
|
563
558
|
[ nil, nil, nil, nil, nil, nil, 13, nil, nil, ],
|
564
559
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
565
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
566
560
|
[ nil, nil, nil, 14, nil, nil, nil, nil, nil, ],
|
567
561
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
568
562
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
569
563
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
570
564
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
565
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
571
566
|
]
|
567
|
+
def action_table; ACTION_TABLE; end
|
568
|
+
|
572
569
|
### Default Reduce Table
|
573
|
-
|
570
|
+
DEFRED_TABLE = [
|
574
571
|
nil,
|
575
572
|
nil,
|
576
573
|
nil,
|
@@ -580,14 +577,16 @@ module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
|
580
577
|
nil,
|
581
578
|
nil,
|
582
579
|
-1,
|
583
|
-
-4,
|
584
580
|
nil,
|
581
|
+
-4,
|
585
582
|
-5,
|
586
583
|
-6,
|
587
584
|
-7,
|
588
585
|
-2,
|
589
586
|
]
|
590
|
-
|
587
|
+
def defred_table; DEFRED_TABLE; end
|
588
|
+
|
589
|
+
DEFRED_AFTER_SHIFT_TABLE = [
|
591
590
|
nil,
|
592
591
|
nil,
|
593
592
|
nil,
|
@@ -597,31 +596,37 @@ module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
|
597
596
|
nil,
|
598
597
|
nil,
|
599
598
|
-1,
|
600
|
-
-4,
|
601
599
|
nil,
|
600
|
+
-4,
|
602
601
|
-5,
|
603
602
|
-6,
|
604
603
|
-7,
|
605
604
|
-2,
|
606
605
|
]
|
606
|
+
def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end
|
607
|
+
|
607
608
|
### Nonterm to Int
|
608
|
-
|
609
|
-
:start => 0,
|
610
|
-
:option_list => 1,
|
611
|
-
:option => 2,
|
609
|
+
NONTERM_TO_INT = {
|
610
|
+
:start => 0,
|
611
|
+
:option_list => 1,
|
612
|
+
:option => 2,
|
612
613
|
}
|
614
|
+
def nonterm_to_int; NONTERM_TO_INT; end
|
615
|
+
|
613
616
|
### Int to Nonterm
|
614
|
-
|
615
|
-
:start,
|
616
|
-
:option_list,
|
617
|
-
:option,
|
617
|
+
INT_TO_NONTERM = [
|
618
|
+
:start,
|
619
|
+
:option_list,
|
620
|
+
:option,
|
618
621
|
]
|
622
|
+
def int_to_nonterm; INT_TO_NONTERM; end
|
623
|
+
|
619
624
|
### Goto Table
|
620
|
-
|
625
|
+
GOTO_TABLE = [
|
621
626
|
[ 1, nil, nil, ],
|
622
627
|
[ nil, nil, nil, ],
|
623
628
|
[ nil, 3, 4, ],
|
624
|
-
[ nil, nil,
|
629
|
+
[ nil, nil, 10, ],
|
625
630
|
[ nil, nil, nil, ],
|
626
631
|
[ nil, nil, nil, ],
|
627
632
|
[ nil, nil, nil, ],
|
@@ -634,10 +639,7 @@ module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
|
634
639
|
[ nil, nil, nil, ],
|
635
640
|
[ nil, nil, nil, ],
|
636
641
|
]
|
637
|
-
|
638
|
-
Tables = [ reduce_table, action_table,
|
639
|
-
defred_table, defred_after_shift_table, goto_table,
|
640
|
-
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
642
|
+
def goto_table; GOTO_TABLE; end
|
641
643
|
|
642
644
|
def initialize g_parser, master
|
643
645
|
super()
|
@@ -662,49 +664,42 @@ module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
|
662
664
|
"[> ...] / Depager::StatefulLexerExtension"
|
663
665
|
end
|
664
666
|
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
case @line
|
670
|
-
|
667
|
+
def lex
|
668
|
+
begin
|
669
|
+
until @line.empty?
|
670
|
+
case @line
|
671
671
|
when /\A\s+/
|
672
672
|
@line = $'
|
673
673
|
|
674
674
|
|
675
|
-
|
676
675
|
when /\A:[a-zA-Z_]+\??/
|
677
676
|
@line = $'
|
678
677
|
yield token(:SYMBOL, $&)
|
679
678
|
|
680
|
-
|
681
679
|
when /\A\]/
|
682
680
|
@line = $'
|
683
681
|
yield token($&, $&); @line = $'; yield nil, nil
|
684
682
|
|
685
|
-
|
686
683
|
when /\A./
|
687
684
|
@line = $'
|
688
685
|
yield token($&, $&)
|
689
686
|
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
end
|
698
|
-
|
699
|
-
end
|
687
|
+
|
688
|
+
else
|
689
|
+
raise RuntimeError, "must not happen #{@line}"
|
690
|
+
end
|
691
|
+
end
|
692
|
+
end while @original_line = @line = file.gets
|
693
|
+
yield nil, nil
|
700
694
|
end
|
701
695
|
|
696
|
+
end
|
697
|
+
end
|
702
698
|
|
703
|
-
class Depager::StatefulLexerExtension::
|
699
|
+
class Depager::StatefulLexerExtension::PreRhsPostSymbol1::Action < Depager::LALR::Action #:nodoc:all
|
704
700
|
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
705
|
-
|
706
|
-
|
707
|
-
nil,
|
701
|
+
ON_REDUCE = [
|
702
|
+
nil,
|
708
703
|
:_act_1,
|
709
704
|
:_act_2,
|
710
705
|
:_act_3,
|
@@ -713,68 +708,62 @@ class Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol::Action < Depa
|
|
713
708
|
:_act_6,
|
714
709
|
:_act_7,
|
715
710
|
|
716
|
-
|
717
|
-
|
711
|
+
]
|
712
|
+
def on_reduce; ON_REDUCE; end
|
718
713
|
|
719
|
-
|
720
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 181
|
714
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 180
|
721
715
|
def _act_1 val
|
722
|
-
_, _option_list, _, = *val
|
716
|
+
_, _option_list, _, = *val
|
723
717
|
|
724
718
|
master.ins.push [g_parser.rhs.size, _option_list, false]
|
725
719
|
|
726
720
|
end
|
727
721
|
DEPAGER_EXPANDED_CODE
|
728
|
-
|
729
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 185
|
722
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 184
|
730
723
|
def _act_2 val
|
731
|
-
_, _option_list, _, _, = *val
|
724
|
+
_, _option_list, _, _, = *val
|
732
725
|
|
733
726
|
master.ins.push [g_parser.rhs.size, _option_list, true]
|
734
727
|
|
735
728
|
end
|
736
729
|
DEPAGER_EXPANDED_CODE
|
737
|
-
|
738
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 191
|
730
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 190
|
739
731
|
def _act_3 val
|
740
|
-
_option, = *val
|
732
|
+
_option, = *val
|
741
733
|
[_option]
|
742
734
|
|
743
735
|
end
|
744
736
|
DEPAGER_EXPANDED_CODE
|
745
|
-
|
746
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 192
|
737
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 191
|
747
738
|
def _act_4 val
|
748
|
-
_option_list, _option, = *val
|
739
|
+
_option_list, _option, = *val
|
749
740
|
_option_list << _option
|
750
741
|
|
751
742
|
end
|
752
743
|
DEPAGER_EXPANDED_CODE
|
753
|
-
|
754
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 195
|
744
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 194
|
755
745
|
def _act_5 val
|
756
|
-
_, _SYMBOL, = *val
|
746
|
+
_, _SYMBOL, = *val
|
757
747
|
[:GOTO, _SYMBOL.value]
|
758
748
|
|
759
749
|
end
|
760
750
|
DEPAGER_EXPANDED_CODE
|
761
|
-
|
762
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 196
|
751
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 195
|
763
752
|
def _act_6 val
|
764
|
-
_, _SYMBOL, = *val
|
753
|
+
_, _SYMBOL, = *val
|
765
754
|
[:ADD, _SYMBOL.value]
|
766
755
|
|
767
756
|
end
|
768
757
|
DEPAGER_EXPANDED_CODE
|
769
|
-
|
770
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 197
|
758
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/slex.dr', 196
|
771
759
|
def _act_7 val
|
772
|
-
_, _SYMBOL, = *val
|
760
|
+
_, _SYMBOL, = *val
|
773
761
|
[:SUB, _SYMBOL.value]
|
774
762
|
|
775
763
|
end
|
776
764
|
DEPAGER_EXPANDED_CODE
|
777
|
-
|
778
|
-
|
765
|
+
|
766
|
+
|
779
767
|
end
|
780
|
-
|
768
|
+
|
769
|
+
|