Class: Predicator::Parser

Inherits:
Racc::Parser
  • Object
show all
Defined in:
lib/predicator/parser.rb

Constant Summary collapse

Racc_arg =
[
racc_action_table,
racc_action_check,
racc_action_default,
racc_action_pointer,
racc_goto_table,
racc_goto_check,
racc_goto_default,
racc_goto_pointer,
racc_nt_base,
racc_reduce_table,
racc_token_table,
racc_shift_n,
racc_reduce_n,
racc_use_result_var ]
Racc_token_to_s_table =
[
"$end",
"error",
"TRUE",
"FALSE",
"LPAREN",
"RPAREN",
"LBRACKET",
"RBRACKET",
"BANG",
"NOT",
"DOT",
"COMMA",
"AT",
"AND",
"OR",
"EQ",
"GT",
"LT",
"BETWEEN",
"IN",
"PRESENT",
"BLANK",
"INTEGER",
"STRING",
"IDENTIFIER",
"DATE",
"DURATION",
"AGO",
"FROMNOW",
"STARTSWITH",
"ENDSWITH",
"$start",
"predicate",
"boolean_predicate",
"logical_predicate",
"group_predicate",
"comparison_predicate",
"variable",
"integer_comparison_predicate",
"string_comparison_predicate",
"date_comparison_predicate",
"integer",
"integer_array",
"string",
"string_array",
"date",
"integer_array_contents",
"string_array_contents",
"duration" ]
Racc_debug_parser =
false

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



15
16
17
# File 'lib/predicator/parser.rb', line 15

def initialize
  @lexer = Lexer.new
end

Instance Method Details

#_reduce_10(val, _values) ⇒ Object



295
296
297
# File 'lib/predicator/parser.rb', line 295

def _reduce_10(val, _values)
 AST::Or.new val.first, val.last 
end

#_reduce_11(val, _values) ⇒ Object



299
300
301
# File 'lib/predicator/parser.rb', line 299

def _reduce_11(val, _values)
 AST::Present.new val.first 
end

#_reduce_12(val, _values) ⇒ Object



303
304
305
# File 'lib/predicator/parser.rb', line 303

def _reduce_12(val, _values)
 AST::Blank.new val.first 
end

#_reduce_13(val, _values) ⇒ Object



307
308
309
# File 'lib/predicator/parser.rb', line 307

def _reduce_13(val, _values)
 AST::Group.new val[1] 
end

#_reduce_17(val, _values) ⇒ Object

reduce 16 omitted



317
318
319
# File 'lib/predicator/parser.rb', line 317

def _reduce_17(val, _values)
 AST::IntegerEqual.new val.first, val.last 
end

#_reduce_18(val, _values) ⇒ Object



321
322
323
# File 'lib/predicator/parser.rb', line 321

def _reduce_18(val, _values)
 AST::IntegerGreaterThan.new val.first, val.last 
end

#_reduce_19(val, _values) ⇒ Object



325
326
327
# File 'lib/predicator/parser.rb', line 325

def _reduce_19(val, _values)
 AST::IntegerLessThan.new val.first, val.last 
end

#_reduce_20(val, _values) ⇒ Object



329
330
331
# File 'lib/predicator/parser.rb', line 329

def _reduce_20(val, _values)
 AST::IntegerBetween.new val.first, val[2], val.last 
end

#_reduce_21(val, _values) ⇒ Object



333
334
335
# File 'lib/predicator/parser.rb', line 333

def _reduce_21(val, _values)
 AST::IntegerIn.new val.first, val.last 
end

#_reduce_22(val, _values) ⇒ Object



337
338
339
# File 'lib/predicator/parser.rb', line 337

def _reduce_22(val, _values)
 AST::IntegerNotIn.new val.first, val.last 
end

#_reduce_23(val, _values) ⇒ Object



341
342
343
# File 'lib/predicator/parser.rb', line 341

def _reduce_23(val, _values)
 AST::StringEqual.new val.first, val.last 
end

#_reduce_24(val, _values) ⇒ Object



345
346
347
# File 'lib/predicator/parser.rb', line 345

def _reduce_24(val, _values)
 AST::StringGreaterThan.new val.first, val.last 
end

#_reduce_25(val, _values) ⇒ Object



349
350
351
# File 'lib/predicator/parser.rb', line 349

def _reduce_25(val, _values)
 AST::StringLessThan.new val.first, val.last 
end

#_reduce_26(val, _values) ⇒ Object



353
354
355
# File 'lib/predicator/parser.rb', line 353

def _reduce_26(val, _values)
 AST::StringIn.new val.first, val.last 
end

#_reduce_27(val, _values) ⇒ Object



357
358
359
# File 'lib/predicator/parser.rb', line 357

def _reduce_27(val, _values)
 AST::StringNotIn.new val.first, val.last 
end

#_reduce_28(val, _values) ⇒ Object



361
362
363
# File 'lib/predicator/parser.rb', line 361

def _reduce_28(val, _values)
 AST::StringStartsWith.new val.first, val.last 
end

#_reduce_29(val, _values) ⇒ Object



365
366
367
# File 'lib/predicator/parser.rb', line 365

def _reduce_29(val, _values)
 AST::StringEndsWith.new val.first, val.last 
