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
@@ -1,17 +1,17 @@
|
|
1
1
|
%class StatefulLexerTest1
|
2
|
-
%extend StatefulLexer ('
|
3
|
-
%extend NVAction ('
|
2
|
+
%extend StatefulLexer ('plugins/slex.rb')
|
3
|
+
%extend NVAction ('plugins/nvaction.rb')
|
4
4
|
%decorate @NVAction
|
5
5
|
%decorate @StatefulLexer
|
6
|
-
#%decorate ShiftReducePrinter ('
|
6
|
+
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
7
7
|
%%
|
8
8
|
%LEX{
|
9
9
|
<START>
|
10
10
|
/\s+/ { }
|
11
|
-
/\/(([^\/\\]+|\\.)*)\// { yield
|
12
|
-
/./ { yield
|
11
|
+
/\/(([^\/\\]+|\\.)*)\// { yield token(:REGEXP, $&) }
|
12
|
+
/./ { yield token($&, $&) }
|
13
13
|
<OPMODE : START>
|
14
|
-
'/' { yield
|
14
|
+
'/' { yield token($&, $&) }
|
15
15
|
%}
|
16
16
|
|
17
17
|
#begin-rule
|
@@ -26,4 +26,4 @@
|
|
26
26
|
#end-rule
|
27
27
|
%%
|
28
28
|
p = createDecoratedStatefulLexerTest1
|
29
|
-
p.
|
29
|
+
p.parse(STDIN)
|
@@ -19,8 +19,8 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
19
19
|
]
|
20
20
|
### Extension Params
|
21
21
|
nparams = {
|
22
|
-
'StatefulLexer' => 2,
|
23
22
|
'NVAction' => 3,
|
23
|
+
'StatefulLexer' => 2,
|
24
24
|
}
|
25
25
|
### Term to Int
|
26
26
|
t2i = {
|
@@ -38,20 +38,20 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
38
38
|
]
|
39
39
|
### Action Table
|
40
40
|
action_table = [
|
41
|
-
[ nil, nil, nil,
|
41
|
+
[ nil, nil, nil, 2, ],
|
42
42
|
[ ACC, nil, 4, nil, ],
|
43
43
|
[ nil, nil, nil, nil, ],
|
44
44
|
[ nil, nil, nil, nil, ],
|
45
45
|
[ nil, nil, nil, nil, ],
|
46
|
-
[ nil, nil, nil,
|
46
|
+
[ nil, nil, nil, 2, ],
|
47
47
|
[ nil, nil, nil, nil, ],
|
48
48
|
]
|
49
49
|
### Default Reduce Table
|
50
50
|
defred_table = [
|
51
51
|
nil,
|
52
52
|
nil,
|
53
|
-
-2,
|
54
53
|
-4,
|
54
|
+
-2,
|
55
55
|
-3,
|
56
56
|
nil,
|
57
57
|
-1,
|
@@ -59,8 +59,8 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
59
59
|
defred_after_shift_table = [
|
60
60
|
nil,
|
61
61
|
nil,
|
62
|
-
-2,
|
63
62
|
-4,
|
63
|
+
-2,
|
64
64
|
-3,
|
65
65
|
nil,
|
66
66
|
-1,
|
@@ -79,7 +79,7 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
79
79
|
]
|
80
80
|
### Goto Table
|
81
81
|
goto_table = [
|
82
|
-
[ 1,
|
82
|
+
[ 1, 3, nil, ],
|
83
83
|
[ nil, nil, nil, ],
|
84
84
|
[ nil, nil, nil, ],
|
85
85
|
[ nil, nil, nil, ],
|
@@ -101,7 +101,7 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
101
101
|
I000 =
|
102
102
|
( 0) $start : _ expr
|
103
103
|
|
104
|
-
REGEXP shift, and goto to state
|
104
|
+
REGEXP shift, and goto to state 2
|
105
105
|
|
106
106
|
|
107
107
|
----------
|
@@ -120,19 +120,19 @@ I001 =
|
|
120
120
|
|
121
121
|
<<'----------',
|
122
122
|
I002 =
|
123
|
-
(
|
123
|
+
( 4) fact : REGEXP _
|
124
124
|
|
125
125
|
|
126
|
-
$default reduce using rule
|
126
|
+
$default reduce using rule 4 (fact) [after shift]
|
127
127
|
|
128
128
|
----------
|
129
129
|
|
130
130
|
<<'----------',
|
131
131
|
I003 =
|
132
|
-
(
|
132
|
+
( 2) expr : fact _
|
133
133
|
|
134
134
|
|
135
|
-
$default reduce using rule
|
135
|
+
$default reduce using rule 2 (expr) [after shift]
|
136
136
|
|
137
137
|
----------
|
138
138
|
|
@@ -149,7 +149,7 @@ I004 =
|
|
149
149
|
I005 =
|
150
150
|
( 1) expr : expr '/' __expr_0_2__ _ fact
|
151
151
|
|
152
|
-
REGEXP shift, and goto to state
|
152
|
+
REGEXP shift, and goto to state 2
|
153
153
|
|
154
154
|
|
155
155
|
----------
|
@@ -185,12 +185,12 @@ I006 =
|
|
185
185
|
|
186
186
|
when /\A\/(([^\/\\]+|\\.)*)\//
|
187
187
|
@oldline = @line; @line = $'
|
188
|
-
yield
|
188
|
+
yield token(:REGEXP, $&)
|
189
189
|
|
190
190
|
|
191
191
|
when /\A./
|
192
192
|
@oldline = @line; @line = $'
|
193
|
-
yield
|
193
|
+
yield token($&, $&)
|
194
194
|
|
195
195
|
|
196
196
|
else
|
@@ -203,7 +203,7 @@ I006 =
|
|
203
203
|
|
204
204
|
when /\A\//
|
205
205
|
@oldline = @line; @line = $'
|
206
|
-
yield
|
206
|
+
yield token($&, $&)
|
207
207
|
|
208
208
|
|
209
209
|
else
|
@@ -229,7 +229,7 @@ end
|
|
229
229
|
|
230
230
|
class D4StatefulLexerTest1::StatefulLexer < Depager::LALR::Action #:nodoc:all
|
231
231
|
include Depager::DecoratorUtils
|
232
|
-
|
232
|
+
|
233
233
|
on_reduce = [
|
234
234
|
nil,
|
235
235
|
nil,
|
@@ -262,7 +262,7 @@ end
|
|
262
262
|
|
263
263
|
class D4StatefulLexerTest1::NVAction < Depager::LALR::Action #:nodoc:all
|
264
264
|
include Depager::DecoratorUtils
|
265
|
-
|
265
|
+
|
266
266
|
on_reduce = [
|
267
267
|
nil,
|
268
268
|
nil,
|
@@ -279,13 +279,13 @@ class D4StatefulLexerTest1::NVAction < Depager::LALR::Action #:nodoc:all
|
|
279
279
|
end
|
280
280
|
|
281
281
|
|
282
|
-
module_eval <<-'.,.,
|
282
|
+
module_eval <<-'.,.,122745804061258.,.,', 'slex_test/divreg.slex.dr', 22
|
283
283
|
def _act_3 val
|
284
284
|
_REGEXP, = *val
|
285
285
|
warn "REGEXP: #{_REGEXP.value}"
|
286
286
|
|
287
287
|
end
|
288
|
-
.,.,
|
288
|
+
.,.,122745804061258.,.,
|
289
289
|
|
290
290
|
end
|
291
291
|
|
@@ -298,6 +298,6 @@ end
|
|
298
298
|
if __FILE__ == $0
|
299
299
|
### Main Code
|
300
300
|
p = createDecoratedStatefulLexerTest1
|
301
|
-
p.
|
301
|
+
p.parse(STDIN)
|
302
302
|
|
303
303
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
%class StatefulLexerTest2
|
2
|
-
%extend StatefulLexer ('
|
3
|
-
%extend NVAction ('
|
2
|
+
%extend StatefulLexer ('plugins/slex.rb')
|
3
|
+
%extend NVAction ('plugins/nvaction.rb')
|
4
4
|
%decorate @NVAction
|
5
5
|
%decorate @StatefulLexer
|
6
|
-
#%decorate ShiftReducePrinter ('
|
6
|
+
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
7
7
|
%%
|
8
8
|
%LEX{
|
9
9
|
<START>
|
10
10
|
/[ \t]+/ { }
|
11
|
-
/\n/ { yield
|
12
|
-
/\w+/ { yield
|
13
|
-
/./ { yield
|
11
|
+
/\n/ { yield token(:EOL, $&) }
|
12
|
+
/\w+/ { yield token(:ID, $&) }
|
13
|
+
/./ { yield token($&, $&) }
|
14
14
|
<LCONT : START>
|
15
15
|
/\r?\n/ { }
|
16
16
|
%}
|
@@ -33,4 +33,4 @@
|
|
33
33
|
#end-rule
|
34
34
|
%%
|
35
35
|
p = createDecoratedStatefulLexerTest2
|
36
|
-
p.
|
36
|
+
p.parse(STDIN)
|
@@ -21,8 +21,8 @@ class StatefulLexerTest2 < Depager::LALR::Basis
|
|
21
21
|
]
|
22
22
|
### Extension Params
|
23
23
|
nparams = {
|
24
|
-
'StatefulLexer' => 2,
|
25
24
|
'NVAction' => 3,
|
25
|
+
'StatefulLexer' => 2,
|
26
26
|
}
|
27
27
|
### Term to Int
|
28
28
|
t2i = {
|
@@ -219,17 +219,17 @@ I008 =
|
|
219
219
|
|
220
220
|
when /\A\n/
|
221
221
|
@oldline = @line; @line = $'
|
222
|
-
yield
|
222
|
+
yield token(:EOL, $&)
|
223
223
|
|
224
224
|
|
225
225
|
when /\A\w+/
|
226
226
|
@oldline = @line; @line = $'
|
227
|
-
yield
|
227
|
+
yield token(:ID, $&)
|
228
228
|
|
229
229
|
|
230
230
|
when /\A./
|
231
231
|
@oldline = @line; @line = $'
|
232
|
-
yield
|
232
|
+
yield token($&, $&)
|
233
233
|
|
234
234
|
|
235
235
|
else
|
@@ -268,7 +268,7 @@ end
|
|
268
268
|
|
269
269
|
class D4StatefulLexerTest2::StatefulLexer < Depager::LALR::Action #:nodoc:all
|
270
270
|
include Depager::DecoratorUtils
|
271
|
-
|
271
|
+
|
272
272
|
on_reduce = [
|
273
273
|
nil,
|
274
274
|
nil,
|
@@ -303,7 +303,7 @@ end
|
|
303
303
|
|
304
304
|
class D4StatefulLexerTest2::NVAction < Depager::LALR::Action #:nodoc:all
|
305
305
|
include Depager::DecoratorUtils
|
306
|
-
|
306
|
+
|
307
307
|
on_reduce = [
|
308
308
|
nil,
|
309
309
|
nil,
|
@@ -322,37 +322,37 @@ class D4StatefulLexerTest2::NVAction < Depager::LALR::Action #:nodoc:all
|
|
322
322
|
end
|
323
323
|
|
324
324
|
|
325
|
-
module_eval <<-'.,.,
|
325
|
+
module_eval <<-'.,.,12274580401395.,.,', 'slex_test/ljoin.slex.dr', 19
|
326
326
|
def _act_1 val
|
327
327
|
_stmts, _expr, _EOL, = *val
|
328
328
|
warn "#{_expr} <EOL>:#{@lexstate}"
|
329
329
|
|
330
330
|
end
|
331
|
-
.,.,
|
331
|
+
.,.,12274580401395.,.,
|
332
332
|
|
333
|
-
module_eval <<-'.,.,
|
333
|
+
module_eval <<-'.,.,1227458040182.,.,', 'slex_test/ljoin.slex.dr', 23
|
334
334
|
def _act_2 val
|
335
335
|
_expr, _, ___expr_0_2__, _fact, = *val
|
336
336
|
"#{_expr} + #{_fact}"
|
337
337
|
|
338
338
|
end
|
339
|
-
.,.,
|
339
|
+
.,.,1227458040182.,.,
|
340
340
|
|
341
|
-
module_eval <<-'.,.,
|
341
|
+
module_eval <<-'.,.,122745804061311.,.,', 'slex_test/ljoin.slex.dr', 25
|
342
342
|
def _act_3 val
|
343
343
|
_fact, = *val
|
344
344
|
_fact
|
345
345
|
|
346
346
|
end
|
347
|
-
.,.,
|
347
|
+
.,.,122745804061311.,.,
|
348
348
|
|
349
|
-
module_eval <<-'.,.,
|
349
|
+
module_eval <<-'.,.,122745804033944.,.,', 'slex_test/ljoin.slex.dr', 29
|
350
350
|
def _act_5 val
|
351
351
|
_ID, = *val
|
352
352
|
_ID.value
|
353
353
|
|
354
354
|
end
|
355
|
-
.,.,
|
355
|
+
.,.,122745804033944.,.,
|
356
356
|
|
357
357
|
end
|
358
358
|
|
@@ -365,6 +365,6 @@ end
|
|
365
365
|
if __FILE__ == $0
|
366
366
|
### Main Code
|
367
367
|
p = createDecoratedStatefulLexerTest2
|
368
|
-
p.
|
368
|
+
p.parse(STDIN)
|
369
369
|
|
370
370
|
end
|
data/lib/depager.rb
CHANGED
@@ -4,7 +4,9 @@ require "depager/grammar.rb"
|
|
4
4
|
require "depager/utils.rb"
|
5
5
|
|
6
6
|
module Depager
|
7
|
-
|
7
|
+
LIBDIR = File.expand_path "#{File.dirname(__FILE__)}/depager/ruby"
|
8
|
+
Tmpldir = "#{LIBDIR}/templates"
|
9
|
+
$LOAD_PATH.unshift LIBDIR
|
8
10
|
|
9
11
|
#
|
10
12
|
# file manager
|
@@ -121,11 +123,21 @@ module Depager
|
|
121
123
|
#
|
122
124
|
class GrammarParser
|
123
125
|
include FileUtils
|
126
|
+
|
127
|
+
HOOK_KEYS = [
|
128
|
+
:pre_rule_list, :post_rule_list,
|
129
|
+
:pre_rule, :post_rule,
|
130
|
+
:post_lhs,
|
131
|
+
:post_rhs_list, :pre_rhs_list,
|
132
|
+
:pre_rhs, :post_rhs, :post_symbol
|
133
|
+
] #:nodoc:
|
134
|
+
def self.hook_name? s
|
135
|
+
HOOK_KEYS.include? s.to_sym
|
136
|
+
end
|
137
|
+
|
124
138
|
def files
|
125
139
|
@d_parser.files
|
126
140
|
end
|
127
|
-
alias file files
|
128
|
-
alias f files
|
129
141
|
|
130
142
|
private
|
131
143
|
GToken = Struct.new(:tag, :value, :name, :lineno)
|
@@ -135,18 +147,18 @@ module Depager
|
|
135
147
|
end
|
136
148
|
def parse_grammar
|
137
149
|
gettoken
|
138
|
-
|
150
|
+
do_hook :pre_rule_list
|
139
151
|
parse_rulelist
|
140
|
-
|
152
|
+
do_hook :post_rule_list
|
141
153
|
unless @token.tag == nil
|
142
154
|
error_exit "syntax error(grammar). "<<
|
143
155
|
"unexpected '#{@token.tag}' expect '%%'"
|
144
156
|
end
|
145
157
|
end
|
146
158
|
def parse_rulelist
|
147
|
-
|
159
|
+
do_hook :pre_rule
|
148
160
|
parse_rule
|
149
|
-
|
161
|
+
do_hook :post_rule
|
150
162
|
if @token.tag == :NT
|
151
163
|
parse_rulelist
|
152
164
|
end
|
@@ -156,7 +168,7 @@ module Depager
|
|
156
168
|
@lhs = @token.value
|
157
169
|
|
158
170
|
gettoken
|
159
|
-
|
171
|
+
do_hook :post_lhs
|
160
172
|
|
161
173
|
unless @token.tag == ':'
|
162
174
|
error_exit "syntax error(grammar). "<<
|
@@ -165,13 +177,13 @@ module Depager
|
|
165
177
|
gettoken
|
166
178
|
|
167
179
|
@nrhs = 0
|
168
|
-
|
180
|
+
do_hook :pre_rhs_list
|
169
181
|
parse_rhslist
|
170
|
-
|
182
|
+
do_hook :post_rhs_list
|
171
183
|
|
172
184
|
unless @token.tag == ';'
|
173
185
|
error_exit "syntax error(grammar). " <<
|
174
|
-
"unexpected '#{@token
|
186
|
+
"unexpected '#{@token.tag}' expecting ';'"
|
175
187
|
end
|
176
188
|
gettoken
|
177
189
|
end
|
@@ -179,10 +191,10 @@ module Depager
|
|
179
191
|
def parse_rhslist
|
180
192
|
@rhs = []; @rhsni = {}; @prec = nil
|
181
193
|
@optval = Array.new(@nparam)
|
182
|
-
|
194
|
+
do_hook :pre_rhs
|
183
195
|
parse_syms
|
184
196
|
add_rule(@lhs, @rhs, @prec)
|
185
|
-
|
197
|
+
do_hook :post_rhs
|
186
198
|
@nrhs += 1
|
187
199
|
|
188
200
|
if @token.tag == '|'
|
@@ -195,12 +207,11 @@ module Depager
|
|
195
207
|
rhs_insert_sym(-1, @token.value, @token.name)
|
196
208
|
gettoken
|
197
209
|
|
198
|
-
|
210
|
+
do_hook :post_symbol
|
199
211
|
parse_syms
|
200
212
|
end
|
201
213
|
end
|
202
214
|
|
203
|
-
public
|
204
215
|
def gettoken
|
205
216
|
while !@line.empty? || !eof?
|
206
217
|
if @line.empty?
|
@@ -235,11 +246,11 @@ module Depager
|
|
235
246
|
val = @terms[s] ||= - (@terms.size + 1)
|
236
247
|
when /^%%/
|
237
248
|
return _GToken(nil, nil)
|
238
|
-
when /^(
|
249
|
+
when /^([:;|])/
|
239
250
|
tag = $&
|
240
251
|
val = $&
|
241
252
|
else
|
242
|
-
|
253
|
+
return _GToken(:UNKNOWN, @line[0].chr)
|
243
254
|
end
|
244
255
|
@oldline = @line; @line = $'
|
245
256
|
@i2s[val] ||= s if val && s
|
@@ -250,38 +261,17 @@ module Depager
|
|
250
261
|
end
|
251
262
|
|
252
263
|
private
|
253
|
-
def
|
254
|
-
@
|
255
|
-
end
|
256
|
-
def postRuleList
|
257
|
-
@postrulelist.each{|o, m| o.send m}
|
258
|
-
end
|
259
|
-
def preRule
|
260
|
-
@prerule.each{|o, m| o.send m}
|
261
|
-
end
|
262
|
-
def postRule
|
263
|
-
@postrule.each{|o, m| o.send m}
|
264
|
-
end
|
265
|
-
def postLhs
|
266
|
-
@postlhs.each{|o, m| o.send(m)}
|
267
|
-
end
|
268
|
-
def preRhsList
|
269
|
-
@prerhslist.each{|o, m| o.send m}
|
270
|
-
end
|
271
|
-
def postRhsList
|
272
|
-
@postrhslist.each{|o, m| o.send m}
|
273
|
-
end
|
274
|
-
def preRhs
|
275
|
-
@prerhs.each{|o, m| o.send(m)}
|
276
|
-
end
|
277
|
-
def postRhs
|
278
|
-
@postrhs.each{|o, m| o.send(m)}
|
279
|
-
end
|
280
|
-
def postSymbol
|
281
|
-
@postsymbol.each{|o, m| o.send(m)}
|
264
|
+
def do_hook hook
|
265
|
+
@hooks[hook].each{|o, m| o.send m}
|
282
266
|
end
|
283
267
|
|
284
268
|
public
|
269
|
+
# update line and get token
|
270
|
+
def update_context line
|
271
|
+
@line = line
|
272
|
+
gettoken
|
273
|
+
end
|
274
|
+
|
285
275
|
# get number of param
|
286
276
|
def getnparam a = nil
|
287
277
|
return nil unless a
|
@@ -335,14 +325,11 @@ module Depager
|
|
335
325
|
end
|
336
326
|
end
|
337
327
|
|
338
|
-
attr_accessor :rules, :terms, :nonterms, :precs
|
328
|
+
attr_accessor :rules, :terms, :nonterms, :precs, :table
|
339
329
|
attr_accessor :line, :line0, :oldline, :token
|
340
330
|
attr_accessor :optouter, :optinner, :optmain, :mixin
|
341
331
|
attr_accessor :nparams, :lhs, :rhs, :nrhs, :rhsni, :nparam, :nrules
|
342
|
-
|
343
|
-
attr_accessor :postlhs, :prerhslist, :postrhslist
|
344
|
-
attr_accessor :prerhs, :postrhs, :postsymbol
|
345
|
-
attr_reader :d_parser, :target_name, :table, :parsing_method
|
332
|
+
attr_reader :d_parser, :target_name, :parsing_method, :hooks
|
346
333
|
|
347
334
|
def initialize d_parser
|
348
335
|
@yydebug = true
|
@@ -401,21 +388,7 @@ module Depager
|
|
401
388
|
|
402
389
|
# initialize hook
|
403
390
|
def init_hook
|
404
|
-
@
|
405
|
-
@postrulelist = []
|
406
|
-
|
407
|
-
@prerule = []
|
408
|
-
@postrule = []
|
409
|
-
|
410
|
-
@postlhs = []
|
411
|
-
|
412
|
-
@postrhslist = []
|
413
|
-
@prerhslist = []
|
414
|
-
|
415
|
-
@prerhs = []
|
416
|
-
@postrhs = []
|
417
|
-
|
418
|
-
@postsymbol = []
|
391
|
+
@hooks = HOOK_KEYS.inject({}){|r,i| r[i]=[]; r }
|
419
392
|
end
|
420
393
|
|
421
394
|
def init_grammar
|
@@ -627,21 +600,7 @@ module Depager
|
|
627
600
|
@parsing_method = Simple
|
628
601
|
@basis_name = 'self'
|
629
602
|
@paramkey = nil
|
630
|
-
@regs = {
|
631
|
-
"prerulelist" => nil,
|
632
|
-
"postrulelist" => nil,
|
633
|
-
|
634
|
-
"prerule" => nil,
|
635
|
-
"postrule" => nil,
|
636
|
-
|
637
|
-
"postlhs" => nil,
|
638
|
-
|
639
|
-
"postrhslist" => nil,
|
640
|
-
"prerhslist" => nil,
|
641
|
-
|
642
|
-
"prerhs" => nil,
|
643
|
-
"postrhs" => nil,
|
644
|
-
}
|
603
|
+
@regs = { }
|
645
604
|
end
|
646
605
|
|
647
606
|
def parse_decl
|
@@ -655,8 +614,11 @@ module Depager
|
|
655
614
|
[$1, $3 ? true : false]
|
656
615
|
end
|
657
616
|
hook = hs.split(' ')
|
658
|
-
hookname = hook.join('
|
659
|
-
hook.each
|
617
|
+
hookname = hook.join('__')
|
618
|
+
hook.each do |i| i = i.to_sym
|
619
|
+
raise unless GrammarParser.hook_name? i
|
620
|
+
@regs[i] = "#{@d_parser.target_name}_#{hookname}"
|
621
|
+
end
|
660
622
|
@optouter.push(parse_hook(hookname, mtsk))
|
661
623
|
when /^%param\s*(.*)\s*$/
|
662
624
|
@paramkey = $1
|