depager 0.2.3 → 0.3.0.b20160729
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.en +4 -19
- data/README.ja +42 -79
- data/bin/depager +42 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +49 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +10 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/extension/calc.simple_action.dr +33 -0
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +44 -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/sample_calc/calc.action.dr +33 -33
- data/examples/sample_calc/calc.ast.action.dr +65 -66
- data/examples/sample_calc/calc.ast.dr +55 -55
- data/examples/sample_calc/calc.cst.dr +45 -45
- data/examples/sample_calc/calc.dr +43 -43
- data/examples/sample_calc/calc.lex.dr +29 -29
- data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
- 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/lib/depager.rb +582 -670
- data/lib/depager/grammar.rb +256 -291
- data/lib/depager/lr.rb +574 -579
- data/lib/depager/parser.rb +282 -277
- data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
- data/lib/depager/ruby/plugins/action.rb +53 -43
- data/lib/depager/ruby/plugins/ast.dr +364 -269
- data/lib/depager/ruby/plugins/ast.rb +1367 -1308
- data/lib/depager/ruby/plugins/cst.dr +172 -180
- data/lib/depager/ruby/plugins/cst.rb +587 -626
- data/lib/depager/ruby/plugins/lex.dr +85 -89
- data/lib/depager/ruby/plugins/lex.rb +310 -336
- data/lib/depager/ruby/plugins/rie.dr +723 -0
- data/lib/depager/ruby/plugins/rie.rb +1653 -0
- data/lib/depager/ruby/plugins/slex.dr +202 -200
- data/lib/depager/ruby/plugins/slex.rb +780 -817
- data/lib/depager/ruby/plugins/srp.rb +56 -51
- data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
- data/lib/depager/utils.rb +148 -318
- data/lib/depager/version.rb +4 -3
- metadata +52 -60
- 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.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.dr +0 -33
- 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/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/nvaction.rb +0 -19
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
@@ -1,89 +1,85 @@
|
|
1
|
-
%defext LexerExtension
|
2
|
-
%extend
|
3
|
-
%decorate @
|
4
|
-
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
5
|
-
%
|
6
|
-
%hook pre_rule_list /%LEX\{\s*\Z/ skip
|
7
|
-
%banner '%LEX{ ... }'
|
8
|
-
%inner{
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
;
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
;
|
80
|
-
|
81
|
-
|
82
|
-
| '
|
83
|
-
;
|
84
|
-
|
85
|
-
|
86
|
-
| lexlist ',' LEX { _lexlist << _LEX }
|
87
|
-
;
|
88
|
-
#end-rule
|
89
|
-
%%
|
1
|
+
%defext Depager::LexerExtension
|
2
|
+
%extend Depager::Action ('plugins/action.rb')
|
3
|
+
%decorate @Action
|
4
|
+
#%decorate Depager::LALR::ShiftReducePrinter ('plugins/srp.rb')
|
5
|
+
%expanded_code_delimiter DEPAGER_EXPANDED_CODE
|
6
|
+
%hook pre_rule_list /%LEX\{\s*\Z/ skip
|
7
|
+
%banner '%LEX{ ... }'
|
8
|
+
%inner{
|
9
|
+
def lex
|
10
|
+
until @file.eof?
|
11
|
+
until @line.empty?
|
12
|
+
case @line
|
13
|
+
when /\A\s+/
|
14
|
+
#skip blank
|
15
|
+
when /\A%\}\s*\Z/
|
16
|
+
@line = $'
|
17
|
+
yield nil,nil
|
18
|
+
when /\A\/(([^\/\\]+|\\.)*)\//
|
19
|
+
yield :LEX, "/\\A#{$1}/"
|
20
|
+
when /\A'([^'\\]+|\\.)*'/, /\A"([^"\\]+|\\.)*"/
|
21
|
+
rest = $'
|
22
|
+
str = Regexp.escape($1).gsub('/', '\/')
|
23
|
+
rest.match(/^/)
|
24
|
+
yield :LEX, "/\\A#{str}/"
|
25
|
+
when /\A\{/
|
26
|
+
yield :ACTION, parse_block
|
27
|
+
/./=~'.'
|
28
|
+
when /\A(.)/
|
29
|
+
yield $&, $&
|
30
|
+
else
|
31
|
+
raise RuntimeError, "must not happen #{line}"
|
32
|
+
end
|
33
|
+
@line = $'
|
34
|
+
end
|
35
|
+
@original_line = @line = file.gets
|
36
|
+
end
|
37
|
+
yield nil, nil
|
38
|
+
end
|
39
|
+
%}
|
40
|
+
%%
|
41
|
+
|
42
|
+
#begin-rule
|
43
|
+
start:
|
44
|
+
lexactlist
|
45
|
+
{
|
46
|
+
g_parser.inner_code << %{
|
47
|
+
def lex
|
48
|
+
begin
|
49
|
+
until @line.empty?
|
50
|
+
case @line
|
51
|
+
#{ _lexactlist }
|
52
|
+
else
|
53
|
+
raise RuntimeError, "must not happen \#{@line}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end while @original_line = @line = file.gets
|
57
|
+
yield nil, nil
|
58
|
+
end
|
59
|
+
}; #code
|
60
|
+
}
|
61
|
+
;
|
62
|
+
lexactlist:
|
63
|
+
lexact { _lexact }
|
64
|
+
| lexactlist lexact { _lexactlist << _lexact }
|
65
|
+
;
|
66
|
+
lexact:
|
67
|
+
lexlist opt_noskip ACTION
|
68
|
+
{
|
69
|
+
%{
|
70
|
+
when #{_lexlist.join(', ')}
|
71
|
+
#{ _opt_noskip ? '#' : "@line = $'" }
|
72
|
+
#{ _ACTION }
|
73
|
+
}; #code
|
74
|
+
}
|
75
|
+
;
|
76
|
+
opt_noskip:
|
77
|
+
{ false }
|
78
|
+
| '!' { true }
|
79
|
+
;
|
80
|
+
lexlist:
|
81
|
+
LEX { [ _LEX ] }
|
82
|
+
| lexlist ',' LEX { _lexlist << _LEX }
|
83
|
+
;
|
84
|
+
#end-rule
|
85
|
+
%%
|
@@ -1,336 +1,310 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
###
|
4
|
-
###
|
5
|
-
|
6
|
-
require 'depager/parser.rb'
|
7
|
-
|
8
|
-
|
9
|
-
module
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
def _act_5 val
|
312
|
-
_, = *val
|
313
|
-
true
|
314
|
-
|
315
|
-
end
|
316
|
-
.,.,122745803352625.,.,
|
317
|
-
|
318
|
-
module_eval <<-'.,.,122745803357424.,.,', 'lex.dr', 83
|
319
|
-
def _act_6 val
|
320
|
-
_LEX, = *val
|
321
|
-
[ _LEX ]
|
322
|
-
|
323
|
-
end
|
324
|
-
.,.,122745803357424.,.,
|
325
|
-
|
326
|
-
module_eval <<-'.,.,122745803338595.,.,', 'lex.dr', 84
|
327
|
-
def _act_7 val
|
328
|
-
_lexlist, _, _LEX, = *val
|
329
|
-
_lexlist << _LEX
|
330
|
-
|
331
|
-
end
|
332
|
-
.,.,122745803338595.,.,
|
333
|
-
|
334
|
-
end
|
335
|
-
|
336
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
###
|
4
|
+
### Depager::LexerExtension - Depager Extension (master)
|
5
|
+
###
|
6
|
+
require 'depager/parser.rb'
|
7
|
+
|
8
|
+
|
9
|
+
module Depager ; end
|
10
|
+
|
11
|
+
class Depager::LexerExtension < Depager::Extension
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@master = self
|
15
|
+
@slaves = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def extension_registered g_parser
|
19
|
+
super g_parser
|
20
|
+
|
21
|
+
@slaves[0] = Depager::LexerExtension::Slave_pre_rule_list::Parser.new(g_parser, self)
|
22
|
+
g_parser.hooks[:pre_rule_list].push [@slaves[0], :do_parse]
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
###
|
29
|
+
### Depager::LexerExtension::Slave_pre_rule_list - Part of Depager Extension (slave)
|
30
|
+
###
|
31
|
+
|
32
|
+
module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
33
|
+
class Parser < Depager::LALR::Basis #:nodoc:all
|
34
|
+
include Depager::Utils::ExtensionSlaveMethods
|
35
|
+
|
36
|
+
|
37
|
+
### Reduce Table
|
38
|
+
reduce_table = [
|
39
|
+
[ -1, 1 ],
|
40
|
+
[ 0, 1 ],
|
41
|
+
[ 1, 1 ],
|
42
|
+
[ 1, 2 ],
|
43
|
+
[ 2, 3 ],
|
44
|
+
[ 4, 0 ],
|
45
|
+
[ 4, 1 ],
|
46
|
+
[ 3, 1 ],
|
47
|
+
[ 3, 3 ],
|
48
|
+
]
|
49
|
+
### Term to Int
|
50
|
+
term_to_int = {
|
51
|
+
nil => 0,
|
52
|
+
false => 1,
|
53
|
+
:ACTION => 2,
|
54
|
+
"!" => 3,
|
55
|
+
:LEX => 4,
|
56
|
+
"," => 5,
|
57
|
+
}
|
58
|
+
### Int to Term
|
59
|
+
int_to_term = [
|
60
|
+
nil,
|
61
|
+
false,
|
62
|
+
:ACTION,
|
63
|
+
"!",
|
64
|
+
:LEX,
|
65
|
+
",",
|
66
|
+
]
|
67
|
+
### Action Table
|
68
|
+
action_table = [
|
69
|
+
[ nil, nil, nil, nil, 5, nil, ],
|
70
|
+
[ ACC, nil, nil, nil, nil, nil, ],
|
71
|
+
[ nil, nil, nil, nil, 5, nil, ],
|
72
|
+
[ nil, nil, nil, nil, nil, nil, ],
|
73
|
+
[ nil, nil, nil, 8, nil, 9, ],
|
74
|
+
[ nil, nil, nil, nil, nil, nil, ],
|
75
|
+
[ nil, nil, nil, nil, nil, nil, ],
|
76
|
+
[ nil, nil, 10, nil, nil, nil, ],
|
77
|
+
[ nil, nil, nil, nil, nil, nil, ],
|
78
|
+
[ nil, nil, nil, nil, 11, nil, ],
|
79
|
+
[ nil, nil, nil, nil, nil, nil, ],
|
80
|
+
[ nil, nil, nil, nil, nil, nil, ],
|
81
|
+
]
|
82
|
+
### Default Reduce Table
|
83
|
+
defred_table = [
|
84
|
+
nil,
|
85
|
+
nil,
|
86
|
+
-1,
|
87
|
+
-2,
|
88
|
+
-5,
|
89
|
+
-7,
|
90
|
+
-3,
|
91
|
+
nil,
|
92
|
+
-6,
|
93
|
+
nil,
|
94
|
+
-4,
|
95
|
+
-8,
|
96
|
+
]
|
97
|
+
defred_after_shift_table = [
|
98
|
+
nil,
|
99
|
+
nil,
|
100
|
+
nil,
|
101
|
+
-2,
|
102
|
+
nil,
|
103
|
+
-7,
|
104
|
+
-3,
|
105
|
+
nil,
|
106
|
+
-6,
|
107
|
+
nil,
|
108
|
+
-4,
|
109
|
+
-8,
|
110
|
+
]
|
111
|
+
### Nonterm to Int
|
112
|
+
nonterm_to_int = {
|
113
|
+
:start => 0,
|
114
|
+
:lexactlist => 1,
|
115
|
+
:lexact => 2,
|
116
|
+
:lexlist => 3,
|
117
|
+
:opt_noskip => 4,
|
118
|
+
}
|
119
|
+
### Int to Nonterm
|
120
|
+
int_to_nonterm = [
|
121
|
+
:start,
|
122
|
+
:lexactlist,
|
123
|
+
:lexact,
|
124
|
+
:lexlist,
|
125
|
+
:opt_noskip,
|
126
|
+
]
|
127
|
+
### Goto Table
|
128
|
+
goto_table = [
|
129
|
+
[ 1, 2, 3, 4, nil, ],
|
130
|
+
[ nil, nil, nil, nil, nil, ],
|
131
|
+
[ nil, nil, 6, 4, nil, ],
|
132
|
+
[ nil, nil, nil, nil, nil, ],
|
133
|
+
[ nil, nil, nil, nil, 7, ],
|
134
|
+
[ nil, nil, nil, nil, nil, ],
|
135
|
+
[ nil, nil, nil, nil, nil, ],
|
136
|
+
[ nil, nil, nil, nil, nil, ],
|
137
|
+
[ nil, nil, nil, nil, nil, ],
|
138
|
+
[ nil, nil, nil, nil, nil, ],
|
139
|
+
[ nil, nil, nil, nil, nil, ],
|
140
|
+
[ nil, nil, nil, nil, nil, ],
|
141
|
+
]
|
142
|
+
|
143
|
+
Tables = [ reduce_table, action_table,
|
144
|
+
defred_table, defred_after_shift_table, goto_table,
|
145
|
+
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
146
|
+
|
147
|
+
def initialize g_parser, master
|
148
|
+
super()
|
149
|
+
@g_parser = g_parser
|
150
|
+
@d_parser = g_parser.d_parser
|
151
|
+
@master = master
|
152
|
+
@decorated = Action.new(self)
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
def do_parse?
|
157
|
+
if @line.match(/^\s*%LEX\{\s*\Z/)
|
158
|
+
@line = $'
|
159
|
+
true
|
160
|
+
else
|
161
|
+
false
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def banner
|
167
|
+
"%LEX{ ... } / Depager::LexerExtension"
|
168
|
+
end
|
169
|
+
|
170
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 9
|
171
|
+
def lex
|
172
|
+
until @file.eof?
|
173
|
+
until @line.empty?
|
174
|
+
case @line
|
175
|
+
when /\A\s+/
|
176
|
+
#skip blank
|
177
|
+
when /\A%\}\s*\Z/
|
178
|
+
@line = $'
|
179
|
+
yield nil,nil
|
180
|
+
when /\A\/(([^\/\\]+|\\.)*)\//
|
181
|
+
yield :LEX, "/\\A#{$1}/"
|
182
|
+
when /\A'([^'\\]+|\\.)*'/, /\A"([^"\\]+|\\.)*"/
|
183
|
+
rest = $'
|
184
|
+
str = Regexp.escape($1).gsub('/', '\/')
|
185
|
+
rest.match(/^/)
|
186
|
+
yield :LEX, "/\\A#{str}/"
|
187
|
+
when /\A\{/
|
188
|
+
yield :ACTION, parse_block
|
189
|
+
/./=~'.'
|
190
|
+
when /\A(.)/
|
191
|
+
yield $&, $&
|
192
|
+
else
|
193
|
+
raise RuntimeError, "must not happen #{line}"
|
194
|
+
end
|
195
|
+
@line = $'
|
196
|
+
end
|
197
|
+
@original_line = @line = file.gets
|
198
|
+
end
|
199
|
+
yield nil, nil
|
200
|
+
end
|
201
|
+
|
202
|
+
DEPAGER_EXPANDED_CODE
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
class Depager::LexerExtension::Slave_pre_rule_list::Action < Depager::LALR::Action #:nodoc:all
|
209
|
+
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
210
|
+
|
211
|
+
on_reduce = [
|
212
|
+
nil,
|
213
|
+
:_act_1,
|
214
|
+
:_act_2,
|
215
|
+
:_act_3,
|
216
|
+
:_act_4,
|
217
|
+
:_act_5,
|
218
|
+
:_act_6,
|
219
|
+
:_act_7,
|
220
|
+
:_act_8,
|
221
|
+
|
222
|
+
]
|
223
|
+
Tables = [ on_reduce ]
|
224
|
+
|
225
|
+
|
226
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 43
|
227
|
+
def _act_1 val
|
228
|
+
_lexactlist, = *val
|
229
|
+
|
230
|
+
g_parser.inner_code << %{
|
231
|
+
def lex
|
232
|
+
begin
|
233
|
+
until @line.empty?
|
234
|
+
case @line
|
235
|
+
#{ _lexactlist }
|
236
|
+
else
|
237
|
+
raise RuntimeError, "must not happen \#{@line}"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end while @original_line = @line = file.gets
|
241
|
+
yield nil, nil
|
242
|
+
end
|
243
|
+
}; #code
|
244
|
+
|
245
|
+
end
|
246
|
+
DEPAGER_EXPANDED_CODE
|
247
|
+
|
248
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 61
|
249
|
+
def _act_2 val
|
250
|
+
_lexact, = *val
|
251
|
+
_lexact
|
252
|
+
|
253
|
+
end
|
254
|
+
DEPAGER_EXPANDED_CODE
|
255
|
+
|
256
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 62
|
257
|
+
def _act_3 val
|
258
|
+
_lexactlist, _lexact, = *val
|
259
|
+
_lexactlist << _lexact
|
260
|
+
|
261
|
+
end
|
262
|
+
DEPAGER_EXPANDED_CODE
|
263
|
+
|
264
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 66
|
265
|
+
def _act_4 val
|
266
|
+
_lexlist, _opt_noskip, _ACTION, = *val
|
267
|
+
|
268
|
+
%{
|
269
|
+
when #{_lexlist.join(', ')}
|
270
|
+
#{ _opt_noskip ? '#' : "@line = $'" }
|
271
|
+
#{ _ACTION }
|
272
|
+
}; #code
|
273
|
+
|
274
|
+
end
|
275
|
+
DEPAGER_EXPANDED_CODE
|
276
|
+
|
277
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 75
|
278
|
+
def _act_5 val
|
279
|
+
false
|
280
|
+
|
281
|
+
end
|
282
|
+
DEPAGER_EXPANDED_CODE
|
283
|
+
|
284
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 76
|
285
|
+
def _act_6 val
|
286
|
+
_, = *val
|
287
|
+
true
|
288
|
+
|
289
|
+
end
|
290
|
+
DEPAGER_EXPANDED_CODE
|
291
|
+
|
292
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 79
|
293
|
+
def _act_7 val
|
294
|
+
_LEX, = *val
|
295
|
+
[ _LEX ]
|
296
|
+
|
297
|
+
end
|
298
|
+
DEPAGER_EXPANDED_CODE
|
299
|
+
|
300
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 80
|
301
|
+
def _act_8 val
|
302
|
+
_lexlist, _, _LEX, = *val
|
303
|
+
_lexlist << _LEX
|
304
|
+
|
305
|
+
end
|
306
|
+
DEPAGER_EXPANDED_CODE
|
307
|
+
|
308
|
+
|
309
|
+
end
|
310
|
+
|