predicator 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,91 +35,124 @@ module Predicator
35
35
  ##### State transition tables begin ###
36
36
 
37
37
  racc_action_table = [
38
- 6, 7, 10, 6, 7, 10, 9, 17, 18, 9,
39
- 6, 7, 10, 46, 17, 18, 9, 47, 14, 13,
40
- 15, 14, 13, 15, 28, 6, 7, 10, 14, 13,
41
- 15, 9, 6, 7, 10, 16, 17, 18, 9, 14,
42
- 13, 15, 31, 14, 13, 15, 32, 39, 17, 18,
43
- 14, 13, 15, -7, 17, 18, 14, 13, -7, 14,
44
- 13, 15, 27, 19, 14, 13, -7, -7, 22, 23,
45
- 24, 25, 26, 14, 13, 15, 14, 13, 15, 14,
46
- 13, 15, 40, 19, 41, 39 ]
38
+ 6, 7, 10, 6, 7, 10, 9, 15, 31, 9,
39
+ 6, 7, 10, 6, 7, 10, 9, 16, 17, 9,
40
+ 16, 17, 14, 16, 17, 14, 52, 6, 7, 10,
41
+ 25, 28, 14, 9, 53, 14, 20, 21, 22, 23,
42
+ 24, 18, 19, 37, 57, 38, 39, 41, 38, 14,
43
+ 26, 27, 16, 17, 37, 38, 56, 39, 41, 37,
44
+ 38, 60, 39, 41, 37, 38, 70, 39, 41, 72,
45
+ 71, 16, 17, 73, 58, 59, 37, 38, 39, 41,
46
+ 61, 52, 37, 37, 38 ]
47
47
 
48
48
  racc_action_check = [
49
- 0, 0, 0, 9, 9, 9, 0, 20, 20, 9,
50
- 10, 10, 10, 42, 29, 29, 10, 42, 0, 0,
51
- 0, 9, 9, 9, 16, 17, 17, 17, 10, 10,
52
- 10, 17, 18, 18, 18, 1, 30, 30, 18, 22,
53
- 22, 22, 19, 17, 17, 17, 21, 26, 1, 1,
54
- 18, 18, 18, 8, 21, 21, 39, 39, 8, 23,
55
- 23, 23, 11, 8, 47, 47, 8, 8, 11, 11,
56
- 11, 11, 11, 24, 24, 24, 25, 25, 25, 41,
57
- 41, 41, 27, 34, 37, 40 ]
49
+ 0, 0, 0, 9, 9, 9, 0, 1, 15, 9,
50
+ 10, 10, 10, 16, 16, 16, 10, 29, 29, 16,
51
+ 1, 1, 0, 32, 32, 9, 24, 17, 17, 17,
52
+ 8, 8, 10, 17, 25, 16, 8, 8, 8, 8,
53
+ 8, 8, 8, 23, 30, 26, 23, 23, 27, 17,
54
+ 8, 8, 30, 30, 20, 20, 28, 20, 20, 21,
55
+ 21, 48, 21, 21, 22, 22, 62, 22, 22, 64,
56
+ 62, 33, 33, 64, 40, 40, 52, 52, 61, 61,
57
+ 49, 53, 60, 71, 73 ]
58
58
 
59
59
  racc_action_pointer = [
60
- -2, 35, nil, nil, nil, nil, nil, nil, 53, 1,
61
- 8, 53, nil, nil, nil, nil, 24, 23, 30, 20,
62
- -6, 41, 19, 39, 53, 56, 41, 63, nil, 1,
63
- 23, nil, nil, nil, 73, nil, nil, 71, nil, 36,
64
- 79, 59, 6, nil, nil, nil, nil, 44, nil ]
60
+ -2, 7, nil, nil, nil, nil, nil, nil, 21, 1,
61
+ 8, nil, nil, nil, nil, 8, 11, 25, nil, nil,
62
+ 32, 37, 42, 21, 20, 15, 22, 25, 32, 4,
63
+ 39, nil, 10, 58, nil, nil, nil, nil, nil, nil,
64
+ 47, nil, nil, nil, nil, nil, nil, nil, 48, 67,
65
+ nil, nil, 54, 75, nil, nil, nil, nil, nil, nil,
66
+ 60, 53, 59, nil, 62, nil, nil, nil, nil, nil,
67
+ nil, 61, nil, 61, nil, nil ]
65
68
 