end

#_reduce_30(val, _values) ⇒ Object



369
370
371
# File 'lib/predicator/parser.rb', line 369

def _reduce_30(val, _values)
 AST::DateEqual.new val.first, val.last 
end

#_reduce_31(val, _values) ⇒ Object



373
374
375
# File 'lib/predicator/parser.rb', line 373

def _reduce_31(val, _values)
 AST::DateGreaterThan.new val.first, val.last 
end

#_reduce_32(val, _values) ⇒ Object



377
378
379
# File 'lib/predicator/parser.rb', line 377

def _reduce_32(val, _values)
 AST::DateLessThan.new val.first, val.last 
end

#_reduce_33(val, _values) ⇒ Object



381
382
383
# File 'lib/predicator/parser.rb', line 381

def _reduce_33(val, _values)
 AST::DateBetween.new val.first, val[2], val.last 
end

#_reduce_34(val, _values) ⇒ Object



385
386
387
# File 'lib/predicator/parser.rb', line 385

def _reduce_34(val, _values)
 AST::IntegerArray.new val[1] 
end

#_reduce_36(val, _values) ⇒ Object

reduce 35 omitted



391
392
393
# File 'lib/predicator/parser.rb', line 391

def _reduce_36(val, _values)
 [val.first, val.last].flatten 
end

#_reduce_37(val, _values) ⇒ Object



395
396
397
# File 'lib/predicator/parser.rb', line 395

def _reduce_37(val, _values)
 AST::StringArray.new val[1] 
end

#_reduce_39(val, _values) ⇒ Object

reduce 38 omitted



401
402
403
# File 'lib/predicator/parser.rb', line 401

def _reduce_39(val, _values)
 [val.first, val.last].flatten 
end

#_reduce_40(val, _values) ⇒ Object



405
406
407
# File 'lib/predicator/parser.rb', line 405

def _reduce_40(val, _values)
 AST::Integer.new val.first.to_i 
end

#_reduce_41(val, _values) ⇒ Object



409
410
411
# File 'lib/predicator/parser.rb', line 409

def _reduce_41(val, _values)
 AST::String.new val.first 
end

#_reduce_42(val, _values) ⇒ Object



413
414
415
# File 'lib/predicator/parser.rb', line 413

def _reduce_42(val, _values)
 AST::Date.new val.first 
end

#_reduce_43(val, _values) ⇒ Object



417
418
419
# File 'lib/predicator/parser.rb', line 417

def _reduce_43(val, _values)
 AST::DateAgo.new val.first 
end

#_reduce_44(val, _values) ⇒ Object



421
422
423
# File 'lib/predicator/parser.rb', line 421

def _reduce_44(val, _values)
 AST::DateFromNow.new val.first 
end

#_reduce_45(val, _values) ⇒ Object



425
426
427
# File 'lib/predicator/parser.rb', line 425

def _reduce_45(val, _values)
 AST::Duration.new val.first 
end

#_reduce_46(val, _values) ⇒ Object



429
430
431
# File 'lib/predicator/parser.rb', line 429

def _reduce_46(val, _values)
 AST::Variable.new val.first 
end

#_reduce_47(val, _values) ⇒ Object



433
434
435
# File 'lib/predicator/parser.rb', line 433

def _reduce_47(val, _values)
 AST::Variable.new [val.first, val.last].flatten.join(".") 
end

#_reduce_5(val, _values) ⇒ Object

reduce 4 omitted



275
276
277
# File 'lib/predicator/parser.rb', line 275

def _reduce_5(val, _values)
 AST::True.new true 
end

#_reduce_6(val, _values) ⇒ Object



279
280
281
# File 'lib/predicator/parser.rb', line 279

def _reduce_6(val, _values)
 AST::False.new false 
end

#_reduce_7(val, _values) ⇒ Object



283
284
285
# File 'lib/predicator/parser.rb', line 283

def _reduce_7(val, _values)
 AST::BooleanVariable.new val.first 
end

#_reduce_8(val, _values) ⇒ Object



287
288
289
# File 'lib/predicator/parser.rb', line 287

def _reduce_8(val, _values)
 AST::Not.new val.last 
end

#_reduce_9(val, _values) ⇒ Object



291
292
293
# File 'lib/predicator/parser.rb', line 291

def _reduce_9(val, _values)
 AST::And.new val.first, val.last 
end

#_reduce_none(val, _values) ⇒ Object



437
438
439
# File 'lib/predicator/parser.rb', line 437

def _reduce_none(val, _values)
  val[0]
end

#next_tokenObject



24
25
26
# File 'lib/predicator/parser.rb', line 24

def next_token
  @lexer.next_token
end

#on_error(type, val, values) ⇒ Object



28
29
30
31
32
33
# File 'lib/predicator/parser.rb', line 28

def on_error type, val, values
  super
rescue Racc::ParseError
  trace = values.each_with_index.map{|l, i| "#{' ' * i}#{l}"}
  raise ParseError, "\nparse error on value #{val.inspect}\n#{trace.join("\n")}"
end

#parse(string) ⇒ Object



19
20
21
22
# File 'lib/predicator/parser.rb', line 19

def parse string
  @lexer.parse string
  do_parse
end