predicator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +5 -0
- data/Rakefile +1 -1
- data/lib/predicator/generated_parser.rb +1 -643
- data/lib/predicator/version.rb +1 -1
- data/predicator.gemspec +2 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a87a8988a480ba91dc3ad663aeb1872090fb990
|
4
|
+
data.tar.gz: 34864ab0127fa7a2ad982cce7c19db395286bf19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb875d918d6fe7c3c4dae604a2d22140fac792c5c34cf0cd403250ac2247cd8ac7c1abf0f3fba1ce972952637f1c929d8bf83cbe99b70bedce67fe190e9c06b0
|
7
|
+
data.tar.gz: 216d1f6ae575f00b6762d1683c376725cd374970abd3294cdd994440c3e41a33edea691e67c8180cd93ebf4247fc283490a3222b95ac88f2be51b732bc8a4602
|
data/HISTORY.md
CHANGED
data/Rakefile
CHANGED
@@ -4,649 +4,7 @@
|
|
4
4
|
# from Racc grammer file "".
|
5
5
|
#
|
6
6
|
|
7
|
-
|
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: 2bd697d1146b280d8d3878e21e556ef769484a37 $
|
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
|
-
require 'racc/info'
|
25
|
-
|
26
|
-
unless defined?(NotImplementedError)
|
27
|
-
NotImplementedError = NotImplementError # :nodoc:
|
28
|
-
end
|
29
|
-
|
30
|
-
module Racc
|
31
|
-
class ParseError < StandardError; end
|
32
|
-
end
|
33
|
-
unless defined?(::ParseError)
|
34
|
-
ParseError = Racc::ParseError
|
35
|
-
end
|
36
|
-
|
37
|
-
# Racc is a LALR(1) parser generator.
|
38
|
-
# It is written in Ruby itself, and generates Ruby programs.
|
39
|
-
#
|
40
|
-
# == Command-line Reference
|
41
|
-
#
|
42
|
-
# racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
|
43
|
-
# [-e<var>rubypath</var>] [--embedded=<var>rubypath</var>]
|
44
|
-
# [-v] [--verbose]
|
45
|
-
# [-O<var>filename</var>] [--log-file=<var>filename</var>]
|
46
|
-
# [-g] [--debug]
|
47
|
-
# [-E] [--embedded]
|
48
|
-
# [-l] [--no-line-convert]
|
49
|
-
# [-c] [--line-convert-all]
|
50
|
-
# [-a] [--no-omit-actions]
|
51
|
-
# [-C] [--check-only]
|
52
|
-
# [-S] [--output-status]
|
53
|
-
# [--version] [--copyright] [--help] <var>grammarfile</var>
|
54
|
-
#
|
55
|
-
# [+filename+]
|
56
|
-
# Racc grammar file. Any extention is permitted.
|
57
|
-
# [-o+outfile+, --output-file=+outfile+]
|
58
|
-
# A filename for output. default is <+filename+>.tab.rb
|
59
|
-
# [-O+filename+, --log-file=+filename+]
|
60
|
-
# Place logging output in file +filename+.
|
61
|
-
# Default log file name is <+filename+>.output.
|
62
|
-
# [-e+rubypath+, --executable=+rubypath+]
|
63
|
-
# output executable file(mode 755). where +path+ is the Ruby interpreter.
|
64
|
-
# [-v, --verbose]
|
65
|
-
# verbose mode. create +filename+.output file, like yacc's y.output file.
|
66
|
-
# [-g, --debug]
|
67
|
-
# add debug code to parser class. To display debuggin information,
|
68
|
-
# use this '-g' option and set @yydebug true in parser class.
|
69
|
-
# [-E, --embedded]
|
70
|
-
# Output parser which doesn't need runtime files (racc/parser.rb).
|
71
|
-
# [-C, --check-only]
|
72
|
-
# Check syntax of racc grammer file and quit.
|
73
|
-
# [-S, --output-status]
|
74
|
-
# Print messages time to time while compiling.
|
75
|
-
# [-l, --no-line-convert]
|
76
|
-
# turns off line number converting.
|
77
|
-
# [-c, --line-convert-all]
|
78
|
-
# Convert line number of actions, inner, header and footer.
|
79
|
-
# [-a, --no-omit-actions]
|
80
|
-
# Call all actions, even if an action is empty.
|
81
|
-
# [--version]
|
82
|
-
# print Racc version and quit.
|
83
|
-
# [--copyright]
|
84
|
-
# Print copyright and quit.
|
85
|
-
# [--help]
|
86
|
-
# Print usage and quit.
|
87
|
-
#
|
88
|
-
# == Generating Parser Using Racc
|
89
|
-
#
|
90
|
-
# To compile Racc grammar file, simply type:
|
91
|
-
#
|
92
|
-
# $ racc parse.y
|
93
|
-
#
|
94
|
-
# This creates Ruby script file "parse.tab.y". The -o option can change the output filename.
|
95
|
-
#
|
96
|
-
# == Writing A Racc Grammar File
|
97
|
-
#
|
98
|
-
# If you want your own parser, you have to write a grammar file.
|
99
|
-
# A grammar file contains the name of your parser class, grammar for the parser,
|
100
|
-
# user code, and anything else.
|
101
|
-
# When writing a grammar file, yacc's knowledge is helpful.
|
102
|
-
# If you have not used yacc before, Racc is not too difficult.
|
103
|
-
#
|
104
|
-
# Here's an example Racc grammar file.
|
105
|
-
#
|
106
|
-
# class Calcparser
|
107
|
-
# rule
|
108
|
-
# target: exp { print val[0] }
|
109
|
-
#
|
110
|
-
# exp: exp '+' exp
|
111
|
-
# | exp '*' exp
|
112
|
-
# | '(' exp ')'
|
113
|
-
# | NUMBER
|
114
|
-
# end
|
115
|
-
#
|
116
|
-
# Racc grammar files resemble yacc files.
|
117
|
-
# But (of course), this is Ruby code.
|
118
|
-
# yacc's $$ is the 'result', $0, $1... is
|
119
|
-
# an array called 'val', and $-1, $-2... is an array called '_values'.
|
120
|
-
#
|
121
|
-
# See the {Grammar File Reference}[rdoc-ref:lib/racc/rdoc/grammar.en.rdoc] for
|
122
|
-
# more information on grammar files.
|
123
|
-
#
|
124
|
-
# == Parser
|
125
|
-
#
|
126
|
-
# Then you must prepare the parse entry method. There are two types of
|
127
|
-
# parse methods in Racc, Racc::Parser#do_parse and Racc::Parser#yyparse
|
128
|
-
#
|
129
|
-
# Racc::Parser#do_parse is simple.
|
130
|
-
#
|
131
|
-
# It's yyparse() of yacc, and Racc::Parser#next_token is yylex().
|
132
|
-
# This method must returns an array like [TOKENSYMBOL, ITS_VALUE].
|
133
|
-
# EOF is [false, false].
|
134
|
-
# (TOKENSYMBOL is a Ruby symbol (taken from String#intern) by default.
|
135
|
-
# If you want to change this, see the grammar reference.
|
136
|
-
#
|
137
|
-
# Racc::Parser#yyparse is little complicated, but useful.
|
138
|
-
# It does not use Racc::Parser#next_token, instead it gets tokens from any iterator.
|
139
|
-
#
|
140
|
-
# For example, <code>yyparse(obj, :scan)</code> causes
|
141
|
-
# calling +obj#scan+, and you can return tokens by yielding them from +obj#scan+.
|
142
|
-
#
|
143
|
-
# == Debugging
|
144
|
-
#
|
145
|
-
# When debugging, "-v" or/and the "-g" option is helpful.
|
146
|
-
#
|
147
|
-
# "-v" creates verbose log file (.output).
|
148
|
-
# "-g" creates a "Verbose Parser".
|
149
|
-
# Verbose Parser prints the internal status when parsing.
|
150
|
-
# But it's _not_ automatic.
|
151
|
-
# You must use -g option and set +@yydebug+ to +true+ in order to get output.
|
152
|
-
# -g option only creates the verbose parser.
|
153
|
-
#
|
154
|
-
# === Racc reported syntax error.
|
155
|
-
#
|
156
|
-
# Isn't there too many "end"?
|
157
|
-
# grammar of racc file is changed in v0.10.
|
158
|
-
#
|
159
|
-
# Racc does not use '%' mark, while yacc uses huge number of '%' marks..
|
160
|
-
#
|
161
|
-
# === Racc reported "XXXX conflicts".
|
162
|
-
#
|
163
|
-
# Try "racc -v xxxx.y".
|
164
|
-
# It causes producing racc's internal log file, xxxx.output.
|
165
|
-
#
|
166
|
-
# === Generated parsers does not work correctly
|
167
|
-
#
|
168
|
-
# Try "racc -g xxxx.y".
|
169
|
-
# This command let racc generate "debugging parser".
|
170
|
-
# Then set @yydebug=true in your parser.
|
171
|
-
# It produces a working log of your parser.
|
172
|
-
#
|
173
|
-
# == Re-distributing Racc runtime
|
174
|
-
#
|
175
|
-
# A parser, which is created by Racc, requires the Racc runtime module;
|
176
|
-
# racc/parser.rb.
|
177
|
-
#
|
178
|
-
# Ruby 1.8.x comes with Racc runtime module,
|
179
|
-
# you need NOT distribute Racc runtime files.
|
180
|
-
#
|
181
|
-
# If you want to include the Racc runtime module with your parser.
|
182
|
-
# This can be done by using '-E' option:
|
183
|
-
#
|
184
|
-
# $ racc -E -omyparser.rb myparser.y
|
185
|
-
#
|
186
|
-
# This command creates myparser.rb which `includes' Racc runtime.
|
187
|
-
# Only you must do is to distribute your parser file (myparser.rb).
|
188
|
-
#
|
189
|
-
# Note: parser.rb is LGPL, but your parser is not.
|
190
|
-
# Your own parser is completely yours.
|
191
|
-
module Racc
|
192
|
-
|
193
|
-
unless defined?(Racc_No_Extentions)
|
194
|
-
Racc_No_Extentions = false # :nodoc:
|
195
|
-
end
|
196
|
-
|
197
|
-
class Parser
|
198
|
-
|
199
|
-
Racc_Runtime_Version = ::Racc::VERSION
|
200
|
-
Racc_Runtime_Revision = '$Id: 2bd697d1146b280d8d3878e21e556ef769484a37 $'
|
201
|
-
|
202
|
-
Racc_Runtime_Core_Version_R = ::Racc::VERSION
|
203
|
-
Racc_Runtime_Core_Revision_R = '$Id: 2bd697d1146b280d8d3878e21e556ef769484a37 $'.split[1]
|
204
|
-
begin
|
205
|
-
if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
|
206
|
-
require 'racc/cparse-jruby.jar'
|
207
|
-
com.headius.racc.Cparse.new.load(JRuby.runtime, false)
|
208
|
-
else
|
209
|
-
require 'racc/cparse'
|
210
|
-
end
|
211
|
-
# Racc_Runtime_Core_Version_C = (defined in extention)
|
212
|
-
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
|
213
|
-
unless new.respond_to?(:_racc_do_parse_c, true)
|
214
|
-
raise LoadError, 'old cparse.so'
|
215
|
-
end
|
216
|
-
if Racc_No_Extentions
|
217
|
-
raise LoadError, 'selecting ruby version of racc runtime core'
|
218
|
-
end
|
219
|
-
|
220
|
-
Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
|
221
|
-
Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
|
222
|
-
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
|
223
|
-
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C # :nodoc:
|
224
|
-
Racc_Runtime_Type = 'c' # :nodoc:
|
225
|
-
rescue LoadError
|
226
|
-
puts $!
|
227
|
-
puts $!.backtrace
|
228
|
-
Racc_Main_Parsing_Routine = :_racc_do_parse_rb
|
229
|
-
Racc_YY_Parse_Method = :_racc_yyparse_rb
|
230
|
-
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
|
231
|
-
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_R
|
232
|
-
Racc_Runtime_Type = 'ruby'
|
233
|
-
end
|
234
|
-
|
235
|
-
def Parser.racc_runtime_type # :nodoc:
|
236
|
-
Racc_Runtime_Type
|
237
|
-
end
|
238
|
-
|
239
|
-
def _racc_setup
|
240
|
-
@yydebug = false unless self.class::Racc_debug_parser
|
241
|
-
@yydebug = false unless defined?(@yydebug)
|
242
|
-
if @yydebug
|
243
|
-
@racc_debug_out = $stderr unless defined?(@racc_debug_out)
|
244
|
-
@racc_debug_out ||= $stderr
|
245
|
-
end
|
246
|
-
arg = self.class::Racc_arg
|
247
|
-
arg[13] = true if arg.size < 14
|
248
|
-
arg
|
249
|
-
end
|
250
|
-
|
251
|
-
def _racc_init_sysvars
|
252
|
-
@racc_state = [0]
|
253
|
-
@racc_tstack = []
|
254
|
-
@racc_vstack = []
|
255
|
-
|
256
|
-
@racc_t = nil
|
257
|
-
@racc_val = nil
|
258
|
-
|
259
|
-
@racc_read_next = true
|
260
|
-
|
261
|
-
@racc_user_yyerror = false
|
262
|
-
@racc_error_status = 0
|
263
|
-
end
|
264
|
-
|
265
|
-
# The entry point of the parser. This method is used with #next_token.
|
266
|
-
# If Racc wants to get token (and its value), calls next_token.
|
267
|
-
#
|
268
|
-
# Example:
|
269
|
-
# def parse
|
270
|
-
# @q = [[1,1],
|
271
|
-
# [2,2],
|
272
|
-
# [3,3],
|
273
|
-
# [false, '$']]
|
274
|
-
# do_parse
|
275
|
-
# end
|
276
|
-
#
|
277
|
-
# def next_token
|
278
|
-
# @q.shift
|
279
|
-
# end
|
280
|
-
def do_parse
|
281
|
-
__send__(Racc_Main_Parsing_Routine, _racc_setup(), false)
|
282
|
-
end
|
283
|
-
|
284
|
-
# The method to fetch next token.
|
285
|
-
# If you use #do_parse method, you must implement #next_token.
|
286
|
-
#
|
287
|
-
# The format of return value is [TOKEN_SYMBOL, VALUE].
|
288
|
-
# +token-symbol+ is represented by Ruby's symbol by default, e.g. :IDENT
|
289
|
-
# for 'IDENT'. ";" (String) for ';'.
|
290
|
-
#
|
291
|
-
# The final symbol (End of file) must be false.
|
292
|
-
def next_token
|
293
|
-
raise NotImplementedError, "#{self.class}\#next_token is not defined"
|
294
|
-
end
|
295
|
-
|
296
|
-
def _racc_do_parse_rb(arg, in_debug)
|
297
|
-
action_table, action_check, action_default, action_pointer,
|
298
|
-
_, _, _, _,
|
299
|
-
_, _, token_table, * = arg
|
300
|
-
|
301
|
-
_racc_init_sysvars
|
302
|
-
tok = act = i = nil
|
303
|
-
|
304
|
-
catch(:racc_end_parse) {
|
305
|
-
while true
|
306
|
-
if i = action_pointer[@racc_state[-1]]
|
307
|
-
if @racc_read_next
|
308
|
-
if @racc_t != 0 # not EOF
|
309
|
-
tok, @racc_val = next_token()
|
310
|
-
unless tok # EOF
|
311
|
-
@racc_t = 0
|
312
|
-
else
|
313
|
-
@racc_t = (token_table[tok] or 1) # error token
|
314
|
-
end
|
315
|
-
racc_read_token(@racc_t, tok, @racc_val) if @yydebug
|
316
|
-
@racc_read_next = false
|
317
|
-
end
|
318
|
-
end
|
319
|
-
i += @racc_t
|
320
|
-
unless i >= 0 and
|
321
|
-
act = action_table[i] and
|
322
|
-
action_check[i] == @racc_state[-1]
|
323
|
-
act = action_default[@racc_state[-1]]
|
324
|
-
end
|
325
|
-
else
|
326
|
-
act = action_default[@racc_state[-1]]
|
327
|
-
end
|
328
|
-
while act = _racc_evalact(act, arg)
|
329
|
-
;
|
330
|
-
end
|
331
|
-
end
|
332
|
-
}
|
333
|
-
end
|
334
|
-
|
335
|
-
# Another entry point for the parser.
|
336
|
-
# If you use this method, you must implement RECEIVER#METHOD_ID method.
|
337
|
-
#
|
338
|
-
# RECEIVER#METHOD_ID is a method to get next token.
|
339
|
-
# It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
|
340
|
-
def yyparse(recv, mid)
|
341
|
-
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), false)
|
342
|
-
end
|
343
|
-
|
344
|
-
def _racc_yyparse_rb(recv, mid, arg, c_debug)
|
345
|
-
action_table, action_check, action_default, action_pointer,
|
346
|
-
_, _, _, _,
|
347
|
-
_, _, token_table, * = arg
|
348
|
-
|
349
|
-
_racc_init_sysvars
|
350
|
-
|
351
|
-
catch(:racc_end_parse) {
|
352
|
-
until i = action_pointer[@racc_state[-1]]
|
353
|
-
while act = _racc_evalact(action_default[@racc_state[-1]], arg)
|
354
|
-
;
|
355
|
-
end
|
356
|
-
end
|
357
|
-
recv.__send__(mid) do |tok, val|
|
358
|
-
unless tok
|
359
|
-
@racc_t = 0
|
360
|
-
else
|
361
|
-
@racc_t = (token_table[tok] or 1) # error token
|
362
|
-
end
|
363
|
-
@racc_val = val
|
364
|
-
@racc_read_next = false
|
365
|
-
|
366
|
-
i += @racc_t
|
367
|
-
unless i >= 0 and
|
368
|
-
act = action_table[i] and
|
369
|
-
action_check[i] == @racc_state[-1]
|
370
|
-
act = action_default[@racc_state[-1]]
|
371
|
-
end
|
372
|
-
while act = _racc_evalact(act, arg)
|
373
|
-
;
|
374
|
-
end
|
375
|
-
|
376
|
-
while !(i = action_pointer[@racc_state[-1]]) ||
|
377
|
-
! @racc_read_next ||
|
378
|
-
@racc_t == 0 # $
|
379
|
-
unless i and i += @racc_t and
|
380
|
-
i >= 0 and
|
381
|
-
act = action_table[i] and
|
382
|
-
action_check[i] == @racc_state[-1]
|
383
|
-
act = action_default[@racc_state[-1]]
|
384
|
-
end
|
385
|
-
while act = _racc_evalact(act, arg)
|
386
|
-
;
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
}
|
391
|
-
end
|
392
|
-
|
393
|
-
###
|
394
|
-
### common
|
395
|
-
###
|
396
|
-
|
397
|
-
def _racc_evalact(act, arg)
|
398
|
-
action_table, action_check, _, action_pointer,
|
399
|
-
_, _, _, _,
|
400
|
-
_, _, _, shift_n,
|
401
|
-
reduce_n, * = arg
|
402
|
-
nerr = 0 # tmp
|
403
|
-
|
404
|
-
if act > 0 and act < shift_n
|
405
|
-
#
|
406
|
-
# shift
|
407
|
-
#
|
408
|
-
if @racc_error_status > 0
|
409
|
-
@racc_error_status -= 1 unless @racc_t <= 1 # error token or EOF
|
410
|
-
end
|
411
|
-
@racc_vstack.push @racc_val
|
412
|
-
@racc_state.push act
|
413
|
-
@racc_read_next = true
|
414
|
-
if @yydebug
|
415
|
-
@racc_tstack.push @racc_t
|
416
|
-
racc_shift @racc_t, @racc_tstack, @racc_vstack
|
417
|
-
end
|
418
|
-
|
419
|
-
elsif act < 0 and act > -reduce_n
|
420
|
-
#
|
421
|
-
# reduce
|
422
|
-
#
|
423
|
-
code = catch(:racc_jump) {
|
424
|
-
@racc_state.push _racc_do_reduce(arg, act)
|
425
|
-
false
|
426
|
-
}
|
427
|
-
if code
|
428
|
-
case code
|
429
|
-
when 1 # yyerror
|
430
|
-
@racc_user_yyerror = true # user_yyerror
|
431
|
-
return -reduce_n
|
432
|
-
when 2 # yyaccept
|
433
|
-
return shift_n
|
434
|
-
else
|
435
|
-
raise '[Racc Bug] unknown jump code'
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
elsif act == shift_n
|
440
|
-
#
|
441
|
-
# accept
|
442
|
-
#
|
443
|
-
racc_accept if @yydebug
|
444
|
-
throw :racc_end_parse, @racc_vstack[0]
|
445
|
-
|
446
|
-
elsif act == -reduce_n
|
447
|
-
#
|
448
|
-
# error
|
449
|
-
#
|
450
|
-
case @racc_error_status
|
451
|
-
when 0
|
452
|
-
unless arg[21] # user_yyerror
|
453
|
-
nerr += 1
|
454
|
-
on_error @racc_t, @racc_val, @racc_vstack
|
455
|
-
end
|
456
|
-
when 3
|
457
|
-
if @racc_t == 0 # is $
|
458
|
-
# We're at EOF, and another error occurred immediately after
|
459
|
-
# attempting auto-recovery
|
460
|
-
throw :racc_end_parse, nil
|
461
|
-
end
|
462
|
-
@racc_read_next = true
|
463
|
-
end
|
464
|
-
@racc_user_yyerror = false
|
465
|
-
@racc_error_status = 3
|
466
|
-
while true
|
467
|
-
if i = action_pointer[@racc_state[-1]]
|
468
|
-
i += 1 # error token
|
469
|
-
if i >= 0 and
|
470
|
-
(act = action_table[i]) and
|
471
|
-
action_check[i] == @racc_state[-1]
|
472
|
-
break
|
473
|
-
end
|
474
|
-
end
|
475
|
-
throw :racc_end_parse, nil if @racc_state.size <= 1
|
476
|
-
@racc_state.pop
|
477
|
-
@racc_vstack.pop
|
478
|
-
if @yydebug
|
479
|
-
@racc_tstack.pop
|
480
|
-
racc_e_pop @racc_state, @racc_tstack, @racc_vstack
|
481
|
-
end
|
482
|
-
end
|
483
|
-
return act
|
484
|
-
|
485
|
-
else
|
486
|
-
raise "[Racc Bug] unknown action #{act.inspect}"
|
487
|
-
end
|
488
|
-
|
489
|
-
racc_next_state(@racc_state[-1], @racc_state) if @yydebug
|
490
|
-
|
491
|
-
nil
|
492
|
-
end
|
493
|
-
|
494
|
-
def _racc_do_reduce(arg, act)
|
495
|
-
_, _, _, _,
|
496
|
-
goto_table, goto_check, goto_default, goto_pointer,
|
497
|
-
nt_base, reduce_table, _, _,
|
498
|
-
_, use_result, * = arg
|
499
|
-
|
500
|
-
state = @racc_state
|
501
|
-
vstack = @racc_vstack
|
502
|
-
tstack = @racc_tstack
|
503
|
-
|
504
|
-
i = act * -3
|
505
|
-
len = reduce_table[i]
|
506
|
-
reduce_to = reduce_table[i+1]
|
507
|
-
method_id = reduce_table[i+2]
|
508
|
-
void_array = []
|
509
|
-
|
510
|
-
tmp_t = tstack[-len, len] if @yydebug
|
511
|
-
tmp_v = vstack[-len, len]
|
512
|
-
tstack[-len, len] = void_array if @yydebug
|
513
|
-
vstack[-len, len] = void_array
|
514
|
-
state[-len, len] = void_array
|
515
|
-
|
516
|
-
# tstack must be updated AFTER method call
|
517
|
-
if use_result
|
518
|
-
vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
|
519
|
-
else
|
520
|
-
vstack.push __send__(method_id, tmp_v, vstack)
|
521
|
-
end
|
522
|
-
tstack.push reduce_to
|
523
|
-
|
524
|
-
racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
|
525
|
-
|
526
|
-
k1 = reduce_to - nt_base
|
527
|
-
if i = goto_pointer[k1]
|
528
|
-
i += state[-1]
|
529
|
-
if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
|
530
|
-
return curstate
|
531
|
-
end
|
532
|
-
end
|
533
|
-
goto_default[k1]
|
534
|
-
end
|
535
|
-
|
536
|
-
# This method is called when a parse error is found.
|
537
|
-
#
|
538
|
-
# ERROR_TOKEN_ID is an internal ID of token which caused error.
|
539
|
-
# You can get string representation of this ID by calling
|
540
|
-
# #token_to_str.
|
541
|
-
#
|
542
|
-
# ERROR_VALUE is a value of error token.
|
543
|
-
#
|
544
|
-
# value_stack is a stack of symbol values.
|
545
|
-
# DO NOT MODIFY this object.
|
546
|
-
#
|
547
|
-
# This method raises ParseError by default.
|
548
|
-
#
|
549
|
-
# If this method returns, parsers enter "error recovering mode".
|
550
|
-
def on_error(t, val, vstack)
|
551
|
-
raise ParseError, sprintf("\nparse error on value %s (%s)",
|
552
|
-
val.inspect, token_to_str(t) || '?')
|
553
|
-
end
|
554
|
-
|
555
|
-
# Enter error recovering mode.
|
556
|
-
# This method does not call #on_error.
|
557
|
-
def yyerror
|
558
|
-
throw :racc_jump, 1
|
559
|
-
end
|
560
|
-
|
561
|
-
# Exit parser.
|
562
|
-
# Return value is Symbol_Value_Stack[0].
|
563
|
-
def yyaccept
|
564
|
-
throw :racc_jump, 2
|
565
|
-
end
|
566
|
-
|
567
|
-
# Leave error recovering mode.
|
568
|
-
def yyerrok
|
569
|
-
@racc_error_status = 0
|
570
|
-
end
|
571
|
-
|
572
|
-
# For debugging output
|
573
|
-
def racc_read_token(t, tok, val)
|
574
|
-
@racc_debug_out.print 'read '
|
575
|
-
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
|
576
|
-
@racc_debug_out.puts val.inspect
|
577
|
-
@racc_debug_out.puts
|
578
|
-
end
|
579
|
-
|
580
|
-
def racc_shift(tok, tstack, vstack)
|
581
|
-
@racc_debug_out.puts "shift #{racc_token2str tok}"
|
582
|
-
racc_print_stacks tstack, vstack
|
583
|
-
@racc_debug_out.puts
|
584
|
-
end
|
585
|
-
|
586
|
-
def racc_reduce(toks, sim, tstack, vstack)
|
587
|
-
out = @racc_debug_out
|
588
|
-
out.print 'reduce '
|
589
|
-
if toks.empty?
|
590
|
-
out.print ' <none>'
|
591
|
-
else
|
592
|
-
toks.each {|t| out.print ' ', racc_token2str(t) }
|
593
|
-
end
|
594
|
-
out.puts " --> #{racc_token2str(sim)}"
|
595
|
-
racc_print_stacks tstack, vstack
|
596
|
-
@racc_debug_out.puts
|
597
|
-
end
|
598
|
-
|
599
|
-
def racc_accept
|
600
|
-
@racc_debug_out.puts 'accept'
|
601
|
-
@racc_debug_out.puts
|
602
|
-
end
|
603
|
-
|
604
|
-
def racc_e_pop(state, tstack, vstack)
|
605
|
-
@racc_debug_out.puts 'error recovering mode: pop token'
|
606
|
-
racc_print_states state
|
607
|
-
racc_print_stacks tstack, vstack
|
608
|
-
@racc_debug_out.puts
|
609
|
-
end
|
610
|
-
|
611
|
-
def racc_next_state(curstate, state)
|
612
|
-
@racc_debug_out.puts "goto #{curstate}"
|
613
|
-
racc_print_states state
|
614
|
-
@racc_debug_out.puts
|
615
|
-
end
|
616
|
-
|
617
|
-
def racc_print_stacks(t, v)
|
618
|
-
out = @racc_debug_out
|
619
|
-
out.print ' ['
|
620
|
-
t.each_index do |i|
|
621
|
-
out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
|
622
|
-
end
|
623
|
-
out.puts ' ]'
|
624
|
-
end
|
625
|
-
|
626
|
-
def racc_print_states(s)
|
627
|
-
out = @racc_debug_out
|
628
|
-
out.print ' ['
|
629
|
-
s.each {|st| out.print ' ', st }
|
630
|
-
out.puts ' ]'
|
631
|
-
end
|
632
|
-
|
633
|
-
def racc_token2str(tok)
|
634
|
-
self.class::Racc_token_to_s_table[tok] or
|
635
|
-
raise "[Racc Bug] can't convert token #{tok} to string"
|
636
|
-
end
|
637
|
-
|
638
|
-
# Convert internal ID of token symbol to the string.
|
639
|
-
def token_to_str(t)
|
640
|
-
self.class::Racc_token_to_s_table[t]
|
641
|
-
end
|
642
|
-
|
643
|
-
end
|
644
|
-
|
645
|
-
end
|
646
|
-
|
647
|
-
...end racc/parser.rb/module_eval...
|
648
|
-
end
|
649
|
-
###### racc/parser.rb end
|
7
|
+
require 'racc/parser.rb'
|
650
8
|
module Predicator
|
651
9
|
class GeneratedParser < Racc::Parser
|
652
10
|
##### State transition tables begin ###
|
data/lib/predicator/version.rb
CHANGED
data/predicator.gemspec
CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename f }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "racc"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler"
|
22
24
|
spec.add_development_dependency "coveralls"
|
23
25
|
spec.add_development_dependency "minitest", "= 5.4.2"
|
24
|
-
spec.add_development_dependency "racc"
|
25
26
|
spec.add_development_dependency "rake"
|
26
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: predicator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JohnnyT
|
@@ -11,13 +11,13 @@ cert_chain: []
|
|
11
11
|
date: 2016-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: racc
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,33 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: coveralls
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 5.4.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 5.4.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|