abnf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +194 -0
- data/Rakefile +18 -0
- data/abnf.gemspec +24 -0
- data/lib/abnf.rb +57 -0
- data/lib/abnf/abnf.rb +136 -0
- data/lib/abnf/corerules.rb +28 -0
- data/lib/abnf/grammar.rb +183 -0
- data/lib/abnf/parser.output +348 -0
- data/lib/abnf/parser.rb +821 -0
- data/lib/abnf/parser.y +156 -0
- data/lib/abnf/regexp.rb +394 -0
- data/lib/abnf/version.rb +3 -0
- data/lib/natset.rb +411 -0
- data/lib/regexptree.rb +530 -0
- data/sample/in-place.rb +26 -0
- data/sample/ipv6.rb +42 -0
- data/sample/multiples-of-3.rb +19 -0
- data/sample/uri.rb +75 -0
- data/test/abnf_test.rb +82 -0
- data/test/regexptree_test.rb +12 -0
- data/test/test_helper.rb +3 -0
- metadata +115 -0
data/lib/abnf/parser.rb
ADDED
@@ -0,0 +1,821 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.9
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
###### racc/parser.rb begin
|
8
|
+
unless $".index 'racc/parser.rb'
|
9
|
+
$".push 'racc/parser.rb'
|
10
|
+
self.class.module_eval(<<'...end racc/parser.rb/module_eval...', 'racc/parser.rb', 1)
|
11
|
+
#
|
12
|
+
# $Id: ad1fffef443194fdfa1052d2eee6850552f94313 $
|
13
|
+
#
|
14
|
+
# Copyright (c) 1999-2006 Minero Aoki
|
15
|
+
#
|
16
|
+
# This program is free software.
|
17
|
+
# You can distribute/modify this program under the same terms of ruby.
|
18
|
+
#
|
19
|
+
# As a special exception, when this code is copied by Racc
|
20
|
+
# into a Racc output file, you may use that output file
|
21
|
+
# without restriction.
|
22
|
+
#
|
23
|
+
|
24
|
+
unless defined?(NotImplementedError)
|
25
|
+
NotImplementedError = NotImplementError
|
26
|
+
end
|
27
|
+
|
28
|
+
module Racc
|
29
|
+
class ParseError < StandardError; end
|
30
|
+
end
|
31
|
+
unless defined?(::ParseError)
|
32
|
+
ParseError = Racc::ParseError
|
33
|
+
end
|
34
|
+
|
35
|
+
module Racc
|
36
|
+
|
37
|
+
unless defined?(Racc_No_Extentions)
|
38
|
+
Racc_No_Extentions = false
|
39
|
+
end
|
40
|
+
|
41
|
+
class Parser
|
42
|
+
|
43
|
+
Racc_Runtime_Version = '1.4.6'
|
44
|
+
Racc_Runtime_Revision = '$Id: ad1fffef443194fdfa1052d2eee6850552f94313 $'
|
45
|
+
|
46
|
+
Racc_Runtime_Core_Version_R = '1.4.6'
|
47
|
+
Racc_Runtime_Core_Revision_R = '$Id: ad1fffef443194fdfa1052d2eee6850552f94313 $'.split[1]
|
48
|
+
begin
|
49
|
+
require 'racc/cparse'
|
50
|
+
# Racc_Runtime_Core_Version_C = (defined in extention)
|
51
|
+
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
|
52
|
+
unless new.respond_to?(:_racc_do_parse_c, true)
|
53
|
+
raise LoadError, 'old cparse.so'
|
54
|
+
end
|
55
|
+
if Racc_No_Extentions
|
56
|
+
raise LoadError, 'selecting ruby version of racc runtime core'
|
57
|
+
end
|
58
|
+
|
59
|
+
Racc_Main_Parsing_Routine = :_racc_do_parse_c
|
60
|
+
Racc_YY_Parse_Method = :_racc_yyparse_c
|
61
|
+
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C
|
62
|
+
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C
|
63
|
+
Racc_Runtime_Type = 'c'
|
64
|
+
rescue LoadError
|
65
|
+
Racc_Main_Parsing_Routine = :_racc_do_parse_rb
|
66
|
+
Racc_YY_Parse_Method = :_racc_yyparse_rb
|
67
|
+
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
|
68
|
+
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_R
|
69
|
+
Racc_Runtime_Type = 'ruby'
|
70
|
+
end
|
71
|
+
|
72
|
+
def Parser.racc_runtime_type
|
73
|
+
Racc_Runtime_Type
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def _racc_setup
|
79
|
+
@yydebug = false unless self.class::Racc_debug_parser
|
80
|
+
@yydebug = false unless defined?(@yydebug)
|
81
|
+
if @yydebug
|
82
|
+
@racc_debug_out = $stderr unless defined?(@racc_debug_out)
|
83
|
+
@racc_debug_out ||= $stderr
|
84
|
+
end
|
85
|
+
arg = self.class::Racc_arg
|
86
|
+
arg[13] = true if arg.size < 14
|
87
|
+
arg
|
88
|
+
end
|
89
|
+
|
90
|
+
def _racc_init_sysvars
|
91
|
+
@racc_state = [0]
|
92
|
+
@racc_tstack = []
|
93
|
+
@racc_vstack = []
|
94
|
+
|
95
|
+
@racc_t = nil
|
96
|
+
@racc_val = nil
|
97
|
+
|
98
|
+
@racc_read_next = true
|
99
|
+
|
100
|
+
@racc_user_yyerror = false
|
101
|
+
@racc_error_status = 0
|
102
|
+
end
|
103
|
+
|
104
|
+
###
|
105
|
+
### do_parse
|
106
|
+
###
|
107
|
+
|
108
|
+
def do_parse
|
109
|
+
__send__(Racc_Main_Parsing_Routine, _racc_setup(), false)
|
110
|
+
end
|
111
|
+
|
112
|
+
def next_token
|
113
|
+
raise NotImplementedError, "#{self.class}\#next_token is not defined"
|
114
|
+
end
|
115
|
+
|
116
|
+
def _racc_do_parse_rb(arg, in_debug)
|
117
|
+
action_table, action_check, action_default, action_pointer,
|
118
|
+
_, _, _, _,
|
119
|
+
_, _, token_table, * = arg
|
120
|
+
|
121
|
+
_racc_init_sysvars
|
122
|
+
tok = act = i = nil
|
123
|
+
|
124
|
+
catch(:racc_end_parse) {
|
125
|
+
while true
|
126
|
+
if i = action_pointer[@racc_state[-1]]
|
127
|
+
if @racc_read_next
|
128
|
+
if @racc_t != 0 # not EOF
|
129
|
+
tok, @racc_val = next_token()
|
130
|
+
unless tok # EOF
|
131
|
+
@racc_t = 0
|
132
|
+
else
|
133
|
+
@racc_t = (token_table[tok] or 1) # error token
|
134
|
+
end
|
135
|
+
racc_read_token(@racc_t, tok, @racc_val) if @yydebug
|
136
|
+
@racc_read_next = false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
i += @racc_t
|
140
|
+
unless i >= 0 and
|
141
|
+
act = action_table[i] and
|
142
|
+
action_check[i] == @racc_state[-1]
|
143
|
+
act = action_default[@racc_state[-1]]
|
144
|
+
end
|
145
|
+
else
|
146
|
+
act = action_default[@racc_state[-1]]
|
147
|
+
end
|
148
|
+
while act = _racc_evalact(act, arg)
|
149
|
+
;
|
150
|
+
end
|
151
|
+
end
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
###
|
156
|
+
### yyparse
|
157
|
+
###
|
158
|
+
|
159
|
+
def yyparse(recv, mid)
|
160
|
+
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
|
161
|
+
end
|
162
|
+
|
163
|
+
def _racc_yyparse_rb(recv, mid, arg, c_debug)
|
164
|
+
action_table, action_check, action_default, action_pointer,
|
165
|
+
_, _, _, _,
|
166
|
+
_, _, token_table, * = arg
|
167
|
+
|
168
|
+
_racc_init_sysvars
|
169
|
+
|
170
|
+
catch(:racc_end_parse) {
|
171
|
+
until i = action_pointer[@racc_state[-1]]
|
172
|
+
while act = _racc_evalact(action_default[@racc_state[-1]], arg)
|
173
|
+
;
|
174
|
+
end
|
175
|
+
end
|
176
|
+
recv.__send__(mid) do |tok, val|
|
177
|
+
unless tok
|
178
|
+
@racc_t = 0
|
179
|
+
else
|
180
|
+
@racc_t = (token_table[tok] or 1) # error token
|
181
|
+
end
|
182
|
+
@racc_val = val
|
183
|
+
@racc_read_next = false
|
184
|
+
|
185
|
+
i += @racc_t
|
186
|
+
unless i >= 0 and
|
187
|
+
act = action_table[i] and
|
188
|
+
action_check[i] == @racc_state[-1]
|
189
|
+
act = action_default[@racc_state[-1]]
|
190
|
+
end
|
191
|
+
while act = _racc_evalact(act, arg)
|
192
|
+
;
|
193
|
+
end
|
194
|
+
|
195
|
+
while !(i = action_pointer[@racc_state[-1]]) ||
|
196
|
+
! @racc_read_next ||
|
197
|
+
@racc_t == 0 # $
|
198
|
+
unless i and i += @racc_t and
|
199
|
+
i >= 0 and
|
200
|
+
act = action_table[i] and
|
201
|
+
action_check[i] == @racc_state[-1]
|
202
|
+
act = action_default[@racc_state[-1]]
|
203
|
+
end
|
204
|
+
while act = _racc_evalact(act, arg)
|
205
|
+
;
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
}
|
210
|
+
end
|
211
|
+
|
212
|
+
###
|
213
|
+
### common
|
214
|
+
###
|
215
|
+
|
216
|
+
def _racc_evalact(act, arg)
|
217
|
+
action_table, action_check, _, action_pointer,
|
218
|
+
_, _, _, _,
|
219
|
+
_, _, _, shift_n,
|
220
|
+
reduce_n, * = arg
|
221
|
+
nerr = 0 # tmp
|
222
|
+
|
223
|
+
if act > 0 and act < shift_n
|
224
|
+
#
|
225
|
+
# shift
|
226
|
+
#
|
227
|
+
if @racc_error_status > 0
|
228
|
+
@racc_error_status -= 1 unless @racc_t == 1 # error token
|
229
|
+
end
|
230
|
+
@racc_vstack.push @racc_val
|
231
|
+
@racc_state.push act
|
232
|
+
@racc_read_next = true
|
233
|
+
if @yydebug
|
234
|
+
@racc_tstack.push @racc_t
|
235
|
+
racc_shift @racc_t, @racc_tstack, @racc_vstack
|
236
|
+
end
|
237
|
+
|
238
|
+
elsif act < 0 and act > -reduce_n
|
239
|
+
#
|
240
|
+
# reduce
|
241
|
+
#
|
242
|
+
code = catch(:racc_jump) {
|
243
|
+
@racc_state.push _racc_do_reduce(arg, act)
|
244
|
+
false
|
245
|
+
}
|
246
|
+
if code
|
247
|
+
case code
|
248
|
+
when 1 # yyerror
|
249
|
+
@racc_user_yyerror = true # user_yyerror
|
250
|
+
return -reduce_n
|
251
|
+
when 2 # yyaccept
|
252
|
+
return shift_n
|
253
|
+
else
|
254
|
+
raise '[Racc Bug] unknown jump code'
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
elsif act == shift_n
|
259
|
+
#
|
260
|
+
# accept
|
261
|
+
#
|
262
|
+
racc_accept if @yydebug
|
263
|
+
throw :racc_end_parse, @racc_vstack[0]
|
264
|
+
|
265
|
+
elsif act == -reduce_n
|
266
|
+
#
|
267
|
+
# error
|
268
|
+
#
|
269
|
+
case @racc_error_status
|
270
|
+
when 0
|
271
|
+
unless arg[21] # user_yyerror
|
272
|
+
nerr += 1
|
273
|
+
on_error @racc_t, @racc_val, @racc_vstack
|
274
|
+
end
|
275
|
+
when 3
|
276
|
+
if @racc_t == 0 # is $
|
277
|
+
throw :racc_end_parse, nil
|
278
|
+
end
|
279
|
+
@racc_read_next = true
|
280
|
+
end
|
281
|
+
@racc_user_yyerror = false
|
282
|
+
@racc_error_status = 3
|
283
|
+
while true
|
284
|
+
if i = action_pointer[@racc_state[-1]]
|
285
|
+
i += 1 # error token
|
286
|
+
if i >= 0 and
|
287
|
+
(act = action_table[i]) and
|
288
|
+
action_check[i] == @racc_state[-1]
|
289
|
+
break
|
290
|
+
end
|
291
|
+
end
|
292
|
+
throw :racc_end_parse, nil if @racc_state.size <= 1
|
293
|
+
@racc_state.pop
|
294
|
+
@racc_vstack.pop
|
295
|
+
if @yydebug
|
296
|
+
@racc_tstack.pop
|
297
|
+
racc_e_pop @racc_state, @racc_tstack, @racc_vstack
|
298
|
+
end
|
299
|
+
end
|
300
|
+
return act
|
301
|
+
|
302
|
+
else
|
303
|
+
raise "[Racc Bug] unknown action #{act.inspect}"
|
304
|
+
end
|
305
|
+
|
306
|
+
racc_next_state(@racc_state[-1], @racc_state) if @yydebug
|
307
|
+
|
308
|
+
nil
|
309
|
+
end
|
310
|
+
|
311
|
+
def _racc_do_reduce(arg, act)
|
312
|
+
_, _, _, _,
|
313
|
+
goto_table, goto_check, goto_default, goto_pointer,
|
314
|
+
nt_base, reduce_table, _, _,
|
315
|
+
_, use_result, * = arg
|
316
|
+
|
317
|
+
state = @racc_state
|
318
|
+
vstack = @racc_vstack
|
319
|
+
tstack = @racc_tstack
|
320
|
+
|
321
|
+
i = act * -3
|
322
|
+
len = reduce_table[i]
|
323
|
+
reduce_to = reduce_table[i+1]
|
324
|
+
method_id = reduce_table[i+2]
|
325
|
+
void_array = []
|
326
|
+
|
327
|
+
tmp_t = tstack[-len, len] if @yydebug
|
328
|
+
tmp_v = vstack[-len, len]
|
329
|
+
tstack[-len, len] = void_array if @yydebug
|
330
|
+
vstack[-len, len] = void_array
|
331
|
+
state[-len, len] = void_array
|
332
|
+
|
333
|
+
# tstack must be updated AFTER method call
|
334
|
+
if use_result
|
335
|
+
vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
|
336
|
+
else
|
337
|
+
vstack.push __send__(method_id, tmp_v, vstack)
|
338
|
+
end
|
339
|
+
tstack.push reduce_to
|
340
|
+
|
341
|
+
racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
|
342
|
+
|
343
|
+
k1 = reduce_to - nt_base
|
344
|
+
if i = goto_pointer[k1]
|
345
|
+
i += state[-1]
|
346
|
+
if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
|
347
|
+
return curstate
|
348
|
+
end
|
349
|
+
end
|
350
|
+
goto_default[k1]
|
351
|
+
end
|
352
|
+
|
353
|
+
def on_error(t, val, vstack)
|
354
|
+
raise ParseError, sprintf("\nparse error on value %s (%s)",
|
355
|
+
val.inspect, token_to_str(t) || '?')
|
356
|
+
end
|
357
|
+
|
358
|
+
def yyerror
|
359
|
+
throw :racc_jump, 1
|
360
|
+
end
|
361
|
+
|
362
|
+
def yyaccept
|
363
|
+
throw :racc_jump, 2
|
364
|
+
end
|
365
|
+
|
366
|
+
def yyerrok
|
367
|
+
@racc_error_status = 0
|
368
|
+
end
|
369
|
+
|
370
|
+
#
|
371
|
+
# for debugging output
|
372
|
+
#
|
373
|
+
|
374
|
+
def racc_read_token(t, tok, val)
|
375
|
+
@racc_debug_out.print 'read '
|
376
|
+
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
|
377
|
+
@racc_debug_out.puts val.inspect
|
378
|
+
@racc_debug_out.puts
|
379
|
+
end
|
380
|
+
|
381
|
+
def racc_shift(tok, tstack, vstack)
|
382
|
+
@racc_debug_out.puts "shift #{racc_token2str tok}"
|
383
|
+
racc_print_stacks tstack, vstack
|
384
|
+
@racc_debug_out.puts
|
385
|
+
end
|
386
|
+
|
387
|
+
def racc_reduce(toks, sim, tstack, vstack)
|
388
|
+
out = @racc_debug_out
|
389
|
+
out.print 'reduce '
|
390
|
+
if toks.empty?
|
391
|
+
out.print ' <none>'
|
392
|
+
else
|
393
|
+
toks.each {|t| out.print ' ', racc_token2str(t) }
|
394
|
+
end
|
395
|
+
out.puts " --> #{racc_token2str(sim)}"
|
396
|
+
|
397
|
+
racc_print_stacks tstack, vstack
|
398
|
+
@racc_debug_out.puts
|
399
|
+
end
|
400
|
+
|
401
|
+
def racc_accept
|
402
|
+
@racc_debug_out.puts 'accept'
|
403
|
+
@racc_debug_out.puts
|
404
|
+
end
|
405
|
+
|
406
|
+
def racc_e_pop(state, tstack, vstack)
|
407
|
+
@racc_debug_out.puts 'error recovering mode: pop token'
|
408
|
+
racc_print_states state
|
409
|
+
racc_print_stacks tstack, vstack
|
410
|
+
@racc_debug_out.puts
|
411
|
+
end
|
412
|
+
|
413
|
+
def racc_next_state(curstate, state)
|
414
|
+
@racc_debug_out.puts "goto #{curstate}"
|
415
|
+
racc_print_states state
|
416
|
+
@racc_debug_out.puts
|
417
|
+
end
|
418
|
+
|
419
|
+
def racc_print_stacks(t, v)
|
420
|
+
out = @racc_debug_out
|
421
|
+
out.print ' ['
|
422
|
+
t.each_index do |i|
|
423
|
+
out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
|
424
|
+
end
|
425
|
+
out.puts ' ]'
|
426
|
+
end
|
427
|
+
|
428
|
+
def racc_print_states(s)
|
429
|
+
out = @racc_debug_out
|
430
|
+
out.print ' ['
|
431
|
+
s.each {|st| out.print ' ', st }
|
432
|
+
out.puts ' ]'
|
433
|
+
end
|
434
|
+
|
435
|
+
def racc_token2str(tok)
|
436
|
+
self.class::Racc_token_to_s_table[tok] or
|
437
|
+
raise "[Racc Bug] can't convert token #{tok} to string"
|
438
|
+
end
|
439
|
+
|
440
|
+
def token_to_str(t)
|
441
|
+
self.class::Racc_token_to_s_table[t]
|
442
|
+
end
|
443
|
+
|
444
|
+
end
|
445
|
+
|
446
|
+
end
|
447
|
+
|
448
|
+
...end racc/parser.rb/module_eval...
|
449
|
+
end
|
450
|
+
###### racc/parser.rb end
|
451
|
+
|
452
|
+
|
453
|
+
require 'abnf/grammar'
|
454
|
+
|
455
|
+
class ABNF
|
456
|
+
def ABNF.parse(desc, dont_merge_core_rules=false)
|
457
|
+
grammar = ABNF.new
|
458
|
+
Parser.new(grammar).parse(desc)
|
459
|
+
grammar.merge(CoreRules) unless dont_merge_core_rules
|
460
|
+
grammar
|
461
|
+
end
|
462
|
+
|
463
|
+
class Parser < Racc::Parser
|
464
|
+
|
465
|
+
module_eval(<<'...end parser.y/module_eval...', 'parser.y', 48)
|
466
|
+
|
467
|
+
def initialize(grammar)
|
468
|
+
@grammar = grammar
|
469
|
+
end
|
470
|
+
|
471
|
+
def parse(input)
|
472
|
+
@input = input
|
473
|
+
yyparse self, :scan
|
474
|
+
end
|
475
|
+
|
476
|
+
def scan
|
477
|
+
prev = nil
|
478
|
+
scan1 do |toktype, tokval|
|
479
|
+
if prev
|
480
|
+
if prev[0] == :name && toktype == :assign
|
481
|
+
yield [:defname, prev[1]]
|
482
|
+
else
|
483
|
+
yield prev
|
484
|
+
end
|
485
|
+
end
|
486
|
+
prev = [toktype, tokval]
|
487
|
+
end
|
488
|
+
yield prev
|
489
|
+
end
|
490
|
+
|
491
|
+
def scan1
|
492
|
+
@input.each_line {|line|
|
493
|
+
until line.empty?
|
494
|
+
case line
|
495
|
+
when /\A[ \t\r\n]+/
|
496
|
+
t = $&
|
497
|
+
when /\A;/
|
498
|
+
t = line
|
499
|
+
when /\A[A-Za-z][A-Za-z0-9\-_]*/ # _ is not permitted by ABNF
|
500
|
+
yield :name, (t = $&).downcase.intern
|
501
|
+
when /\A=\/?/
|
502
|
+
yield :assign, (t = $&) # | is not permitted by ABNF
|
503
|
+
when /\A[\/|]/
|
504
|
+
yield :altop, (t = $&)
|
505
|
+
when /\A\*/
|
506
|
+
yield :repop, (t = $&)
|
507
|
+
when /\A\(/
|
508
|
+
yield :lparen, (t = $&)
|
509
|
+
when /\A\)/
|
510
|
+
yield :rparen, (t = $&)
|
511
|
+
when /\A\[/
|
512
|
+
yield :lbracket, (t = $&)
|
513
|
+
when /\A\]/
|
514
|
+
yield :rbracket, (t = $&)
|
515
|
+
when /\A\d+/
|
516
|
+
yield :int, (t = $&).to_i
|
517
|
+
when /\A"([ !#-~]*)"/
|
518
|
+
es = []
|
519
|
+
(t = $&)[1...-1].each_byte {|b|
|
520
|
+
case b
|
521
|
+
when 0x41..0x5a # ?A..?Z
|
522
|
+
b2 = b - 0x41 + 0x61 # ?A + ?a
|
523
|
+
es << Term.new(NatSet.new(b, b2))
|
524
|
+
when 0x61..0x7a # ?a..?z
|
525
|
+
b2 = b - 0x61 + 0x41 # ?a + ?A
|
526
|
+
es << Term.new(NatSet.new(b, b2))
|
527
|
+
else
|
528
|
+
es << Term.new(NatSet.new(b))
|
529
|
+
end
|
530
|
+
}
|
531
|
+
yield :val, Seq.new(*es)
|
532
|
+
when /\A%b([01]+)-([01]+)/
|
533
|
+
t = $&
|
534
|
+
yield :val, Term.new(NatSet.new($1.to_i(2)..$2.to_i(2)))
|
535
|
+
when /\A%b[01]+(?:\.[01]+)*/
|
536
|
+
es = []
|
537
|
+
(t = $&).scan(/[0-1]+/) {|v|
|
538
|
+
es << Term.new(NatSet.new(v.to_i(2)))
|
539
|
+
}
|
540
|
+
yield :val, Seq.new(*es)
|
541
|
+
when /\A%d([0-9]+)-([0-9]+)/
|
542
|
+
t = $&
|
543
|
+
yield :val, Term.new(NatSet.new($1.to_i..$2.to_i))
|
544
|
+
when /\A%d[0-9]+(?:\.[0-9]+)*/
|
545
|
+
es = []
|
546
|
+
(t = $&).scan(/[0-9]+/) {|v|
|
547
|
+
es << Term.new(NatSet.new(v.to_i))
|
548
|
+
}
|
549
|
+
yield :val, Seq.new(*es)
|
550
|
+
when /\A%x([0-9A-Fa-f]+)-([0-9A-Fa-f]+)/
|
551
|
+
t = $&
|
552
|
+
yield :val, Term.new(NatSet.new($1.hex..$2.hex))
|
553
|
+
when /\A%x[0-9A-Fa-f]+(?:\.[0-9A-Fa-f]+)*/
|
554
|
+
es = []
|
555
|
+
(t = $&).scan(/[0-9A-Fa-f]+/) {|v|
|
556
|
+
es << Term.new(NatSet.new(v.hex))
|
557
|
+
}
|
558
|
+
yield :val, Seq.new(*es)
|
559
|
+
when /\A<([\x20-\x3D\x3F-\x7E]*)>/
|
560
|
+
raise ScanError.new("prose-val is not supported: #{$&}")
|
561
|
+
else
|
562
|
+
raise ScanError.new(line)
|
563
|
+
end
|
564
|
+
line[0, t.length] = ''
|
565
|
+
end
|
566
|
+
}
|
567
|
+
yield false, false
|
568
|
+
end
|
569
|
+
|
570
|
+
class ScanError < StandardError
|
571
|
+
end
|
572
|
+
|
573
|
+
...end parser.y/module_eval...
|
574
|
+
##### State transition tables begin ###
|
575
|
+
|
576
|
+
racc_action_table = [
|
577
|
+
12, 13, 14, 15, 18, 16, 2, 17, 4, 21,
|
578
|
+
18, 28, 12, 13, 14, 15, 26, 16, 6, 17,
|
579
|
+
12, 13, 14, 15, 5, 16, 22, 17, 12, 13,
|
580
|
+
14, 15, nil, 16, nil, 17, 12, 13, 14, 15,
|
581
|
+
nil, 16, nil, 17, 12, 13, 14, 15, nil, 16,
|
582
|
+
nil, 17, 14, 15, 18, 16, nil, 17, nil, 27 ]
|
583
|
+
|
584
|
+
racc_action_check = [
|
585
|
+
25, 25, 25, 25, 24, 25, 1, 25, 1, 12,
|
586
|
+
7, 24, 15, 15, 15, 15, 22, 15, 4, 15,
|
587
|
+
6, 6, 6, 6, 2, 6, 13, 6, 16, 16,
|
588
|
+
16, 16, nil, 16, nil, 16, 8, 8, 8, 8,
|
589
|
+
nil, 8, nil, 8, 18, 18, 18, 18, nil, 18,
|
590
|
+
nil, 18, 11, 11, 23, 11, nil, 11, nil, 23 ]
|
591
|
+
|
592
|
+
racc_action_pointer = [
|
593
|
+
nil, 6, 24, nil, 15, nil, 15, 6, 31, nil,
|
594
|
+
nil, 45, 3, 21, nil, 7, 23, nil, 39, nil,
|
595
|
+
nil, nil, 10, 50, 0, -5, nil, nil, nil ]
|
596
|
+
|
597
|
+
racc_action_default = [
|
598
|
+
-1, -19, -19, -2, -19, 29, -19, -3, -4, -6,
|
599
|
+
-8, -19, -10, -12, -15, -19, -19, -18, -19, -7,
|
600
|
+
-9, -11, -13, -19, -19, -5, -14, -16, -17 ]
|
601
|
+
|
602
|
+
racc_goto_table = [
|
603
|
+
19, 7, 25, 1, 3, 20, nil, nil, nil, nil,
|
604
|
+
23, 24, nil, nil, nil, nil, nil, 19 ]
|
605
|
+
|
606
|
+
racc_goto_check = [
|
607
|
+
5, 3, 4, 1, 2, 6, nil, nil, nil, nil,
|
608
|
+
3, 3, nil, nil, nil, nil, nil, 5 ]
|
609
|
+
|
610
|
+
racc_goto_pointer = [
|
611
|
+
nil, 3, 3, -5, -16, -8, -6, nil ]
|
612
|
+
|
613
|
+
racc_goto_default = [
|
614
|
+
nil, nil, nil, nil, 8, 9, 10, 11 ]
|
615
|
+
|
616
|
+
racc_reduce_table = [
|
617
|
+
0, 0, :racc_error,
|
618
|
+
0, 14, :_reduce_1,
|
619
|
+
2, 14, :_reduce_2,
|
620
|
+
3, 15, :_reduce_3,
|
621
|
+
1, 16, :_reduce_none,
|
622
|
+
3, 16, :_reduce_5,
|
623
|
+
1, 17, :_reduce_none,
|
624
|
+
2, 17, :_reduce_7,
|
625
|
+
1, 18, :_reduce_none,
|
626
|
+
2, 18, :_reduce_9,
|
627
|
+
1, 20, :_reduce_10,
|
628
|
+
2, 20, :_reduce_11,
|
629
|
+
1, 20, :_reduce_12,
|
630
|
+
2, 20, :_reduce_13,
|
631
|
+
3, 20, :_reduce_14,
|
632
|
+
1, 19, :_reduce_15,
|
633
|
+
3, 19, :_reduce_16,
|
634
|
+
3, 19, :_reduce_17,
|
635
|
+
1, 19, :_reduce_none ]
|
636
|
+
|
637
|
+
racc_reduce_n = 19
|
638
|
+
|
639
|
+
racc_shift_n = 29
|
640
|
+
|
641
|
+
racc_token_table = {
|
642
|
+
false => 0,
|
643
|
+
:error => 1,
|
644
|
+
:defname => 2,
|
645
|
+
:assign => 3,
|
646
|
+
:altop => 4,
|
647
|
+
:repop => 5,
|
648
|
+
:int => 6,
|
649
|
+
:name => 7,
|
650
|
+
:lparen => 8,
|
651
|
+
:rparen => 9,
|
652
|
+
:lbracket => 10,
|
653
|
+
:rbracket => 11,
|
654
|
+
:val => 12 }
|
655
|
+
|
656
|
+
racc_nt_base = 13
|
657
|
+
|
658
|
+
racc_use_result_var = true
|
659
|
+
|
660
|
+
Racc_arg = [
|
661
|
+
racc_action_table,
|
662
|
+
racc_action_check,
|
663
|
+
racc_action_default,
|
664
|
+
racc_action_pointer,
|
665
|
+
racc_goto_table,
|
666
|
+
racc_goto_check,
|
667
|
+
racc_goto_default,
|
668
|
+
racc_goto_pointer,
|
669
|
+
racc_nt_base,
|
670
|
+
racc_reduce_table,
|
671
|
+
racc_token_table,
|
672
|
+
racc_shift_n,
|
673
|
+
racc_reduce_n,
|
674
|
+
racc_use_result_var ]
|
675
|
+
|
676
|
+
Racc_token_to_s_table = [
|
677
|
+
"$end",
|
678
|
+
"error",
|
679
|
+
"defname",
|
680
|
+
"assign",
|
681
|
+
"altop",
|
682
|
+
"repop",
|
683
|
+
"int",
|
684
|
+
"name",
|
685
|
+
"lparen",
|
686
|
+
"rparen",
|
687
|
+
"lbracket",
|
688
|
+
"rbracket",
|
689
|
+
"val",
|
690
|
+
"$start",
|
691
|
+
"rulelist",
|
692
|
+
"rule",
|
693
|
+
"alt",
|
694
|
+
"seq",
|
695
|
+
"rep",
|
696
|
+
"element",
|
697
|
+
"repeat" ]
|
698
|
+
|
699
|
+
Racc_debug_parser = false
|
700
|
+
|
701
|
+
##### State transition tables end #####
|
702
|
+
|
703
|
+
# reduce 0 omitted
|
704
|
+
|
705
|
+
module_eval(<<'.,.,', 'parser.y', 3)
|
706
|
+
def _reduce_1(val, _values, result)
|
707
|
+
result = nil
|
708
|
+
result
|
709
|
+
end
|
710
|
+
.,.,
|
711
|
+
|
712
|
+
module_eval(<<'.,.,', 'parser.y', 5)
|
713
|
+
def _reduce_2(val, _values, result)
|
714
|
+
name = val[1][0]
|
715
|
+
rhs = val[1][1]
|
716
|
+
@grammar.add(name, rhs)
|
717
|
+
result ||= name
|
718
|
+
|
719
|
+
result
|
720
|
+
end
|
721
|
+
.,.,
|
722
|
+
|
723
|
+
module_eval(<<'.,.,', 'parser.y', 11)
|
724
|
+
def _reduce_3(val, _values, result)
|
725
|
+
result = [val[0], val[2]]
|
726
|
+
result
|
727
|
+
end
|
728
|
+
.,.,
|
729
|
+
|
730
|
+
# reduce 4 omitted
|
731
|
+
|
732
|
+
module_eval(<<'.,.,', 'parser.y', 14)
|
733
|
+
def _reduce_5(val, _values, result)
|
734
|
+
result = val[0] | val[2]
|
735
|
+
result
|
736
|
+
end
|
737
|
+
.,.,
|
738
|
+
|
739
|
+
# reduce 6 omitted
|
740
|
+
|
741
|
+
module_eval(<<'.,.,', 'parser.y', 17)
|
742
|
+
def _reduce_7(val, _values, result)
|
743
|
+
result = val[0] + val[1]
|
744
|
+
result
|
745
|
+
end
|
746
|
+
.,.,
|
747
|
+
|
748
|
+
# reduce 8 omitted
|
749
|
+
|
750
|
+
module_eval(<<'.,.,', 'parser.y', 20)
|
751
|
+
def _reduce_9(val, _values, result)
|
752
|
+
result = val[1].rep(*val[0])
|
753
|
+
result
|
754
|
+
end
|
755
|
+
.,.,
|
756
|
+
|
757
|
+
module_eval(<<'.,.,', 'parser.y', 22)
|
758
|
+
def _reduce_10(val, _values, result)
|
759
|
+
result = [0, nil]
|
760
|
+
result
|
761
|
+
end
|
762
|
+
.,.,
|
763
|
+
|
764
|
+
module_eval(<<'.,.,', 'parser.y', 23)
|
765
|
+
def _reduce_11(val, _values, result)
|
766
|
+
result = [0, val[1]]
|
767
|
+
result
|
768
|
+
end
|
769
|
+
.,.,
|
770
|
+
|
771
|
+
module_eval(<<'.,.,', 'parser.y', 24)
|
772
|
+
def _reduce_12(val, _values, result)
|
773
|
+
result = [val[0], val[0]]
|
774
|
+
result
|
775
|
+
end
|
776
|
+
.,.,
|
777
|
+
|
778
|
+
module_eval(<<'.,.,', 'parser.y', 25)
|
779
|
+
def _reduce_13(val, _values, result)
|
780
|
+
result = [val[0], nil]
|
781
|
+
result
|
782
|
+
end
|
783
|
+
.,.,
|
784
|
+
|
785
|
+
module_eval(<<'.,.,', 'parser.y', 26)
|
786
|
+
def _reduce_14(val, _values, result)
|
787
|
+
result = [val[0], val[2]]
|
788
|
+
result
|
789
|
+
end
|
790
|
+
.,.,
|
791
|
+
|
792
|
+
module_eval(<<'.,.,', 'parser.y', 28)
|
793
|
+
def _reduce_15(val, _values, result)
|
794
|
+
result = Var.new(val[0])
|
795
|
+
result
|
796
|
+
end
|
797
|
+
.,.,
|
798
|
+
|
799
|
+
module_eval(<<'.,.,', 'parser.y', 29)
|
800
|
+
def _reduce_16(val, _values, result)
|
801
|
+
result = val[1]
|
802
|
+
result
|
803
|
+
end
|
804
|
+
.,.,
|
805
|
+
|
806
|
+
module_eval(<<'.,.,', 'parser.y', 30)
|
807
|
+
def _reduce_17(val, _values, result)
|
808
|
+
result = val[1].rep(0, 1)
|
809
|
+
result
|
810
|
+
end
|
811
|
+
.,.,
|
812
|
+
|
813
|
+
# reduce 18 omitted
|
814
|
+
|
815
|
+
def _reduce_none(val, _values, result)
|
816
|
+
val[0]
|
817
|
+
end
|
818
|
+
|
819
|
+
end # class Parser
|
820
|
+
|
821
|
+
end
|