66
69
  racc_action_default = [
67
- -27, -27, -1, -2, -3, -4, -5, -6, -22, -27,
68
- -27, -27, -21, -23, -24, -25, -27, -27, -27, -27,
69
- -8, -27, -27, -27, -27, -27, -27, -27, 49, -9,
70
- -10, -26, -11, -12, -22, -13, -14, -27, -16, -27,
71
- -27, -27, -27, -19, -17, -15, -18, -27, -20 ]
70
+ -48, -48, -1, -2, -3, -4, -5, -6, -7, -48,
71
+ -48, -14, -15, -16, -46, -48, -48, -48, -11, -12,
72
+ -48, -48, -48, -48, -48, -48, -48, -48, -48, -8,
73
+ -48, 76, -9, -10, -17, -23, -30, -40, -41, -42,
74
+ -48, -45, -18, -24, -31, -19, -25, -32, -48, -48,
75
+ -21, -26, -48, -48, -28, -29, -47, -13, -43, -44,
76
+ -48, -48, -48, -35, -48, -38, -22, -27, -20, -33,
77
+ -34, -48, -37, -48, -36, -39 ]
72
78
 
73
79
  racc_goto_table = [
74
- 34, 34, 34, 34, 33, 35, 36, 37, 1, 42,
75
- 38, nil, 43, nil, nil, nil, nil, 20, 21, 34,
76
- 48, nil, nil, 45, 44, 29, 30 ]
80
+ 35, 43, 46, 62, 50, 51, 54, 55, 34, 42,
81
+ 45, 48, 1, 36, 44, 47, 49, 64, nil, nil,
82
+ nil, 29, 30, nil, nil, nil, nil, nil, 32, 33,
83
+ nil, nil, 65, 66, 67, nil, nil, nil, nil, nil,
84
+ 63, nil, nil, nil, nil, nil, nil, nil, 68, nil,
85
+ nil, nil, nil, 75, 69, nil, nil, nil, nil, 74 ]
77
86
 
78
87
  racc_goto_check = [
79
- 6, 6, 6, 6, 7, 7, 7, 7, 1, 9,
80
- 8, nil, 10, nil, nil, nil, nil, 1, 1, 6,
81
- 10, nil, nil, 7, 8, 1, 1 ]
88
+ 12, 12, 12, 15, 11, 13, 12, 12, 10, 10,
89
+ 10, 10, 1, 14, 14, 14, 14, 16, nil, nil,
90
+ nil, 1, 1, nil, nil, nil, nil, nil, 1, 1,
91
+ nil, nil, 12, 11, 13, nil, nil, nil, nil, nil,
92
+ 10, nil, nil, nil, nil, nil, nil, nil, 10, nil,
93
+ nil, nil, nil, 12, 14, nil, nil, nil, nil, 10 ]
82
94
 
83
95
  racc_goto_pointer = [
84
- nil, 8, nil, nil, nil, nil, -22, -18, -16, -30,
85
- -27 ]
96
+ nil, 12, nil, nil, nil, nil, nil, nil, nil, nil,
97
+ -12, -20, -20, -19, -7, -49, -35, nil ]
86
98
 
87
99
  racc_goto_default = [
88
- nil, nil, 2, 3, 4, 5, 8, 11, nil, nil,
89
- 12 ]
100
+ nil, nil, 2, 3, 4, 5, 8, 11, 12, 13,
101
+ nil, nil, nil, nil, nil, nil, nil, 40 ]
90
102
 
