ed-precompiled_racc 1.8.1

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.
@@ -0,0 +1,496 @@
1
+ # :stopdoc:
2
+ module Racc
3
+ PARSER_TEXT = <<'__end_of_file__'
4
+ #--
5
+ # Copyright (c) 1999-2006 Minero Aoki
6
+ #
7
+ # This program is free software.
8
+ # You can distribute/modify this program under the same terms of ruby.
9
+ #
10
+ # As a special exception, when this code is copied by Racc
11
+ # into a Racc output file, you may use that output file
12
+ # without restriction.
13
+ #++
14
+
15
+ unless $".find {|p| p.end_with?('/racc/info.rb')}
16
+ $".push "#{__dir__}/racc/info.rb"
17
+
18
+ module Racc
19
+ VERSION = '1.8.1'
20
+ Version = VERSION
21
+ Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
22
+ end
23
+
24
+ end
25
+
26
+
27
+ module Racc
28
+ class ParseError < StandardError; end
29
+ end
30
+ unless defined?(::ParseError)
31
+ ParseError = Racc::ParseError # :nodoc:
32
+ end
33
+
34
+ #--
35
+ module Racc
36
+
37
+ unless defined?(Racc_No_Extensions)
38
+ Racc_No_Extensions = false # :nodoc:
39
+ end
40
+
41
+ class Parser
42
+
43
+ Racc_Runtime_Version = ::Racc::VERSION
44
+ Racc_Runtime_Core_Version_R = ::Racc::VERSION
45
+
46
+ begin
47
+ if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
48
+ require 'jruby'
49
+ require 'racc/cparse-jruby.jar'
50
+ com.headius.racc.Cparse.new.load(JRuby.runtime, false)
51
+ else
52
+ begin
53
+ ruby_version = /(\d+\.\d+)/.match(::RUBY_VERSION)
54
+ require "racc/#{ruby_version}/cparse"
55
+ rescue LoadError
56
+ require 'racc/cparse'
57
+ end
58
+ end
59
+
60
+ unless new.respond_to?(:_racc_do_parse_c, true)
61
+ raise LoadError, 'old cparse.so'
62
+ end
63
+ if Racc_No_Extensions
64
+ raise LoadError, 'selecting ruby version of racc runtime core'
65
+ end
66
+
67
+ Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
68
+ Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
69
+ Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
70
+ Racc_Runtime_Type = 'c' # :nodoc:
71
+ rescue LoadError
72
+ Racc_Main_Parsing_Routine = :_racc_do_parse_rb
73
+ Racc_YY_Parse_Method = :_racc_yyparse_rb
74
+ Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
75
+ Racc_Runtime_Type = 'ruby'
76
+ end
77
+
78
+ def Parser.racc_runtime_type # :nodoc:
79
+ Racc_Runtime_Type
80
+ end
81
+
82
+ def _racc_setup
83
+ @yydebug = false unless self.class::Racc_debug_parser
84
+ @yydebug = false unless defined?(@yydebug)
85
+ if @yydebug
86
+ @racc_debug_out = $stderr unless defined?(@racc_debug_out)
87
+ @racc_debug_out ||= $stderr
88
+ end
89
+ arg = self.class::Racc_arg
90
+ arg[13] = true if arg.size < 14
91
+ arg
92
+ end
93
+
94
+ def _racc_init_sysvars
95
+ @racc_state = [0]
96
+ @racc_tstack = []
97
+ @racc_vstack = []
98
+
99
+ @racc_t = nil
100
+ @racc_val = nil
101
+
102
+ @racc_read_next = true
103
+
104
+ @racc_user_yyerror = false
105
+ @racc_error_status = 0
106
+ end
107
+
108
+ # The entry point of the parser. This method is used with #next_token.
109
+ # If Racc wants to get token (and its value), calls next_token.
110
+ #
111
+ # Example:
112
+ # def parse
113
+ # @q = [[1,1],
114
+ # [2,2],
115
+ # [3,3],
116
+ # [false, '$']]
117
+ # do_parse
118
+ # end
119
+ #
120
+ # def next_token
121
+ # @q.shift
122
+ # end
123
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
124
+ def do_parse
125
+ #{Racc_Main_Parsing_Routine}(_racc_setup(), false)
126
+ end
127
+ RUBY
128
+
129
+ # The method to fetch next token.
130
+ # If you use #do_parse method, you must implement #next_token.
131
+ #
132
+ # The format of return value is [TOKEN_SYMBOL, VALUE].
133
+ # +token-symbol+ is represented by Ruby's symbol by default, e.g. :IDENT
134
+ # for 'IDENT'. ";" (String) for ';'.
135
+ #
136
+ # The final symbol (End of file) must be false.
137
+ def next_token
138
+ raise NotImplementedError, "#{self.class}\#next_token is not defined"
139
+ end
140
+
141
+ def _racc_do_parse_rb(arg, in_debug)
142
+ action_table, action_check, action_default, action_pointer,
143
+ _, _, _, _,
144
+ _, _, token_table, * = arg
145
+
146
+ _racc_init_sysvars
147
+ tok = act = i = nil
148
+
149
+ catch(:racc_end_parse) {
150
+ while true
151
+ if i = action_pointer[@racc_state[-1]]
152
+ if @racc_read_next
153
+ if @racc_t != 0 # not EOF
154
+ tok, @racc_val = next_token()
155
+ unless tok # EOF
156
+ @racc_t = 0
157
+ else
158
+ @racc_t = (token_table[tok] or 1) # error token
159
+ end
160
+ racc_read_token(@racc_t, tok, @racc_val) if @yydebug
161
+ @racc_read_next = false
162
+ end
163
+ end
164
+ i += @racc_t
165
+ unless i >= 0 and
166
+ act = action_table[i] and
167
+ action_check[i] == @racc_state[-1]
168
+ act = action_default[@racc_state[-1]]
169
+ end
170
+ else
171
+ act = action_default[@racc_state[-1]]
172
+ end
173
+ while act = _racc_evalact(act, arg)
174
+ ;
175
+ end
176
+ end
177
+ }
178
+ end
179
+
180
+ # Another entry point for the parser.
181
+ # If you use this method, you must implement RECEIVER#METHOD_ID method.
182
+ #
183
+ # RECEIVER#METHOD_ID is a method to get next token.
184
+ # It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
185
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
186
+ def yyparse(recv, mid)
187
+ #{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), false)
188
+ end
189
+ RUBY
190
+
191
+ def _racc_yyparse_rb(recv, mid, arg, c_debug)
192
+ action_table, action_check, action_default, action_pointer,
193
+ _, _, _, _,
194
+ _, _, token_table, * = arg
195
+
196
+ _racc_init_sysvars
197
+
198
+ catch(:racc_end_parse) {
199
+ until i = action_pointer[@racc_state[-1]]
200
+ while act = _racc_evalact(action_default[@racc_state[-1]], arg)
201
+ ;
202
+ end
203
+ end
204
+ recv.__send__(mid) do |tok, val|
205
+ unless tok
206
+ @racc_t = 0
207
+ else
208
+ @racc_t = (token_table[tok] or 1) # error token
209
+ end
210
+ @racc_val = val
211
+ @racc_read_next = false
212
+
213
+ i += @racc_t
214
+ unless i >= 0 and
215
+ act = action_table[i] and
216
+ action_check[i] == @racc_state[-1]
217
+ act = action_default[@racc_state[-1]]
218
+ end
219
+ while act = _racc_evalact(act, arg)
220
+ ;
221
+ end
222
+
223
+ while !(i = action_pointer[@racc_state[-1]]) ||
224
+ ! @racc_read_next ||
225
+ @racc_t == 0 # $
226
+ unless i and i += @racc_t and
227
+ i >= 0 and
228
+ act = action_table[i] and
229
+ action_check[i] == @racc_state[-1]
230
+ act = action_default[@racc_state[-1]]
231
+ end
232
+ while act = _racc_evalact(act, arg)
233
+ ;
234
+ end
235
+ end
236
+ end
237
+ }
238
+ end
239
+
240
+ ###
241
+ ### common
242
+ ###
243
+
244
+ def _racc_evalact(act, arg)
245
+ action_table, action_check, _, action_pointer,
246
+ _, _, _, _,
247
+ _, _, _, shift_n,
248
+ reduce_n, * = arg
249
+ nerr = 0 # tmp
250
+
251
+ if act > 0 and act < shift_n
252
+ #
253
+ # shift
254
+ #
255
+ if @racc_error_status > 0
256
+ @racc_error_status -= 1 unless @racc_t <= 1 # error token or EOF
257
+ end
258
+ @racc_vstack.push @racc_val
259
+ @racc_state.push act
260
+ @racc_read_next = true
261
+ if @yydebug
262
+ @racc_tstack.push @racc_t
263
+ racc_shift @racc_t, @racc_tstack, @racc_vstack
264
+ end
265
+
266
+ elsif act < 0 and act > -reduce_n
267
+ #
268
+ # reduce
269
+ #
270
+ code = catch(:racc_jump) {
271
+ @racc_state.push _racc_do_reduce(arg, act)
272
+ false
273
+ }
274
+ if code
275
+ case code
276
+ when 1 # yyerror
277
+ @racc_user_yyerror = true # user_yyerror
278
+ return -reduce_n
279
+ when 2 # yyaccept
280
+ return shift_n
281
+ else
282
+ raise '[Racc Bug] unknown jump code'
283
+ end
284
+ end
285
+
286
+ elsif act == shift_n
287
+ #
288
+ # accept
289
+ #
290
+ racc_accept if @yydebug
291
+ throw :racc_end_parse, @racc_vstack[0]
292
+
293
+ elsif act == -reduce_n
294
+ #
295
+ # error
296
+ #
297
+ case @racc_error_status
298
+ when 0
299
+ unless arg[21] # user_yyerror
300
+ nerr += 1
301
+ on_error @racc_t, @racc_val, @racc_vstack
302
+ end
303
+ when 3
304
+ if @racc_t == 0 # is $
305
+ # We're at EOF, and another error occurred immediately after
306
+ # attempting auto-recovery
307
+ throw :racc_end_parse, nil
308
+ end
309
+ @racc_read_next = true
310
+ end
311
+ @racc_user_yyerror = false
312
+ @racc_error_status = 3
313
+ while true
314
+ if i = action_pointer[@racc_state[-1]]
315
+ i += 1 # error token
316
+ if i >= 0 and
317
+ (act = action_table[i]) and
318
+ action_check[i] == @racc_state[-1]
319
+ break
320
+ end
321
+ end
322
+ throw :racc_end_parse, nil if @racc_state.size <= 1
323
+ @racc_state.pop
324
+ @racc_vstack.pop
325
+ if @yydebug
326
+ @racc_tstack.pop
327
+ racc_e_pop @racc_state, @racc_tstack, @racc_vstack
328
+ end
329
+ end
330
+ return act
331
+
332
+ else
333
+ raise "[Racc Bug] unknown action #{act.inspect}"
334
+ end
335
+
336
+ racc_next_state(@racc_state[-1], @racc_state) if @yydebug
337
+
338
+ nil
339
+ end
340
+
341
+ def _racc_do_reduce(arg, act)
342
+ _, _, _, _,
343
+ goto_table, goto_check, goto_default, goto_pointer,
344
+ nt_base, reduce_table, _, _,
345
+ _, use_result, * = arg
346
+
347
+ state = @racc_state
348
+ vstack = @racc_vstack
349
+ tstack = @racc_tstack
350
+
351
+ i = act * -3
352
+ len = reduce_table[i]
353
+ reduce_to = reduce_table[i+1]
354
+ method_id = reduce_table[i+2]
355
+ void_array = []
356
+
357
+ tmp_t = tstack[-len, len] if @yydebug
358
+ tmp_v = vstack[-len, len]
359
+ tstack[-len, len] = void_array if @yydebug
360
+ vstack[-len, len] = void_array
361
+ state[-len, len] = void_array
362
+
363
+ # tstack must be updated AFTER method call
364
+ if use_result
365
+ vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
366
+ else
367
+ vstack.push __send__(method_id, tmp_v, vstack)
368
+ end
369
+ tstack.push reduce_to
370
+
371
+ racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
372
+
373
+ k1 = reduce_to - nt_base
374
+ if i = goto_pointer[k1]
375
+ i += state[-1]
376
+ if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
377
+ return curstate
378
+ end
379
+ end
380
+ goto_default[k1]
381
+ end
382
+
383
+ # This method is called when a parse error is found.
384
+ #
385
+ # ERROR_TOKEN_ID is an internal ID of token which caused error.
386
+ # You can get string representation of this ID by calling
387
+ # #token_to_str.
388
+ #
389
+ # ERROR_VALUE is a value of error token.
390
+ #
391
+ # value_stack is a stack of symbol values.
392
+ # DO NOT MODIFY this object.
393
+ #
394
+ # This method raises ParseError by default.
395
+ #
396
+ # If this method returns, parsers enter "error recovering mode".
397
+ def on_error(t, val, vstack)
398
+ raise ParseError, sprintf("parse error on value %s (%s)",
399
+ val.inspect, token_to_str(t) || '?')
400
+ end
401
+
402
+ # Enter error recovering mode.
403
+ # This method does not call #on_error.
404
+ def yyerror
405
+ throw :racc_jump, 1
406
+ end
407
+
408
+ # Exit parser.
409
+ # Return value is +Symbol_Value_Stack[0]+.
410
+ def yyaccept
411
+ throw :racc_jump, 2
412
+ end
413
+
414
+ # Leave error recovering mode.
415
+ def yyerrok
416
+ @racc_error_status = 0
417
+ end
418
+
419
+ # For debugging output
420
+ def racc_read_token(t, tok, val)
421
+ @racc_debug_out.print 'read '
422
+ @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
423
+ @racc_debug_out.puts val.inspect
424
+ @racc_debug_out.puts
425
+ end
426
+
427
+ def racc_shift(tok, tstack, vstack)
428
+ @racc_debug_out.puts "shift #{racc_token2str tok}"
429
+ racc_print_stacks tstack, vstack
430
+ @racc_debug_out.puts
431
+ end
432
+
433
+ def racc_reduce(toks, sim, tstack, vstack)
434
+ out = @racc_debug_out
435
+ out.print 'reduce '
436
+ if toks.empty?
437
+ out.print ' <none>'
438
+ else
439
+ toks.each {|t| out.print ' ', racc_token2str(t) }
440
+ end
441
+ out.puts " --> #{racc_token2str(sim)}"
442
+ racc_print_stacks tstack, vstack
443
+ @racc_debug_out.puts
444
+ end
445
+
446
+ def racc_accept
447
+ @racc_debug_out.puts 'accept'
448
+ @racc_debug_out.puts
449
+ end
450
+
451
+ def racc_e_pop(state, tstack, vstack)
452
+ @racc_debug_out.puts 'error recovering mode: pop token'
453
+ racc_print_states state
454
+ racc_print_stacks tstack, vstack
455
+ @racc_debug_out.puts
456
+ end
457
+
458
+ def racc_next_state(curstate, state)
459
+ @racc_debug_out.puts "goto #{curstate}"
460
+ racc_print_states state
461
+ @racc_debug_out.puts
462
+ end
463
+
464
+ def racc_print_stacks(t, v)
465
+ out = @racc_debug_out
466
+ out.print ' ['
467
+ t.each_index do |i|
468
+ out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
469
+ end
470
+ out.puts ' ]'
471
+ end
472
+
473
+ def racc_print_states(s)
474
+ out = @racc_debug_out
475
+ out.print ' ['
476
+ s.each {|st| out.print ' ', st }
477
+ out.puts ' ]'
478
+ end
479
+
480
+ def racc_token2str(tok)
481
+ self.class::Racc_token_to_s_table[tok] or
482
+ raise "[Racc Bug] can't convert token #{tok} to string"
483
+ end
484
+
485
+ # Convert internal ID of token symbol to the string.
486
+ def token_to_str(t)
487
+ self.class::Racc_token_to_s_table[t]
488
+ end
489
+
490
+ end
491
+
492
+ end
493
+ #++
494
+
495
+ __end_of_file__
496
+ end