predicator 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77daae72081a8e8de11e9a873f550e8b25d22eda
4
- data.tar.gz: da30db2dc8b2121b69ff574b483830962b9f998f
3
+ metadata.gz: 0c7b8eb2c384628b6669a6acc95b0da5099c10cd
4
+ data.tar.gz: 618a91830663362301f93de960a46ec5b873136c
5
5
  SHA512:
6
- metadata.gz: 2822bdbd8a2e118006de78c0c01239bfc5f3831b1fff666943ff8ddb5de3ef22e1e387471211a8a7082b1e326cfaf915b9fb443cb18e21bb63da1b8fdbc747f9
7
- data.tar.gz: c7747febf870787e37aed8429dcf101ccb2d66b68cc5ce5bb79fb344da33b3c661a6ac6712666dc73b166af21bdfd9521ae517b676fe5ffe87dc32044c9c6e33
6
+ metadata.gz: a499801cb8d6de62764108e83e19a163da52f8fef51a3d75a6d593d9fd7b453128b2a18956472c8078346d72c9152f0d6afcb08f7a100424855aca4d3d3a4de1
7
+ data.tar.gz: 2a3ff0fbc3ffdf3059c56c2e26c161611ae7b59f47e3fb19e7eec80ceb445cbec73b712682a15cd3d93f4982d8700fd6baf1b697a4157f751a291cbe2624f14c
data/HISTORY.md ADDED
@@ -0,0 +1,9 @@
1
+ ### 0.1.0 / 2016-02-21
2
+
3
+ * 1 major enhancement
4
+ * Changed from Parslet to RACC
5
+
6
+ ### 0.0.0 / 2016-02-08
7
+
8
+ * 1 major enhancement
9
+ * Birthday!
data/README.md CHANGED
@@ -1,7 +1,27 @@
1
+ [![Gem Version](https://badge.fury.io/rb/predicator.svg)](http://badge.fury.io/rb/predicator)
2
+ [![Build Status](https://travis-ci.org/johnnyt/predicator.svg?branch=master)](https://travis-ci.org/johnnyt/predicator)
3
+ [![Dependency Status](https://img.shields.io/gemnasium/johnnyt/predicator.svg)](https://gemnasium.com/johnnyt/predicator)
4
+ [![Coverage Status](https://coveralls.io/repos/github/johnnyt/predicator/badge.svg?branch=master)](https://coveralls.io/github/johnnyt/predicator?branch=master)
5
+
1
6
  # Predicator
2
7
 
3
8
  Predicator is a predicate engine
4
9
 
10
+ ## Usage
11
+
12
+ Example usage:
13
+
14
+ ```ruby
15
+ require "predicator"
16
+
17
+ pred = Predicator.parse "a.b = 5"
18
+
19
+ context = Predicator::Context.new
20
+ context[:a] = {b:5}
21
+
22
+ pred.satisfied? context
23
+ ```
24
+
5
25
  ## Installation
6
26
 
7
27
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -8,3 +8,8 @@ Rake::TestTask.new :test do |t|
8
8
  end
9
9
 
10
10
  task :default => :test
11
+
12
+ desc "Compile and generate the parser"
13
+ task :compile do
14
+ sh "racc -E lib/predicator/parser.y -o lib/predicator/generated_parser.rb"
15
+ end
data/bin/console CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "predicator"
5
+ P = Predicator
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
data/lib/predicator.rb CHANGED
@@ -1,21 +1,10 @@
1
- if RUBY_ENGINE == "maglev"
2
- class String
3
- alias_method :byteslice, :slice
4
- end
5
- require "rubygems"
6
- end
7
-
8
- require "parslet"
9
- require "parslet/convenience"
10
-
11
- require "predicator/version"
12
-
1
+ require "predicator/context"
2
+ require "predicator/lexer"
13
3
  require "predicator/parser"
14
- require "predicator/transform"
15
-
16
- require "predicator/predicates/not"
17
- require "predicator/predicates/and"
18
- require "predicator/predicates/or"
4
+ require "predicator/version"
19
5
 
20
6
  module Predicator
7
+ def self.parse string
8
+ Predicator::Parser.new.parse string
9
+ end
21
10
  end
@@ -0,0 +1,24 @@
1
+ require "ostruct"
2
+
3
+ module Predicator
4
+ class Context
5
+ attr_reader :entities
6
+
7
+ def initialize
8
+ @entities = {}
9
+ end
10
+
11
+ def bind name, value
12
+ value = OpenStruct.new(value) if value.kind_of? Hash
13
+ entities[name.to_s] = value
14
+ end
15
+ alias :[]= :bind
16
+
17
+ def value_for input
18
+ return input unless input.kind_of? Predicator::Variable
19
+
20
+ input.value_in self
21
+ end
22
+ alias :[] :value_for
23
+ end
24
+ end
@@ -0,0 +1,885 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.14
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: 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
650
+ module Predicator
651
+ class GeneratedParser < Racc::Parser
652
+ ##### State transition tables begin ###
653
+
654
+ racc_action_table = [
655
+ 9, 26, 25, 7, 8, 14, 15, 16, 17, 18,
656
+ 9, 23, 5, 7, 8, 14, 15, 16, 17, 18,
657
+ 9, 31, 5, 7, 8, 14, 15, 16, 17, 18,
658
+ 9, nil, 5, 7, 8, 14, 15, 16, 17, 18,
659
+ 20, 21, 5, 14, 15, 16, 17, 18, nil, nil,
660
+ 9, nil, 29, 7, 8, 14, 15, 16, 17, 18,
661
+ 19, nil, 5, 20, 21 ]
662
+
663
+ racc_action_check = [
664
+ 0, 19, 18, 0, 0, 0, 0, 0, 0, 0,
665
+ 20, 6, 0, 20, 20, 20, 20, 20, 20, 20,
666
+ 5, 25, 20, 5, 5, 5, 5, 5, 5, 5,
667
+ 21, nil, 5, 21, 21, 21, 21, 21, 21, 21,
668
+ 22, 22, 21, 23, 23, 23, 23, 23, nil, nil,
669
+ 9, nil, 22, 9, 9, 9, 9, 9, 9, 9,
670
+ 1, nil, 9, 1, 1 ]
671
+
672
+ racc_action_pointer = [
673
+ -2, 60, nil, nil, nil, 18, -2, nil, nil, 48,
674
+ nil, nil, nil, nil, nil, nil, nil, nil, -10, 1,
675
+ 8, 28, 37, 36, nil, 10, nil, nil, nil, nil,
676
+ nil, nil ]
677
+
678
+ racc_action_default = [
679
+ -20, -20, -1, -2, -3, -20, -20, -6, -7, -20,
680
+ -11, -12, -13, -14, -15, -16, -17, -18, -20, -20,
681
+ -20, -20, -20, -20, -10, -20, 32, -8, -9, -4,
682
+ -5, -19 ]
683
+
684
+ racc_goto_table = [
685
+ 1, 30, nil, nil, nil, 22, nil, nil, nil, 24,
686
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
687
+ 27, 28 ]
688
+
689
+ racc_goto_check = [
690
+ 1, 5, nil, nil, nil, 1, nil, nil, nil, 1,
691
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
692
+ 1, 1 ]
693
+
694
+ racc_goto_pointer = [
695
+ nil, 0, nil, nil, nil, -22, nil, nil, nil, nil ]
696
+
697
+ racc_goto_default = [
698
+ nil, nil, 2, 3, 4, 6, 10, 11, 12, 13 ]
699
+
700
+ racc_reduce_table = [
701
+ 0, 0, :racc_error,
702
+ 1, 17, :_reduce_none,
703
+ 1, 17, :_reduce_none,
704
+ 1, 17, :_reduce_none,
705
+ 3, 17, :_reduce_none,
706
+ 3, 18, :_reduce_5,
707
+ 1, 19, :_reduce_6,
708
+ 1, 19, :_reduce_7,
709
+ 3, 20, :_reduce_8,
710
+ 3, 20, :_reduce_9,
711
+ 2, 20, :_reduce_10,
712
+ 1, 21, :_reduce_none,
713
+ 1, 21, :_reduce_none,
714
+ 1, 22, :_reduce_none,
715
+ 1, 22, :_reduce_none,
716
+ 1, 24, :_reduce_15,
717
+ 1, 25, :_reduce_16,
718
+ 1, 25, :_reduce_17,
719
+ 1, 25, :_reduce_18,
720
+ 3, 23, :_reduce_19 ]
721
+
722
+ racc_reduce_n = 20
723
+
724
+ racc_shift_n = 32
725
+
726
+ racc_token_table = {
727
+ false => 0,
728
+ :error => 1,
729
+ :tBANG => 2,
730
+ :tAND => 3,
731
+ :tOR => 4,
732
+ :tTRUE => 5,
733
+ :tFALSE => 6,
734
+ :tSTRING => 7,
735
+ :tFLOAT => 8,
736
+ :tINTEGER => 9,
737
+ :tDATE => 10,
738
+ :tIDENTIFIER => 11,
739
+ :tDOT => 12,
740
+ :tEQUAL => 13,
741
+ :tLPAREN => 14,
742
+ :tRPAREN => 15 }
743
+
744
+ racc_nt_base = 16
745
+
746
+ racc_use_result_var = false
747
+
748
+ Racc_arg = [
749
+ racc_action_table,
750
+ racc_action_check,
751
+ racc_action_default,
752
+ racc_action_pointer,
753
+ racc_goto_table,
754
+ racc_goto_check,
755
+ racc_goto_default,
756
+ racc_goto_pointer,
757
+ racc_nt_base,
758
+ racc_reduce_table,
759
+ racc_token_table,
760
+ racc_shift_n,
761
+ racc_reduce_n,
762
+ racc_use_result_var ]
763
+
764
+ Racc_token_to_s_table = [
765
+ "$end",
766
+ "error",
767
+ "tBANG",
768
+ "tAND",
769
+ "tOR",
770
+ "tTRUE",
771
+ "tFALSE",
772
+ "tSTRING",
773
+ "tFLOAT",
774
+ "tINTEGER",
775
+ "tDATE",
776
+ "tIDENTIFIER",
777
+ "tDOT",
778
+ "tEQUAL",
779
+ "tLPAREN",
780
+ "tRPAREN",
781
+ "$start",
782
+ "predicate",
783
+ "equals_predicate",
784
+ "boolean_predicate",
785
+ "logical_predicate",
786
+ "value",
787
+ "scalar",
788
+ "variable",
789
+ "string",
790
+ "literal" ]
791
+
792
+ Racc_debug_parser = false
793
+
794
+ ##### State transition tables end #####
795
+
796
+ # reduce 0 omitted
797
+
798
+ # reduce 1 omitted
799
+
800
+ # reduce 2 omitted
801
+
802
+ # reduce 3 omitted
803
+
804
+ # reduce 4 omitted
805
+
806
+ module_eval(<<'.,.,', 'parser.y', 16)
807
+ def _reduce_5(val, _values)
808
+ Predicator::Predicates::Equals.new val[0], val[2]
809
+ end
810
+ .,.,
811
+
812
+ module_eval(<<'.,.,', 'parser.y', 19)
813
+ def _reduce_6(val, _values)
814
+ Predicator::Predicates::True.new
815
+ end
816
+ .,.,
817
+
818
+ module_eval(<<'.,.,', 'parser.y', 20)
819
+ def _reduce_7(val, _values)
820
+ Predicator::Predicates::False.new
821
+ end
822
+ .,.,
823
+
824
+ module_eval(<<'.,.,', 'parser.y', 23)
825
+ def _reduce_8(val, _values)
826
+ Predicator::Predicates::And.new [val[0], val[2]]
827
+ end
828
+ .,.,
829
+
830
+ module_eval(<<'.,.,', 'parser.y', 24)
831
+ def _reduce_9(val, _values)
832
+ Predicator::Predicates::Or.new [val[0], val[2]]
833
+ end
834
+ .,.,
835
+
836
+ module_eval(<<'.,.,', 'parser.y', 25)
837
+ def _reduce_10(val, _values)
838
+ Predicator::Predicates::Not.new val[0]
839
+ end
840
+ .,.,
841
+
842
+ # reduce 11 omitted
843
+
844
+ # reduce 12 omitted
845
+
846
+ # reduce 13 omitted
847
+
848
+ # reduce 14 omitted
849
+
850
+ module_eval(<<'.,.,', 'parser.y', 36)
851
+ def _reduce_15(val, _values)
852
+ val[0]
853
+ end
854
+ .,.,
855
+
856
+ module_eval(<<'.,.,', 'parser.y', 39)
857
+ def _reduce_16(val, _values)
858
+ val[0].to_f
859
+ end
860
+ .,.,
861
+
862
+ module_eval(<<'.,.,', 'parser.y', 40)
863
+ def _reduce_17(val, _values)
864
+ val[0].to_i
865
+ end
866
+ .,.,
867
+
868
+ module_eval(<<'.,.,', 'parser.y', 41)
869
+ def _reduce_18(val, _values)
870
+ Date.new *val[0]
871
+ end
872
+ .,.,
873
+
874
+ module_eval(<<'.,.,', 'parser.y', 44)
875
+ def _reduce_19(val, _values)
876
+ Predicator::Variable.new val[0], val[2]
877
+ end
878
+ .,.,
879
+
880
+ def _reduce_none(val, _values)
881
+ val[0]
882
+ end
883
+
884
+ end # class GeneratedParser
885
+ end # module Predicator