91
103
  racc_reduce_table = [
92
104
  0, 0, :racc_error,
93
- 1, 24, :_reduce_none,
94
- 1, 24, :_reduce_none,
95
- 1, 24, :_reduce_none,
96
- 1, 24, :_reduce_none,
97
- 1, 25, :_reduce_5,
98
- 1, 25, :_reduce_6,
99
- 1, 25, :_reduce_7,
100
- 2, 26, :_reduce_8,
101
- 3, 26, :_reduce_9,
102
- 3, 26, :_reduce_10,
103
- 3, 27, :_reduce_11,
104
- 3, 28, :_reduce_12,
105
- 3, 28, :_reduce_13,
106
- 3, 28, :_reduce_14,
107
- 5, 28, :_reduce_15,
108
- 3, 28, :_reduce_16,
109
- 4, 28, :_reduce_17,
110
- 3, 31, :_reduce_18,
111
105
  1, 32, :_reduce_none,
112
- 3, 32, :_reduce_20,
113
- 1, 30, :_reduce_none,
114
- 1, 30, :_reduce_none,
115
- 1, 33, :_reduce_23,
116
- 1, 33, :_reduce_24,
117
- 1, 29, :_reduce_25,
118
- 3, 29, :_reduce_26 ]
119
-
120
- racc_reduce_n = 27
121
-
122
- racc_shift_n = 49
106
+ 1, 32, :_reduce_none,
107
+ 1, 32, :_reduce_none,
108
+ 1, 32, :_reduce_none,
109
+ 1, 33, :_reduce_5,
110
+ 1, 33, :_reduce_6,
111
+ 1, 33, :_reduce_7,
112
+ 2, 34, :_reduce_8,
113
+ 3, 34, :_reduce_9,
114
+ 3, 34, :_reduce_10,
115
+ 2, 34, :_reduce_11,
116
+ 2, 34, :_reduce_12,
117
+ 3, 35, :_reduce_13,
118
+ 1, 36, :_reduce_none,
119
+ 1, 36, :_reduce_none,
120
+ 1, 36, :_reduce_none,
121
+ 3, 38, :_reduce_17,
122
+ 3, 38, :_reduce_18,
123
+ 3, 38, :_reduce_19,
124
+ 5, 38, :_reduce_20,
125
+ 3, 38, :_reduce_21,
126
+ 4, 38, :_reduce_22,
127
+ 3, 39, :_reduce_23,
128
+ 3, 39, :_reduce_24,
129
+ 3, 39, :_reduce_25,
130
+ 3, 39, :_reduce_26,
131
+ 4, 39, :_reduce_27,
132
+ 3, 39, :_reduce_28,
133
+ 3, 39, :_reduce_29,
134
+ 3, 40, :_reduce_30,
135
+ 3, 40, :_reduce_31,
136
+ 3, 40, :_reduce_32,
137
+ 5, 40, :_reduce_33,
138
+ 3, 42, :_reduce_34,
139
+ 1, 46, :_reduce_none,
140
+ 3, 46, :_reduce_36,
141
+ 3, 44, :_reduce_37,
142
+ 1, 47, :_reduce_none,
143
+ 3, 47, :_reduce_39,
144
+ 1, 41, :_reduce_40,
145
+ 1, 43, :_reduce_41,
146
+ 1, 45, :_reduce_42,
147
+ 2, 45, :_reduce_43,
148
+ 2, 45, :_reduce_44,
149
+ 1, 48, :_reduce_45,
150
+ 1, 37, :_reduce_46,
151
+ 3, 37, :_reduce_47 ]
152
+
153
+ racc_reduce_n = 48
154
+
155
+ racc_shift_n = 76
123
156
 
