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::CSTBuilderExtension - Depager Extension (master)
|
5
3
|
###
|
@@ -11,6 +9,7 @@ module Depager ; end
|
|
11
9
|
class Depager::CSTBuilderExtension < 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::CSTBuilderExtension < 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_lhs].push [@slaves
|
20
|
+
@slaves << Depager::CSTBuilderExtension::PreRuleList0::Parser.new(g_parser, self)
|
21
|
+
g_parser.hooks[:pre_rule_list].push [@slaves.last, :do_parse]
|
22
|
+
@slaves << Depager::CSTBuilderExtension::PostLhs1::Parser.new(g_parser, self)
|
23
|
+
g_parser.hooks[:post_lhs].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/cst.dr', 7
|
28
27
|
attr_accessor :action_code, :nodes_code, :visitor_code
|
29
28
|
def init_extension
|
30
29
|
@n = 0
|
@@ -61,7 +60,7 @@ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 8
|
|
61
60
|
end
|
62
61
|
attrc = nodes.map{|i| ":#{i}" }.join(', ')
|
63
62
|
inic = nodes.map{|i| "@#{i} = #{i}"}.join('; ')
|
64
|
-
@nodes_code <<
|
63
|
+
@nodes_code << <<-CODE
|
65
64
|
class Node_#{node_name} < Node_#{g_parser.lhs_name}
|
66
65
|
attr_accessor #{attrc}
|
67
66
|
def initialize #{nodes.join(', ')}
|
@@ -72,8 +71,11 @@ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 8
|
|
72
71
|
#{accept}
|
73
72
|
v.visit_Node_#{node_name}(self)
|
74
73
|
end
|
74
|
+
def children
|
75
|
+
[#{nodes.join(', ')}]
|
76
|
+
end
|
75
77
|
end
|
76
|
-
|
78
|
+
CODE
|
77
79
|
|
78
80
|
@visitor_code <<
|
79
81
|
expand_inline_code(modify_action_code(code), lineno, :wrap => "def visit_Node_#{node_name} node")
|
@@ -90,11 +92,11 @@ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 8
|
|
90
92
|
def term_extension
|
91
93
|
g_parser.outer_code << "module #{target_namespace}\n"
|
92
94
|
g_parser.outer_code << @nodes_code
|
93
|
-
g_parser.outer_code <<
|
95
|
+
g_parser.outer_code << <<-CODE
|
94
96
|
class Visitor
|
95
|
-
|
97
|
+
#{@visitor_code}
|
96
98
|
end
|
97
|
-
|
99
|
+
CODE
|
98
100
|
g_parser.outer_code << "end\n"
|
99
101
|
g_parser.outer_code << generate_action_decorator_code(@on_reduce, @action_code)
|
100
102
|
end
|
@@ -104,16 +106,15 @@ DEPAGER_EXPANDED_CODE
|
|
104
106
|
end
|
105
107
|
|
106
108
|
###
|
107
|
-
### Depager::CSTBuilderExtension::
|
109
|
+
### Depager::CSTBuilderExtension::PreRuleList0 - Part of Depager Extension (slave)
|
108
110
|
###
|
109
111
|
|
110
|
-
module Depager::CSTBuilderExtension::
|
112
|
+
module Depager::CSTBuilderExtension::PreRuleList0 #:nodoc:all
|
111
113
|
class Parser < Depager::LALR::Basis #:nodoc:all
|
112
114
|
include Depager::Utils::ExtensionSlaveMethods
|
113
|
-
|
114
115
|
|
115
116
|
### Reduce Table
|
116
|
-
|
117
|
+
REDUCE_TABLE = [
|
117
118
|
[ -1, 1 ],
|
118
119
|
[ 0, 2 ],
|
119
120
|
[ 1, 0 ],
|
@@ -121,24 +122,30 @@ module Depager::CSTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
121
122
|
[ 2, 0 ],
|
122
123
|
[ 2, 2 ],
|
123
124
|
]
|
125
|
+
def reduce_table; REDUCE_TABLE; end
|
126
|
+
|
124
127
|
### Term to Int
|
125
|
-
|
128
|
+
TERM_TO_INT = {
|
126
129
|
nil => 0,
|
127
130
|
false => 1,
|
128
131
|
:NODE => 2,
|
129
132
|
:ACTION => 3,
|
130
133
|
:VISITOR => 4,
|
131
134
|
}
|
135
|
+
def term_to_int; TERM_TO_INT; end
|
136
|
+
|
132
137
|
### Int to Term
|
133
|
-
|
138
|
+
INT_TO_TERM = [
|
134
139
|
nil,
|
135
140
|
false,
|
136
141
|
:NODE,
|
137
142
|
:ACTION,
|
138
143
|
:VISITOR,
|
139
144
|
]
|
145
|
+
def int_to_term; INT_TO_TERM; end
|
146
|
+
|
140
147
|
### Action Table
|
141
|
-
|
148
|
+
ACTION_TABLE = [
|
142
149
|
[ nil, nil, 3, nil, nil, ],
|
143
150
|
[ ACC, nil, nil, nil, nil, ],
|
144
151
|
[ nil, nil, nil, nil, 5, ],
|
@@ -148,8 +155,10 @@ module Depager::CSTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
148
155
|
[ nil, nil, nil, nil, nil, ],
|
149
156
|
[ nil, nil, nil, nil, nil, ],
|
150
157
|
]
|
158
|
+
def action_table; ACTION_TABLE; end
|
159
|
+
|
151
160
|
### Default Reduce Table
|
152
|
-
|
161
|
+
DEFRED_TABLE = [
|
153
162
|
-2,
|
154
163
|
nil,
|
155
164
|
-4,
|
@@ -159,7 +168,9 @@ module Depager::CSTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
159
168
|
-3,
|
160
169
|
-5,
|
161
170
|
]
|
162
|
-
|
171
|
+
def defred_table; DEFRED_TABLE; end
|
172
|
+
|
173
|
+
DEFRED_AFTER_SHIFT_TABLE = [
|
163
174
|
nil,
|
164
175
|
nil,
|
165
176
|
nil,
|
@@ -169,20 +180,26 @@ module Depager::CSTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
169
180
|
-3,
|
170
181
|
-5,
|
171
182
|
]
|
183
|
+
def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end
|
184
|
+
|
172
185
|
### Nonterm to Int
|
173
|
-
|
174
|
-
:start => 0,
|
175
|
-
:opt_node => 1,
|
176
|
-
:opt_visitor => 2,
|
186
|
+
NONTERM_TO_INT = {
|
187
|
+
:start => 0,
|
188
|
+
:opt_node => 1,
|
189
|
+
:opt_visitor => 2,
|
177
190
|
}
|
191
|
+
def nonterm_to_int; NONTERM_TO_INT; end
|
192
|
+
|
178
193
|
### Int to Nonterm
|
179
|
-
|
180
|
-
:start,
|
181
|
-
:opt_node,
|
182
|
-
:opt_visitor,
|
194
|
+
INT_TO_NONTERM = [
|
195
|
+
:start,
|
196
|
+
:opt_node,
|
197
|
+
:opt_visitor,
|
183
198
|
]
|
199
|
+
def int_to_nonterm; INT_TO_NONTERM; end
|
200
|
+
|
184
201
|
### Goto Table
|
185
|
-
|
202
|
+
GOTO_TABLE = [
|
186
203
|
[ 1, 2, nil, ],
|
187
204
|
[ nil, nil, nil, ],
|
188
205
|
[ nil, nil, 4, ],
|
@@ -192,10 +209,7 @@ module Depager::CSTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
192
209
|
[ nil, nil, nil, ],
|
193
210
|
[ nil, nil, nil, ],
|
194
211
|
]
|
195
|
-
|
196
|
-
Tables = [ reduce_table, action_table,
|
197
|
-
defred_table, defred_after_shift_table, goto_table,
|
198
|
-
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
212
|
+
def goto_table; GOTO_TABLE; end
|
199
213
|
|
200
214
|
def initialize g_parser, master
|
201
215
|
super()
|
@@ -220,124 +234,112 @@ module Depager::CSTBuilderExtension::Slave_pre_rule_list #:nodoc:all
|
|
220
234
|
"%CST{ ... } / Depager::CSTBuilderExtension"
|
221
235
|
end
|
222
236
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
case @line
|
228
|
-
|
237
|
+
def lex
|
238
|
+
begin
|
239
|
+
until @line.empty?
|
240
|
+
case @line
|
229
241
|
when /\A\s+/, /\A#.*/
|
230
242
|
@line = $'
|
231
243
|
|
232
244
|
|
233
|
-
|
234
245
|
when /\A%\}\s*\Z/
|
235
246
|
@line = $'
|
236
247
|
yield nil,nil
|
237
248
|
|
238
|
-
|
239
249
|
when /\ANode/
|
240
250
|
@line = $'
|
241
251
|
yield token(:NODE, $&)
|
242
252
|
|
243
|
-
|
244
253
|
when /\AVisitor/
|
245
254
|
@line = $'
|
246
255
|
yield token(:VISITOR, $&)
|
247
256
|
|
248
|
-
|
249
257
|
when /\A\{/
|
250
258
|
#
|
251
259
|
lineno = file.lineno; yield token(:ACTION, parse_block, lineno)
|
252
260
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
end
|
261
|
-
|
262
|
-
end
|
261
|
+
|
262
|
+
else
|
263
|
+
raise RuntimeError, "must not happen #{@line}"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end while @original_line = @line = file.gets
|
267
|
+
yield nil, nil
|
263
268
|
end
|
264
269
|
|
270
|
+
end
|
271
|
+
end
|
265
272
|
|
266
|
-
class Depager::CSTBuilderExtension::
|
273
|
+
class Depager::CSTBuilderExtension::PreRuleList0::Action < Depager::LALR::Action #:nodoc:all
|
267
274
|
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
268
|
-
|
269
|
-
|
270
|
-
nil,
|
275
|
+
ON_REDUCE = [
|
276
|
+
nil,
|
271
277
|
:_act_1,
|
272
278
|
:_act_2,
|
273
279
|
:_act_3,
|
274
280
|
:_act_4,
|
275
281
|
:_act_5,
|
276
282
|
|
277
|
-
|
278
|
-
|
283
|
+
]
|
284
|
+
def on_reduce; ON_REDUCE; end
|
279
285
|
|
280
|
-
|
281
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 95
|
286
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 97
|
282
287
|
def _act_1 val
|
283
|
-
_opt_node, _opt_visitor, = *val
|
288
|
+
_opt_node, _opt_visitor, = *val
|
284
289
|
|
285
|
-
master.nodes_code <<
|
290
|
+
master.nodes_code << <<-CODE
|
286
291
|
class Node
|
287
292
|
def accept
|
288
293
|
end
|
289
|
-
|
294
|
+
#{_opt_node}
|
290
295
|
end
|
291
|
-
|
296
|
+
CODE
|
292
297
|
master.visitor_code << _opt_visitor
|
293
298
|
|
294
299
|
end
|
295
300
|
DEPAGER_EXPANDED_CODE
|
296
|
-
|
297
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 107
|
301
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 109
|
298
302
|
def _act_2 val
|
303
|
+
# empty rule
|
299
304
|
''
|
300
305
|
|
301
306
|
end
|
302
307
|
DEPAGER_EXPANDED_CODE
|
303
|
-
|
304
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 108
|
308
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 110
|
305
309
|
def _act_3 val
|
306
|
-
_NODE, _ACTION, = *val
|
310
|
+
_NODE, _ACTION, = *val
|
307
311
|
_ACTION.value
|
308
312
|
|
309
313
|
end
|
310
314
|
DEPAGER_EXPANDED_CODE
|
311
|
-
|
312
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 111
|
315
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 113
|
313
316
|
def _act_4 val
|
317
|
+
# empty rule
|
314
318
|
''
|
315
319
|
|
316
320
|
end
|
317
321
|
DEPAGER_EXPANDED_CODE
|
318
|
-
|
319
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 112
|
322
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 114
|
320
323
|
def _act_5 val
|
321
|
-
_VISITOR, _ACTION, = *val
|
324
|
+
_VISITOR, _ACTION, = *val
|
322
325
|
_ACTION.value
|
323
326
|
|
324
327
|
end
|
325
328
|
DEPAGER_EXPANDED_CODE
|
326
|
-
|
327
|
-
|
329
|
+
|
330
|
+
|
328
331
|
end
|
329
|
-
|
332
|
+
|
330
333
|
###
|
331
|
-
### Depager::CSTBuilderExtension::
|
334
|
+
### Depager::CSTBuilderExtension::PostLhs1 - Part of Depager Extension (slave)
|
332
335
|
###
|
333
336
|
|
334
|
-
module Depager::CSTBuilderExtension::
|
337
|
+
module Depager::CSTBuilderExtension::PostLhs1 #:nodoc:all
|
335
338
|
class Parser < Depager::LALR::Basis #:nodoc:all
|
336
339
|
include Depager::Utils::ExtensionSlaveMethods
|
337
|
-
|
338
340
|
|
339
341
|
### Reduce Table
|
340
|
-
|
342
|
+
REDUCE_TABLE = [
|
341
343
|
[ -1, 1 ],
|
342
344
|
[ 0, 3 ],
|
343
345
|
[ 1, 1 ],
|
@@ -345,8 +347,10 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
345
347
|
[ 2, 1 ],
|
346
348
|
[ 2, 3 ],
|
347
349
|
]
|
350
|
+
def reduce_table; REDUCE_TABLE; end
|
351
|
+
|
348
352
|
### Term to Int
|
349
|
-
|
353
|
+
TERM_TO_INT = {
|
350
354
|
nil => 0,
|
351
355
|
false => 1,
|
352
356
|
"[" => 2,
|
@@ -356,8 +360,10 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
356
360
|
"=" => 6,
|
357
361
|
:LIT => 7,
|
358
362
|
}
|
363
|
+
def term_to_int; TERM_TO_INT; end
|
364
|
+
|
359
365
|
### Int to Term
|
360
|
-
|
366
|
+
INT_TO_TERM = [
|
361
367
|
nil,
|
362
368
|
false,
|
363
369
|
"[",
|
@@ -367,8 +373,10 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
367
373
|
"=",
|
368
374
|
:LIT,
|
369
375
|
]
|
376
|
+
def int_to_term; INT_TO_TERM; end
|
377
|
+
|
370
378
|
### Action Table
|
371
|
-
|
379
|
+
ACTION_TABLE = [
|
372
380
|
[ nil, nil, 2, nil, nil, nil, nil, nil, ],
|
373
381
|
[ ACC, nil, nil, nil, nil, nil, nil, nil, ],
|
374
382
|
[ nil, nil, nil, nil, nil, 5, nil, nil, ],
|
@@ -381,8 +389,10 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
381
389
|
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
382
390
|
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
383
391
|
]
|
392
|
+
def action_table; ACTION_TABLE; end
|
393
|
+
|
384
394
|
### Default Reduce Table
|
385
|
-
|
395
|
+
DEFRED_TABLE = [
|
386
396
|
nil,
|
387
397
|
nil,
|
388
398
|
nil,
|
@@ -395,7 +405,9 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
395
405
|
-3,
|
396
406
|
-5,
|
397
407
|
]
|
398
|
-
|
408
|
+
def defred_table; DEFRED_TABLE; end
|
409
|
+
|
410
|
+
DEFRED_AFTER_SHIFT_TABLE = [
|
399
411
|
nil,
|
400
412
|
nil,
|
401
413
|
nil,
|
@@ -408,20 +420,26 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
408
420
|
-3,
|
409
421
|
-5,
|
410
422
|
]
|
423
|
+
def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end
|
424
|
+
|
411
425
|
### Nonterm to Int
|
412
|
-
|
413
|
-
:start => 0,
|
414
|
-
:pair => 1,
|
415
|
-
:expr => 2,
|
426
|
+
NONTERM_TO_INT = {
|
427
|
+
:start => 0,
|
428
|
+
:pair => 1,
|
429
|
+
:expr => 2,
|
416
430
|
}
|
431
|
+
def nonterm_to_int; NONTERM_TO_INT; end
|
432
|
+
|
417
433
|
### Int to Nonterm
|
418
|
-
|
419
|
-
:start,
|
420
|
-
:pair,
|
421
|
-
:expr,
|
434
|
+
INT_TO_NONTERM = [
|
435
|
+
:start,
|
436
|
+
:pair,
|
437
|
+
:expr,
|
422
438
|
]
|
439
|
+
def int_to_nonterm; INT_TO_NONTERM; end
|
440
|
+
|
423
441
|
### Goto Table
|
424
|
-
|
442
|
+
GOTO_TABLE = [
|
425
443
|
[ 1, nil, nil, ],
|
426
444
|
[ nil, nil, nil, ],
|
427
445
|
[ nil, 3, 4, ],
|
@@ -434,10 +452,7 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
434
452
|
[ nil, nil, nil, ],
|
435
453
|
[ nil, nil, nil, ],
|
436
454
|
]
|
437
|
-
|
438
|
-
Tables = [ reduce_table, action_table,
|
439
|
-
defred_table, defred_after_shift_table, goto_table,
|
440
|
-
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
455
|
+
def goto_table; GOTO_TABLE; end
|
441
456
|
|
442
457
|
def initialize g_parser, master
|
443
458
|
super()
|
@@ -462,48 +477,43 @@ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
|
|
462
477
|
"[ ... ] / Depager::CSTBuilderExtension"
|
463
478
|
end
|
464
479
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
case @line
|
470
|
-
|
480
|
+
def lex
|
481
|
+
begin
|
482
|
+
until @line.empty?
|
483
|
+
case @line
|
471
484
|
when /\A\A\s+/
|
472
485
|
@line = $'
|
473
486
|
|
474
487
|
|
475
|
-
|
476
488
|
when /\A""/, /\A''/, /\A[0-9]+/, /\A\{\s*\}/, /\A\[\s*\]/, /\Anil/
|
477
489
|
@line = $'
|
478
490
|
yield token(:LIT, $&)
|
479
491
|
|
480
|
-
|
481
492
|
when /\A\A[a-z][a-z_]*/
|
482
493
|
@line = $'
|
483
494
|
yield token(:ID, $&)
|
484
495
|
|
485
|
-
|
486
496
|
when /\A\A(.)/
|
487
497
|
@line = $'
|
488
498
|
yield token($&, $&)
|
489
499
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
500
|
+
|
501
|
+
else
|
502
|
+
raise RuntimeError, "must not happen #{@line}"
|
503
|
+
end
|
504
|
+
end
|
505
|
+
end while @original_line = @line = file.gets
|
506
|
+
yield nil, nil
|
507
|
+
end
|
508
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 123
|
499
509
|
def do_default
|
500
|
-
master.nodes_code <<
|
510
|
+
master.nodes_code << <<-CODE
|
501
511
|
class Node_#{g_parser.lhs_name} < Node
|
502
512
|
def initialize
|
503
513
|
super()
|
504
514
|
end
|
505
515
|
end
|
506
|
-
|
516
|
+
CODE
|
507
517
|
end
|
508
518
|
|
509
519
|
DEPAGER_EXPANDED_CODE
|
@@ -511,25 +521,22 @@ DEPAGER_EXPANDED_CODE
|
|
511
521
|
end
|
512
522
|
end
|
513
523
|
|
514
|
-
|
515
|
-
class Depager::CSTBuilderExtension::Slave_post_lhs::Action < Depager::LALR::Action #:nodoc:all
|
524
|
+
class Depager::CSTBuilderExtension::PostLhs1::Action < Depager::LALR::Action #:nodoc:all
|
516
525
|
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
517
|
-
|
518
|
-
|
519
|
-
nil,
|
526
|
+
ON_REDUCE = [
|
527
|
+
nil,
|
520
528
|
:_act_1,
|
521
529
|
:_act_2,
|
522
530
|
:_act_3,
|
523
531
|
:_act_4,
|
524
532
|
:_act_5,
|
525
533
|
|
526
|
-
|
527
|
-
|
534
|
+
]
|
535
|
+
def on_reduce; ON_REDUCE; end
|
528
536
|
|
529
|
-
|
530
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 143
|
537
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 145
|
531
538
|
def _act_1 val
|
532
|
-
_, _pair, _, = *val
|
539
|
+
_, _pair, _, = *val
|
533
540
|
|
534
541
|
args = []; code = ''
|
535
542
|
_pair.each do |id, lit|
|
@@ -537,7 +544,7 @@ def _act_1 val
|
|
537
544
|
code << "#{id} = #{lit}; " if lit
|
538
545
|
end
|
539
546
|
attrc = args.map{|i| ":#{i}"}.join(', ')
|
540
|
-
master.nodes_code <<
|
547
|
+
master.nodes_code << <<-CODE
|
541
548
|
class Node_#{g_parser.lhs_name} < Node
|
542
549
|
attr_accessor #{attrc}
|
543
550
|
def initialize
|
@@ -545,43 +552,40 @@ def _act_1 val
|
|
545
552
|
#{code}
|
546
553
|
end
|
547
554
|
end
|
548
|
-
|
555
|
+
CODE
|
549
556
|
|
550
557
|
end
|
551
558
|
DEPAGER_EXPANDED_CODE
|
552
|
-
|
553
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 162
|
559
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 164
|
554
560
|
def _act_2 val
|
555
|
-
_expr, = *val
|
561
|
+
_expr, = *val
|
556
562
|
[ _expr ]
|
557
563
|
|
558
564
|
end
|
559
565
|
DEPAGER_EXPANDED_CODE
|
560
|
-
|
561
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 163
|
566
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 165
|
562
567
|
def _act_3 val
|
563
|
-
_pair, _, _expr, = *val
|
568
|
+
_pair, _, _expr, = *val
|
564
569
|
_pair << _expr
|
565
570
|
|
566
571
|
end
|
567
572
|
DEPAGER_EXPANDED_CODE
|
568
|
-
|
569
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 166
|
573
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 168
|
570
574
|
def _act_4 val
|
571
|
-
_ID, = *val
|
575
|
+
_ID, = *val
|
572
576
|
[ _ID.value, nil]
|
573
577
|
|
574
578
|
end
|
575
579
|
DEPAGER_EXPANDED_CODE
|
576
|
-
|
577
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 167
|
580
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/cst.dr', 169
|
578
581
|
def _act_5 val
|
579
|
-
_ID, _, _LIT, = *val
|
582
|
+
_ID, _, _LIT, = *val
|
580
583
|
[ _ID.value, _LIT.value ]
|
581
584
|
|
582
585
|
end
|
583
586
|
DEPAGER_EXPANDED_CODE
|
584
|
-
|
585
|
-
|
587
|
+
|
588
|
+
|
586
589
|
end
|
587
|
-
|
590
|
+
|
591
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
%defext Depager::LexerExtension
|
2
|
-
%extend Depager::Action ('plugins/action.rb')
|
2
|
+
%extend Depager::Action ('depager/plugins/action.rb')
|
3
3
|
%decorate @Action
|
4
|
-
#%decorate Depager::LALR::ShiftReducePrinter ('plugins/srp.rb')
|
4
|
+
#%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
|
5
5
|
%expanded_code_delimiter DEPAGER_EXPANDED_CODE
|
6
6
|
%hook pre_rule_list /%LEX\{\s*\Z/ skip
|
7
7
|
%banner '%LEX{ ... }'
|
@@ -43,12 +43,12 @@
|
|
43
43
|
start:
|
44
44
|
lexactlist
|
45
45
|
{
|
46
|
-
g_parser.inner_code <<
|
46
|
+
g_parser.inner_code << <<~CODE
|
47
47
|
def lex
|
48
48
|
begin
|
49
49
|
until @line.empty?
|
50
50
|
case @line
|
51
|
-
|
51
|
+
#{ _lexactlist }
|
52
52
|
else
|
53
53
|
raise RuntimeError, "must not happen \#{@line}"
|
54
54
|
end
|
@@ -56,7 +56,7 @@
|
|
56
56
|
end while @original_line = @line = file.gets
|
57
57
|
yield nil, nil
|
58
58
|
end
|
59
|
-
|
59
|
+
CODE
|
60
60
|
}
|
61
61
|
;
|
62
62
|
lexactlist:
|
@@ -66,11 +66,11 @@
|
|
66
66
|
lexact:
|
67
67
|
lexlist opt_noskip ACTION
|
68
68
|
{
|
69
|
-
|
69
|
+
<<-CODE
|
70
70
|
when #{_lexlist.join(', ')}
|
71
71
|
#{ _opt_noskip ? '#' : "@line = $'" }
|
72
72
|
#{ _ACTION }
|
73
|
-
|
73
|
+
CODE
|
74
74
|
}
|
75
75
|
;
|
76
76
|
opt_noskip:
|