124
157
  racc_token_table = {
125
158
  false => 0,
@@ -142,11 +175,19 @@ racc_token_table = {
142
175
  :LT => 17,
143
176
  :BETWEEN => 18,
144
177
  :IN => 19,
145
- :INTEGER => 20,
146
- :STRING => 21,
147
- :IDENTIFIER => 22 }
148
-
149
- racc_nt_base = 23
178
+ :PRESENT => 20,
179
+ :BLANK => 21,
180
+ :INTEGER => 22,
181
+ :STRING => 23,
182
+ :IDENTIFIER => 24,
183
+ :DATE => 25,
184
+ :DURATION => 26,
185
+ :AGO => 27,
186
+ :FROMNOW => 28,
187
+ :STARTSWITH => 29,
188
+ :ENDSWITH => 30 }
189
+
190
+ racc_nt_base = 31
150
191
 
151
192
  racc_use_result_var = false
152
193
 
@@ -187,9 +228,17 @@ Racc_token_to_s_table = [
187
228
  "LT",
188
229
  "BETWEEN",
189
230
  "IN",
231
+ "PRESENT",
232
+ "BLANK",
190
233
  "INTEGER",
191
234
  "STRING",
192
235
  "IDENTIFIER",
236
+ "DATE",
237
+ "DURATION",
238
+ "AGO",
239
+ "FROMNOW",
240
+ "STARTSWITH",
241
+ "ENDSWITH",
193
242
  "$start",
194
243
  "predicate",
195
244
  "boolean_predicate",
@@ -197,10 +246,17 @@ Racc_token_to_s_table = [
197
246
  "group_predicate",
198
247
  "comparison_predicate",
199
248
  "variable",
200
- "value",
201
- "array",
202
- "array_contents",
203
- "literal" ]
249
+ "integer_comparison_predicate",
250
+ "string_comparison_predicate",
251
+ "date_comparison_predicate",
252
+ "integer",
253
+ "integer_array",
254
+ "string",
255
+ "string_array",
256
+ "date",
257
+ "integer_array_contents",
258
+ "string_array_contents",
259
+ "duration" ]
204
260
 
205
261
  Racc_debug_parser = false
206
262
 
@@ -241,60 +297,140 @@ def _reduce_10(val, _values)
241
297
  end
242
298
 
243
299
  def _reduce_11(val, _values)
244
- AST::Group.new val[1]
300
+ AST::Present.new val.first
245
301
  end
246
302
 
247
303
  def _reduce_12(val, _values)
248
- AST::Equal.new val.first, val.last
304
+ AST::Blank.new val.first
249
305
  end
250
306
 
251
307
  def _reduce_13(val, _values)
252
- AST::GreaterThan.new val.first, val.last
308
+ AST::Group.new val[1]
253
309
  end
254
310
 
255
- def _reduce_14(val, _values)
256
- AST::LessThan.new val.first, val.last
257
- end
311
+ # reduce 14 omitted
258
312
 
259
- def _reduce_15(val, _values)
260
- AST::Between.new val.first, val[2], val.last
261
- end
313
+ # reduce 15 omitted
262
314
 
263
- def _reduce_16(val, _values)
264
- AST::In.new val.first, val.last
265
- end
315
+ # reduce 16 omitted
266
316
 
267
317
  def _reduce_17(val, _values)
268
- AST::NotIn.new val.first, val.last
318
+ AST::IntegerEqual.new val.first, val.last
269
319
  end
270
320
 
271
321
  def _reduce_18(val, _values)
272
- AST::Array.new val[1]
322
+ AST::IntegerGreaterThan.new val.first, val.last
273
323
  end
274
324
 
275
- # reduce 19 omitted
325
+ def _reduce_19(val, _values)
326
+ AST::IntegerLessThan.new val.first, val.last
327
+ end
276
328
 
277
329
  def _reduce_20(val, _values)
278
- [val.first, val.last].flatten
330
+ AST::IntegerBetween.new val.first, val[2], val.last
279
331
  end
280
332
 
281
- # reduce 21 omitted
333
+ def _reduce_21(val, _values)
334
+ AST::IntegerIn.new val.first, val.last
335
+ end
282
336
 
283
- # reduce 22 omitted
337
+ def _reduce_22(val, _values)
338
+ AST::IntegerNotIn.new val.first, val.last
339
+ end
284
340
 
285
341
  def _reduce_23(val, _values)
286
- AST::String.new val.first
342
+ AST::StringEqual.new val.first, val.last
287
343
  end
288
344
 
289
345
  def _reduce_24(val, _values)
290
- AST::Integer.new val.first.to_i
346
+ AST::StringGreaterThan.new val.first, val.last
291
347
  end
292
348
 
293
349
  def _reduce_25(val, _values)
294
- AST::Variable.new val.first
350
+ AST::StringLessThan.new val.first, val.last
295
351
  end
296
352
 
297
353
  def _reduce_26(val, _values)
354
+ AST::StringIn.new val.first, val.last
355
+ end
356
+
357
+ def _reduce_27(val, _values)
358
+ AST::StringNotIn.new val.first, val.last
359
+ end
360
+
361
+ def _reduce_28(val, _values)
362
+ AST::StringStartsWith.new val.first, val.last
363
+ end
364
+
365
+ def _reduce_29(val, _values)
366
+ AST::StringEndsWith.new val.first, val.last
367
+ end
368
+
369
+ def _reduce_30(val, _values)
370
+ AST::DateEqual.new val.first, val.last
371
+ end
372
+
373
+ def _reduce_31(val, _values)
374
+ AST::DateGreaterThan.new val.first, val.last
375
+ end
376
+
377
+ def _reduce_32(val, _values)
378
+ AST::DateLessThan.new val.first, val.last
379
+ end
380
+
381
+ def _reduce_33(val, _values)
382
+ AST::DateBetween.new val.first, val[2], val.last
383
+ end
384
+
385
+ def _reduce_34(val, _values)
386
+ AST::IntegerArray.new val[1]
387
+ end
388
+
389
+ # reduce 35 omitted
390
+
391
+ def _reduce_36(val, _values)
392
+ [val.first, val.last].flatten
393
+ end
394
+
395
+ def _reduce_37(val, _values)
396
+ AST::StringArray.new val[1]
397
+ end
398
+
399
+ # reduce 38 omitted
400
+
401
+ def _reduce_39(val, _values)
402
+ [val.first, val.last].flatten
403
+ end
404
+
405
+ def _reduce_40(val, _values)
406
+ AST::Integer.new val.first.to_i
407
+ end
408
+
409
+ def _reduce_41(val, _values)
410
+ AST::String.new val.first
411
+ end
412
+
413
+ def _reduce_42(val, _values)
414
+ AST::Date.new val.first
415
+ end
416
+
417
+ def _reduce_43(val, _values)
418
+ AST::DateAgo.new val.first
419
+ end
420
+
421
+ def _reduce_44(val, _values)
422
+ AST::DateFromNow.new val.first
423
+ end
424
+
425
+ def _reduce_45(val, _values)
426
+ AST::Duration.new val.first
427
+ end
428
+
429
+ def _reduce_46(val, _values)
430
+ AST::Variable.new val.first
431
+ end
432
+
433
+ def _reduce_47(val, _values)
298
434
  AST::Variable.new [val.first, val.last].flatten.join(".")
299
435
  end
300
436
 
@@ -4,8 +4,10 @@ options no_result_var
4
4
 
5
5
  token TRUE FALSE LPAREN RPAREN LBRACKET RBRACKET
6
6
  BANG NOT DOT COMMA AT AND OR
7
- EQ GT LT BETWEEN IN
7
+ EQ GT LT BETWEEN IN PRESENT BLANK
8
8
  INTEGER STRING IDENTIFIER
9
+ DATE DURATION AGO FROMNOW
10
+ STARTSWITH ENDSWITH
9
11
 
10
12
  rule
11
13
  predicate
@@ -23,32 +25,67 @@ rule
23
25
  : BANG predicate { AST::Not.new val.last }
24
26
  | predicate AND predicate { AST::And.new val.first, val.last }
25
27
  | predicate OR predicate { AST::Or.new val.first, val.last }
28
+ | variable PRESENT { AST::Present.new val.first }
29
+ | variable BLANK { AST::Blank.new val.first }
26
30
  ;
27
31
  group_predicate
28
32
  : LPAREN predicate RPAREN { AST::Group.new val[1] }
29
33
  ;
30
34
  comparison_predicate
31
- : value EQ value { AST::Equal.new val.first, val.last }
32
- | value GT value { AST::GreaterThan.new val.first, val.last }
33
- | value LT value { AST::LessThan.new val.first, val.last }
34
- | value BETWEEN value AND value { AST::Between.new val.first, val[2], val.last }
35
- | value IN array { AST::In.new val.first, val.last }
36
- | value NOT IN array { AST::NotIn.new val.first, val.last }
35
+ : integer_comparison_predicate
36
+ | string_comparison_predicate
37
+ | date_comparison_predicate
37
38
  ;
38
- array
39
- : LBRACKET array_contents RBRACKET { AST::Array.new val[1] }
39
+ integer_comparison_predicate
40
+ : variable EQ integer { AST::IntegerEqual.new val.first, val.last }
41
+ | variable GT integer { AST::IntegerGreaterThan.new val.first, val.last }
42
+ | variable LT integer { AST::IntegerLessThan.new val.first, val.last }
43
+ | variable BETWEEN integer AND integer { AST::IntegerBetween.new val.first, val[2], val.last }
44
+ | variable IN integer_array { AST::IntegerIn.new val.first, val.last }
45
+ | variable NOT IN integer_array { AST::IntegerNotIn.new val.first, val.last }
40
46
  ;
41
- array_contents
42
- : literal
43
- | array_contents COMMA literal { [val.first, val.last].flatten }
47
+ string_comparison_predicate
48
+ : variable EQ string { AST::StringEqual.new val.first, val.last }
49
+ | variable GT string { AST::StringGreaterThan.new val.first, val.last }
50
+ | variable LT string { AST::StringLessThan.new val.first, val.last }
51
+ | variable IN string_array { AST::StringIn.new val.first, val.last }
52
+ | variable NOT IN string_array { AST::StringNotIn.new val.first, val.last }
53
+ | variable STARTSWITH string { AST::StringStartsWith.new val.first, val.last }
54
+ | variable ENDSWITH string { AST::StringEndsWith.new val.first, val.last }
44
55
  ;
45
- value
46
- : literal
47
- | variable
56
+ date_comparison_predicate
57
+ : variable EQ date { AST::DateEqual.new val.first, val.last }
58
+ | variable GT date { AST::DateGreaterThan.new val.first, val.last }
59
+ | variable LT date { AST::DateLessThan.new val.first, val.last }
60
+ | variable BETWEEN date AND date { AST::DateBetween.new val.first, val[2], val.last }
48
61
  ;
49
- literal
62
+ integer_array
63
+ : LBRACKET integer_array_contents RBRACKET { AST::IntegerArray.new val[1] }
64
+ ;
65
+ integer_array_contents
66
+ : integer
67
+ | integer_array_contents COMMA integer { [val.first, val.last].flatten }
68
+ ;
69
+ string_array
70
+ : LBRACKET string_array_contents RBRACKET { AST::StringArray.new val[1] }
71
+ ;
72
+ string_array_contents
73
+ : string
74
+ | string_array_contents COMMA string { [val.first, val.last].flatten }
75
+ ;
76
+ integer
77
+ : INTEGER { AST::Integer.new val.first.to_i }
78
+ ;
79
+ string
50
80
  : STRING { AST::String.new val.first }
51
- | INTEGER { AST::Integer.new val.first.to_i }
81
+ ;
82
+ date
83
+ : DATE { AST::Date.new val.first }
84
+ | duration AGO { AST::DateAgo.new val.first }
85
+ | duration FROMNOW { AST::DateFromNow.new val.first }
86
+ ;
87
+ duration
88
+ : DURATION { AST::Duration.new val.first }
52
89
  ;
53
90
  variable
54
91
  : IDENTIFIER { AST::Variable.new val.first }