nql 0.0.3 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +18 -18
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +22 -0
- data/Gemfile +6 -4
- data/LICENSE +21 -21
- data/README.md +74 -54
- data/Rakefile +10 -2
- data/lib/nql.rb +12 -25
- data/lib/nql/error.rb +26 -0
- data/lib/nql/extension/active_record.rb +19 -0
- data/lib/nql/extension/arel.rb +7 -0
- data/lib/nql/extension/hash.rb +9 -0
- data/lib/nql/grammar.rb +842 -760
- data/lib/nql/grammar.treetop +110 -108
- data/lib/nql/query.rb +62 -0
- data/lib/nql/version.rb +3 -3
- data/nql.gemspec +27 -25
- data/spec/comparison_parser_spec.rb +164 -147
- data/spec/coordination_parser_spec.rb +42 -42
- data/spec/coverage_helper.rb +8 -0
- data/spec/migrations/20121108154439_create_countries.rb +9 -9
- data/spec/migrations/20121108154508_create_cities.rb +10 -10
- data/spec/models/city.rb +2 -2
- data/spec/models/country.rb +2 -2
- data/spec/query_spec.rb +48 -0
- data/spec/ransack_spec.rb +163 -134
- data/spec/spec_helper.rb +45 -44
- data/spec/sql_spec.rb +138 -116
- metadata +94 -39
- data/lib/nql/invalid_expression_error.rb +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2425f04ebb2fc216c2026f10a69d644162249f7dd0cc76ceacebd71c0f266603
|
4
|
+
data.tar.gz: c0616e9d0f4ed6fea53b8669420dee4054475e3287fbdfa601f011f3f549de0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8272a744a3a6786c1549d237937ab05815cc543440f3561897fdaee1c96d451ade59f14d4e4e56d1669073ebc00a22bc4fa0afc11d65cb1eab6d3dffff1de723
|
7
|
+
data.tar.gz: b93e13fe0b17a89c1ea394b0e50f0b3bf3c7e3c9a7523c2b21013b560968ef92a5ce704c9cf983c6b17076101ee78ec3deb342ed429d5c71e0c147603f5edbc9
|
data/.coveralls.yml
ADDED
data/.gitignore
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
.idea
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.idea
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
nql
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- 2.3
|
8
|
+
- 2.4
|
9
|
+
- 2.5
|
10
|
+
- 2.6
|
11
|
+
- 2.7
|
12
|
+
- jruby-9.2.9.0
|
13
|
+
- ruby-head
|
14
|
+
- jruby-head
|
15
|
+
|
16
|
+
matrix:
|
17
|
+
fast_finish: true
|
18
|
+
allow_failures:
|
19
|
+
- rvm: 2.7
|
20
|
+
- rvm: jruby-9.2.9.0
|
21
|
+
- rvm: ruby-head
|
22
|
+
- rvm: jruby-head
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2012 gabriel
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
1
|
+
Copyright (c) 2012 gabriel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,54 +1,74 @@
|
|
1
|
-
# NQL
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
|
28
|
-
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
Country.
|
46
|
-
=> "SELECT
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
1
|
+
# NQL
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/nql.svg)](https://rubygems.org/gems/nql)
|
4
|
+
[![Build Status](https://travis-ci.org/gabynaiman/nql.svg?branch=master)](https://travis-ci.org/gabynaiman/nql)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/gabynaiman/nql/badge.svg?branch=master)](https://coveralls.io/r/gabynaiman/nql?branch=master)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/gabynaiman/nql.svg)](https://codeclimate.com/github/gabynaiman/nql)
|
7
|
+
|
8
|
+
Natural Query Language built on top of ActiveRecord and Ransack
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'nql'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install nql
|
23
|
+
|
24
|
+
## Supported comparators
|
25
|
+
|
26
|
+
--------------------------------------
|
27
|
+
| Symbol | Description |
|
28
|
+
--------------------------------------
|
29
|
+
| : | Contains |
|
30
|
+
| !: | Not contains |
|
31
|
+
| = | Equals |
|
32
|
+
| != | Not equals |
|
33
|
+
| > | Grater than |
|
34
|
+
| >= | Grater or equals than |
|
35
|
+
| < | Less than |
|
36
|
+
| <= | Less or equals than |
|
37
|
+
| ~ | Matches (eq ignore case) |
|
38
|
+
--------------------------------------
|
39
|
+
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
Converts from natural language to query expression
|
44
|
+
|
45
|
+
Country.nql('(name: arg | name: br) & region = south').to_sql
|
46
|
+
=> "SELECT coutries.* FROM countries WHERE (countries.name LIKE '%arg%' OR countries.name LIKE '%br%') AND region = 'south'"
|
47
|
+
|
48
|
+
### Joins support
|
49
|
+
|
50
|
+
Country.nql('cities.name: buenos').to_sql
|
51
|
+
=> "SELECT countries.* FROM countries LEFT OUTER JOIN cities ON countries.id = cities.country_id WHERE cities.name LIKE '%buenos%'"
|
52
|
+
|
53
|
+
### Invalid expressions handling
|
54
|
+
|
55
|
+
Safe query
|
56
|
+
|
57
|
+
Country.nql('xyz').to_sql
|
58
|
+
=> "SELECT coutries.* FROM countries WHERE (1=2)
|
59
|
+
|
60
|
+
Raising exceptions
|
61
|
+
|
62
|
+
Country.nql!('xyz') => raise NQL::SyntaxError
|
63
|
+
|
64
|
+
Country.nql!('xyz: arg') => raise NQL::AttributesNotFoundError
|
65
|
+
|
66
|
+
Country.nql!(1234) => raise NQL::DataTypeError
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,2 +1,10 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new do |task|
|
5
|
+
task.pattern = 'spec/**/*_spec.rb'
|
6
|
+
task.rspec_opts = '--tty --color -f documentation'
|
7
|
+
task.verbose = false
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :spec
|
data/lib/nql.rb
CHANGED
@@ -1,25 +1,12 @@
|
|
1
|
-
require 'treetop'
|
2
|
-
require 'active_record'
|
3
|
-
require 'active_support/all'
|
4
|
-
require 'ransack'
|
5
|
-
|
6
|
-
require 'nql/version'
|
7
|
-
require 'nql/
|
8
|
-
require 'nql/
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
return nil if query.nil? || query.strip.empty?
|
14
|
-
expression = parser.parse(query)
|
15
|
-
raise InvalidExpressionError.new(parser.failure_reason) unless expression
|
16
|
-
expression.to_ransack
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def self.parser
|
22
|
-
@@parser ||= SyntaxParser.new
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
1
|
+
require 'treetop'
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'ransack'
|
5
|
+
|
6
|
+
require 'nql/version'
|
7
|
+
require 'nql/extension/hash'
|
8
|
+
require 'nql/extension/active_record'
|
9
|
+
require 'nql/extension/arel'
|
10
|
+
require 'nql/grammar'
|
11
|
+
require 'nql/query'
|
12
|
+
require 'nql/error'
|
data/lib/nql/error.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module NQL
|
2
|
+
class Error < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class SyntaxError < Error
|
6
|
+
end
|
7
|
+
|
8
|
+
class DataTypeError < Error
|
9
|
+
def initialize(text)
|
10
|
+
super "#{text} must be a String"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class InvalidModelError < Error
|
15
|
+
def initialize(model)
|
16
|
+
super "#{model} must be subclass of ActiveRecord::Base"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class AttributesNotFoundError < Error
|
21
|
+
def initialize(model, attributes)
|
22
|
+
super "#{model} does not contains the attributes #{attributes}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def self.nql(query, options={})
|
5
|
+
nql! query, options
|
6
|
+
rescue NQL::Error
|
7
|
+
self.where('1=2')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.nql!(query, options={})
|
11
|
+
nql_search(query).result(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.nql_search(query)
|
15
|
+
NQL::Query.new(self, query).ransack_search
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/nql/grammar.rb
CHANGED
@@ -1,761 +1,843 @@
|
|
1
|
-
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
-
|
3
|
-
|
4
|
-
module NQL
|
5
|
-
module Syntax
|
6
|
-
include Treetop::Runtime
|
7
|
-
|
8
|
-
def root
|
9
|
-
@root ||= :expression
|
10
|
-
end
|
11
|
-
|
12
|
-
def _nt_expression
|
13
|
-
start_index = index
|
14
|
-
if node_cache[:expression].has_key?(index)
|
15
|
-
cached = node_cache[:expression][index]
|
16
|
-
if cached
|
17
|
-
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
18
|
-
@index = cached.interval.end
|
19
|
-
end
|
20
|
-
return cached
|
21
|
-
end
|
22
|
-
|
23
|
-
i0 = index
|
24
|
-
r1 = _nt_boolean
|
25
|
-
if r1
|
26
|
-
r0 = r1
|
27
|
-
else
|
28
|
-
r2 = _nt_primary
|
29
|
-
if r2
|
30
|
-
r0 = r2
|
31
|
-
else
|
32
|
-
@index = i0
|
33
|
-
r0 = nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
node_cache[:expression][start_index] = r0
|
38
|
-
|
39
|
-
r0
|
40
|
-
end
|
41
|
-
|
42
|
-
module Boolean0
|
43
|
-
def left
|
44
|
-
elements[0]
|
45
|
-
end
|
46
|
-
|
47
|
-
def space1
|
48
|
-
elements[1]
|
49
|
-
end
|
50
|
-
|
51
|
-
def coordinator
|
52
|
-
elements[2]
|
53
|
-
end
|
54
|
-
|
55
|
-
def space2
|
56
|
-
elements[3]
|
57
|
-
end
|
58
|
-
|
59
|
-
def right
|
60
|
-
elements[4]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
module Boolean1
|
65
|
-
def to_ransack
|
66
|
-
group = {g: [{m: coordinator.to_ransack}]}
|
67
|
-
|
68
|
-
[left, right].each do |side|
|
69
|
-
if side.is_node?(:boolean)
|
70
|
-
group[:g][0].merge! side.to_ransack
|
71
|
-
else
|
72
|
-
group[:g][0][:c] ||= []
|
73
|
-
group[:g][0][:c] << side.to_ransack
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
group
|
78
|
-
end
|
79
|
-
|
80
|
-
def is_node?(node_type)
|
81
|
-
node_type.to_sym == :boolean
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def _nt_boolean
|
86
|
-
start_index = index
|
87
|
-
if node_cache[:boolean].has_key?(index)
|
88
|
-
cached = node_cache[:boolean][index]
|
89
|
-
if cached
|
90
|
-
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
91
|
-
@index = cached.interval.end
|
92
|
-
end
|
93
|
-
return cached
|
94
|
-
end
|
95
|
-
|
96
|
-
i0, s0 = index, []
|
97
|
-
r1 = _nt_primary
|
98
|
-
s0 << r1
|
99
|
-
if r1
|
100
|
-
r2 = _nt_space
|
101
|
-
s0 << r2
|
102
|
-
if r2
|
103
|
-
r3 = _nt_coordinator
|
104
|
-
s0 << r3
|
105
|
-
if r3
|
106
|
-
r4 = _nt_space
|
107
|
-
s0 << r4
|
108
|
-
if r4
|
109
|
-
r5 = _nt_expression
|
110
|
-
s0 << r5
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
if s0.last
|
116
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
117
|
-
r0.extend(Boolean0)
|
118
|
-
r0.extend(Boolean1)
|
119
|
-
else
|
120
|
-
@index = i0
|
121
|
-
r0 = nil
|
122
|
-
end
|
123
|
-
|
124
|
-
node_cache[:boolean][start_index] = r0
|
125
|
-
|
126
|
-
r0
|
127
|
-
end
|
128
|
-
|
129
|
-
module Primary0
|
130
|
-
def space1
|
131
|
-
elements[0]
|
132
|
-
end
|
133
|
-
|
134
|
-
def comparison
|
135
|
-
elements[1]
|
136
|
-
end
|
137
|
-
|
138
|
-
def space2
|
139
|
-
elements[2]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
module Primary1
|
144
|
-
def space1
|
145
|
-
elements[1]
|
146
|
-
end
|
147
|
-
|
148
|
-
def
|
149
|
-
elements[2]
|
150
|
-
end
|
151
|
-
|
152
|
-
def space2
|
153
|
-
elements[3]
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
module Primary2
|
159
|
-
def
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
def
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
def
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
if
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
end
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
cached
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
s0
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
end
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module NQL
|
5
|
+
module Syntax
|
6
|
+
include Treetop::Runtime
|
7
|
+
|
8
|
+
def root
|
9
|
+
@root ||= :expression
|
10
|
+
end
|
11
|
+
|
12
|
+
def _nt_expression
|
13
|
+
start_index = index
|
14
|
+
if node_cache[:expression].has_key?(index)
|
15
|
+
cached = node_cache[:expression][index]
|
16
|
+
if cached
|
17
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
18
|
+
@index = cached.interval.end
|
19
|
+
end
|
20
|
+
return cached
|
21
|
+
end
|
22
|
+
|
23
|
+
i0 = index
|
24
|
+
r1 = _nt_boolean
|
25
|
+
if r1
|
26
|
+
r0 = r1
|
27
|
+
else
|
28
|
+
r2 = _nt_primary
|
29
|
+
if r2
|
30
|
+
r0 = r2
|
31
|
+
else
|
32
|
+
@index = i0
|
33
|
+
r0 = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
node_cache[:expression][start_index] = r0
|
38
|
+
|
39
|
+
r0
|
40
|
+
end
|
41
|
+
|
42
|
+
module Boolean0
|
43
|
+
def left
|
44
|
+
elements[0]
|
45
|
+
end
|
46
|
+
|
47
|
+
def space1
|
48
|
+
elements[1]
|
49
|
+
end
|
50
|
+
|
51
|
+
def coordinator
|
52
|
+
elements[2]
|
53
|
+
end
|
54
|
+
|
55
|
+
def space2
|
56
|
+
elements[3]
|
57
|
+
end
|
58
|
+
|
59
|
+
def right
|
60
|
+
elements[4]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module Boolean1
|
65
|
+
def to_ransack
|
66
|
+
group = {g: [{m: coordinator.to_ransack}]}
|
67
|
+
|
68
|
+
[left, right].each do |side|
|
69
|
+
if side.is_node?(:boolean)
|
70
|
+
group[:g][0].merge! side.to_ransack
|
71
|
+
else
|
72
|
+
group[:g][0][:c] ||= []
|
73
|
+
group[:g][0][:c] << side.to_ransack
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
group
|
78
|
+
end
|
79
|
+
|
80
|
+
def is_node?(node_type)
|
81
|
+
node_type.to_sym == :boolean
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def _nt_boolean
|
86
|
+
start_index = index
|
87
|
+
if node_cache[:boolean].has_key?(index)
|
88
|
+
cached = node_cache[:boolean][index]
|
89
|
+
if cached
|
90
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
91
|
+
@index = cached.interval.end
|
92
|
+
end
|
93
|
+
return cached
|
94
|
+
end
|
95
|
+
|
96
|
+
i0, s0 = index, []
|
97
|
+
r1 = _nt_primary
|
98
|
+
s0 << r1
|
99
|
+
if r1
|
100
|
+
r2 = _nt_space
|
101
|
+
s0 << r2
|
102
|
+
if r2
|
103
|
+
r3 = _nt_coordinator
|
104
|
+
s0 << r3
|
105
|
+
if r3
|
106
|
+
r4 = _nt_space
|
107
|
+
s0 << r4
|
108
|
+
if r4
|
109
|
+
r5 = _nt_expression
|
110
|
+
s0 << r5
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
if s0.last
|
116
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
117
|
+
r0.extend(Boolean0)
|
118
|
+
r0.extend(Boolean1)
|
119
|
+
else
|
120
|
+
@index = i0
|
121
|
+
r0 = nil
|
122
|
+
end
|
123
|
+
|
124
|
+
node_cache[:boolean][start_index] = r0
|
125
|
+
|
126
|
+
r0
|
127
|
+
end
|
128
|
+
|
129
|
+
module Primary0
|
130
|
+
def space1
|
131
|
+
elements[0]
|
132
|
+
end
|
133
|
+
|
134
|
+
def comparison
|
135
|
+
elements[1]
|
136
|
+
end
|
137
|
+
|
138
|
+
def space2
|
139
|
+
elements[2]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
module Primary1
|
144
|
+
def space1
|
145
|
+
elements[1]
|
146
|
+
end
|
147
|
+
|
148
|
+
def comparison
|
149
|
+
elements[2]
|
150
|
+
end
|
151
|
+
|
152
|
+
def space2
|
153
|
+
elements[3]
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
module Primary2
|
159
|
+
def space1
|
160
|
+
elements[1]
|
161
|
+
end
|
162
|
+
|
163
|
+
def expression
|
164
|
+
elements[2]
|
165
|
+
end
|
166
|
+
|
167
|
+
def space2
|
168
|
+
elements[3]
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
module Primary3
|
174
|
+
def to_ransack
|
175
|
+
detect_node.to_ransack
|
176
|
+
end
|
177
|
+
|
178
|
+
def detect_node
|
179
|
+
self.send %w(comparison expression).detect { |m| self.respond_to? m }
|
180
|
+
end
|
181
|
+
|
182
|
+
def is_node?(node_type)
|
183
|
+
detect_node.is_node?(node_type)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def _nt_primary
|
188
|
+
start_index = index
|
189
|
+
if node_cache[:primary].has_key?(index)
|
190
|
+
cached = node_cache[:primary][index]
|
191
|
+
if cached
|
192
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
193
|
+
@index = cached.interval.end
|
194
|
+
end
|
195
|
+
return cached
|
196
|
+
end
|
197
|
+
|
198
|
+
i0 = index
|
199
|
+
i1, s1 = index, []
|
200
|
+
r2 = _nt_space
|
201
|
+
s1 << r2
|
202
|
+
if r2
|
203
|
+
r3 = _nt_comparison
|
204
|
+
s1 << r3
|
205
|
+
if r3
|
206
|
+
r4 = _nt_space
|
207
|
+
s1 << r4
|
208
|
+
end
|
209
|
+
end
|
210
|
+
if s1.last
|
211
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
212
|
+
r1.extend(Primary0)
|
213
|
+
else
|
214
|
+
@index = i1
|
215
|
+
r1 = nil
|
216
|
+
end
|
217
|
+
if r1
|
218
|
+
r0 = r1
|
219
|
+
r0.extend(Primary3)
|
220
|
+
else
|
221
|
+
i5, s5 = index, []
|
222
|
+
if has_terminal?('(', false, index)
|
223
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
224
|
+
@index += 1
|
225
|
+
else
|
226
|
+
terminal_parse_failure('(')
|
227
|
+
r6 = nil
|
228
|
+
end
|
229
|
+
s5 << r6
|
230
|
+
if r6
|
231
|
+
r7 = _nt_space
|
232
|
+
s5 << r7
|
233
|
+
if r7
|
234
|
+
r8 = _nt_comparison
|
235
|
+
s5 << r8
|
236
|
+
if r8
|
237
|
+
r9 = _nt_space
|
238
|
+
s5 << r9
|
239
|
+
if r9
|
240
|
+
if has_terminal?(')', false, index)
|
241
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
242
|
+
@index += 1
|
243
|
+
else
|
244
|
+
terminal_parse_failure(')')
|
245
|
+
r10 = nil
|
246
|
+
end
|
247
|
+
s5 << r10
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
if s5.last
|
253
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
254
|
+
r5.extend(Primary1)
|
255
|
+
else
|
256
|
+
@index = i5
|
257
|
+
r5 = nil
|
258
|
+
end
|
259
|
+
if r5
|
260
|
+
r0 = r5
|
261
|
+
r0.extend(Primary3)
|
262
|
+
else
|
263
|
+
i11, s11 = index, []
|
264
|
+
if has_terminal?('(', false, index)
|
265
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
266
|
+
@index += 1
|
267
|
+
else
|
268
|
+
terminal_parse_failure('(')
|
269
|
+
r12 = nil
|
270
|
+
end
|
271
|
+
s11 << r12
|
272
|
+
if r12
|
273
|
+
r13 = _nt_space
|
274
|
+
s11 << r13
|
275
|
+
if r13
|
276
|
+
r14 = _nt_expression
|
277
|
+
s11 << r14
|
278
|
+
if r14
|
279
|
+
r15 = _nt_space
|
280
|
+
s11 << r15
|
281
|
+
if r15
|
282
|
+
if has_terminal?(')', false, index)
|
283
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
284
|
+
@index += 1
|
285
|
+
else
|
286
|
+
terminal_parse_failure(')')
|
287
|
+
r16 = nil
|
288
|
+
end
|
289
|
+
s11 << r16
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
if s11.last
|
295
|
+
r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
|
296
|
+
r11.extend(Primary2)
|
297
|
+
else
|
298
|
+
@index = i11
|
299
|
+
r11 = nil
|
300
|
+
end
|
301
|
+
if r11
|
302
|
+
r0 = r11
|
303
|
+
r0.extend(Primary3)
|
304
|
+
else
|
305
|
+
@index = i0
|
306
|
+
r0 = nil
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
node_cache[:primary][start_index] = r0
|
312
|
+
|
313
|
+
r0
|
314
|
+
end
|
315
|
+
|
316
|
+
module Coordinator0
|
317
|
+
def to_ransack
|
318
|
+
coordinators = {'|' => 'or', '&' => 'and'}
|
319
|
+
coordinators[text_value]
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def _nt_coordinator
|
324
|
+
start_index = index
|
325
|
+
if node_cache[:coordinator].has_key?(index)
|
326
|
+
cached = node_cache[:coordinator][index]
|
327
|
+
if cached
|
328
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
329
|
+
@index = cached.interval.end
|
330
|
+
end
|
331
|
+
return cached
|
332
|
+
end
|
333
|
+
|
334
|
+
i0 = index
|
335
|
+
if has_terminal?('|', false, index)
|
336
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
337
|
+
@index += 1
|
338
|
+
else
|
339
|
+
terminal_parse_failure('|')
|
340
|
+
r1 = nil
|
341
|
+
end
|
342
|
+
if r1
|
343
|
+
r0 = r1
|
344
|
+
r0.extend(Coordinator0)
|
345
|
+
else
|
346
|
+
if has_terminal?('&', false, index)
|
347
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
348
|
+
@index += 1
|
349
|
+
else
|
350
|
+
terminal_parse_failure('&')
|
351
|
+
r2 = nil
|
352
|
+
end
|
353
|
+
if r2
|
354
|
+
r0 = r2
|
355
|
+
r0.extend(Coordinator0)
|
356
|
+
else
|
357
|
+
@index = i0
|
358
|
+
r0 = nil
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
node_cache[:coordinator][start_index] = r0
|
363
|
+
|
364
|
+
r0
|
365
|
+
end
|
366
|
+
|
367
|
+
module Comparison0
|
368
|
+
def variable
|
369
|
+
elements[0]
|
370
|
+
end
|
371
|
+
|
372
|
+
def space1
|
373
|
+
elements[1]
|
374
|
+
end
|
375
|
+
|
376
|
+
def comparator
|
377
|
+
elements[2]
|
378
|
+
end
|
379
|
+
|
380
|
+
def space2
|
381
|
+
elements[3]
|
382
|
+
end
|
383
|
+
|
384
|
+
def value
|
385
|
+
elements[4]
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
module Comparison1
|
390
|
+
def to_ransack
|
391
|
+
hash = {a: {'0' => {name: self.variable.text_value.gsub('.', '_')}}, p: self.comparator.to_ransack, v: {'0' => {value: self.value.text_value}}}
|
392
|
+
hash = {c: [hash]} if !parent || !parent.parent || text_value == parent.parent.text_value
|
393
|
+
hash
|
394
|
+
end
|
395
|
+
|
396
|
+
def is_node?(node_type)
|
397
|
+
node_type.to_sym == :comparison
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
def _nt_comparison
|
402
|
+
start_index = index
|
403
|
+
if node_cache[:comparison].has_key?(index)
|
404
|
+
cached = node_cache[:comparison][index]
|
405
|
+
if cached
|
406
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
407
|
+
@index = cached.interval.end
|
408
|
+
end
|
409
|
+
return cached
|
410
|
+
end
|
411
|
+
|
412
|
+
i0, s0 = index, []
|
413
|
+
r1 = _nt_alphanumeric
|
414
|
+
s0 << r1
|
415
|
+
if r1
|
416
|
+
r2 = _nt_space
|
417
|
+
s0 << r2
|
418
|
+
if r2
|
419
|
+
r3 = _nt_comparator
|
420
|
+
s0 << r3
|
421
|
+
if r3
|
422
|
+
r4 = _nt_space
|
423
|
+
s0 << r4
|
424
|
+
if r4
|
425
|
+
r5 = _nt_text
|
426
|
+
s0 << r5
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
if s0.last
|
432
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
433
|
+
r0.extend(Comparison0)
|
434
|
+
r0.extend(Comparison1)
|
435
|
+
else
|
436
|
+
@index = i0
|
437
|
+
r0 = nil
|
438
|
+
end
|
439
|
+
|
440
|
+
node_cache[:comparison][start_index] = r0
|
441
|
+
|
442
|
+
r0
|
443
|
+
end
|
444
|
+
|
445
|
+
module Comparator0
|
446
|
+
def to_ransack
|
447
|
+
comparators = {
|
448
|
+
'=' => 'eq',
|
449
|
+
'!=' => 'not_eq',
|
450
|
+
'>' => 'gt',
|
451
|
+
'>=' => 'gteq',
|
452
|
+
'<' => 'lt',
|
453
|
+
'<=' => 'lteq',
|
454
|
+
':' => 'cont',
|
455
|
+
'!:' => 'not_cont',
|
456
|
+
'~' => 'matches'
|
457
|
+
}
|
458
|
+
comparators[text_value]
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
def _nt_comparator
|
463
|
+
start_index = index
|
464
|
+
if node_cache[:comparator].has_key?(index)
|
465
|
+
cached = node_cache[:comparator][index]
|
466
|
+
if cached
|
467
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
468
|
+
@index = cached.interval.end
|
469
|
+
end
|
470
|
+
return cached
|
471
|
+
end
|
472
|
+
|
473
|
+
s0, i0 = [], index
|
474
|
+
loop do
|
475
|
+
i1 = index
|
476
|
+
if has_terminal?('=', false, index)
|
477
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
478
|
+
@index += 1
|
479
|
+
else
|
480
|
+
terminal_parse_failure('=')
|
481
|
+
r2 = nil
|
482
|
+
end
|
483
|
+
if r2
|
484
|
+
r1 = r2
|
485
|
+
else
|
486
|
+
if has_terminal?('!=', false, index)
|
487
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
488
|
+
@index += 2
|
489
|
+
else
|
490
|
+
terminal_parse_failure('!=')
|
491
|
+
r3 = nil
|
492
|
+
end
|
493
|
+
if r3
|
494
|
+
r1 = r3
|
495
|
+
else
|
496
|
+
if has_terminal?('>', false, index)
|
497
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
498
|
+
@index += 1
|
499
|
+
else
|
500
|
+
terminal_parse_failure('>')
|
501
|
+
r4 = nil
|
502
|
+
end
|
503
|
+
if r4
|
504
|
+
r1 = r4
|
505
|
+
else
|
506
|
+
if has_terminal?('>=', false, index)
|
507
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
508
|
+
@index += 2
|
509
|
+
else
|
510
|
+
terminal_parse_failure('>=')
|
511
|
+
r5 = nil
|
512
|
+
end
|
513
|
+
if r5
|
514
|
+
r1 = r5
|
515
|
+
else
|
516
|
+
if has_terminal?('<', false, index)
|
517
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
518
|
+
@index += 1
|
519
|
+
else
|
520
|
+
terminal_parse_failure('<')
|
521
|
+
r6 = nil
|
522
|
+
end
|
523
|
+
if r6
|
524
|
+
r1 = r6
|
525
|
+
else
|
526
|
+
if has_terminal?('<=', false, index)
|
527
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
528
|
+
@index += 2
|
529
|
+
else
|
530
|
+
terminal_parse_failure('<=')
|
531
|
+
r7 = nil
|
532
|
+
end
|
533
|
+
if r7
|
534
|
+
r1 = r7
|
535
|
+
else
|
536
|
+
if has_terminal?(':', false, index)
|
537
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
538
|
+
@index += 1
|
539
|
+
else
|
540
|
+
terminal_parse_failure(':')
|
541
|
+
r8 = nil
|
542
|
+
end
|
543
|
+
if r8
|
544
|
+
r1 = r8
|
545
|
+
else
|
546
|
+
if has_terminal?('!:', false, index)
|
547
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
548
|
+
@index += 2
|
549
|
+
else
|
550
|
+
terminal_parse_failure('!:')
|
551
|
+
r9 = nil
|
552
|
+
end
|
553
|
+
if r9
|
554
|
+
r1 = r9
|
555
|
+
else
|
556
|
+
if has_terminal?('~', false, index)
|
557
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
558
|
+
@index += 1
|
559
|
+
else
|
560
|
+
terminal_parse_failure('~')
|
561
|
+
r10 = nil
|
562
|
+
end
|
563
|
+
if r10
|
564
|
+
r1 = r10
|
565
|
+
else
|
566
|
+
@index = i1
|
567
|
+
r1 = nil
|
568
|
+
end
|
569
|
+
end
|
570
|
+
end
|
571
|
+
end
|
572
|
+
end
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
end
|
577
|
+
if r1
|
578
|
+
s0 << r1
|
579
|
+
else
|
580
|
+
break
|
581
|
+
end
|
582
|
+
end
|
583
|
+
if s0.empty?
|
584
|
+
@index = i0
|
585
|
+
r0 = nil
|
586
|
+
else
|
587
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
588
|
+
r0.extend(Comparator0)
|
589
|
+
end
|
590
|
+
|
591
|
+
node_cache[:comparator][start_index] = r0
|
592
|
+
|
593
|
+
r0
|
594
|
+
end
|
595
|
+
|
596
|
+
module Text0
|
597
|
+
def space
|
598
|
+
elements[0]
|
599
|
+
end
|
600
|
+
|
601
|
+
end
|
602
|
+
|
603
|
+
module Text1
|
604
|
+
end
|
605
|
+
|
606
|
+
def _nt_text
|
607
|
+
start_index = index
|
608
|
+
if node_cache[:text].has_key?(index)
|
609
|
+
cached = node_cache[:text][index]
|
610
|
+
if cached
|
611
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
612
|
+
@index = cached.interval.end
|
613
|
+
end
|
614
|
+
return cached
|
615
|
+
end
|
616
|
+
|
617
|
+
i0, s0 = index, []
|
618
|
+
s1, i1 = [], index
|
619
|
+
loop do
|
620
|
+
i2 = index
|
621
|
+
r3 = _nt_alphanumeric
|
622
|
+
if r3
|
623
|
+
r2 = r3
|
624
|
+
else
|
625
|
+
r4 = _nt_utf8
|
626
|
+
if r4
|
627
|
+
r2 = r4
|
628
|
+
else
|
629
|
+
r5 = _nt_symbol
|
630
|
+
if r5
|
631
|
+
r2 = r5
|
632
|
+
else
|
633
|
+
@index = i2
|
634
|
+
r2 = nil
|
635
|
+
end
|
636
|
+
end
|
637
|
+
end
|
638
|
+
if r2
|
639
|
+
s1 << r2
|
640
|
+
else
|
641
|
+
break
|
642
|
+
end
|
643
|
+
end
|
644
|
+
if s1.empty?
|
645
|
+
@index = i1
|
646
|
+
r1 = nil
|
647
|
+
else
|
648
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
649
|
+
end
|
650
|
+
s0 << r1
|
651
|
+
if r1
|
652
|
+
s6, i6 = [], index
|
653
|
+
loop do
|
654
|
+
i7, s7 = index, []
|
655
|
+
r8 = _nt_space
|
656
|
+
s7 << r8
|
657
|
+
if r8
|
658
|
+
s9, i9 = [], index
|
659
|
+
loop do
|
660
|
+
i10 = index
|
661
|
+
r11 = _nt_alphanumeric
|
662
|
+
if r11
|
663
|
+
r10 = r11
|
664
|
+
else
|
665
|
+
r12 = _nt_utf8
|
666
|
+
if r12
|
667
|
+
r10 = r12
|
668
|
+
else
|
669
|
+
r13 = _nt_symbol
|
670
|
+
if r13
|
671
|
+
r10 = r13
|
672
|
+
else
|
673
|
+
@index = i10
|
674
|
+
r10 = nil
|
675
|
+
end
|
676
|
+
end
|
677
|
+
end
|
678
|
+
if r10
|
679
|
+
s9 << r10
|
680
|
+
else
|
681
|
+
break
|
682
|
+
end
|
683
|
+
end
|
684
|
+
if s9.empty?
|
685
|
+
@index = i9
|
686
|
+
r9 = nil
|
687
|
+
else
|
688
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
689
|
+
end
|
690
|
+
s7 << r9
|
691
|
+
end
|
692
|
+
if s7.last
|
693
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
694
|
+
r7.extend(Text0)
|
695
|
+
else
|
696
|
+
@index = i7
|
697
|
+
r7 = nil
|
698
|
+
end
|
699
|
+
if r7
|
700
|
+
s6 << r7
|
701
|
+
else
|
702
|
+
break
|
703
|
+
end
|
704
|
+
end
|
705
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
706
|
+
s0 << r6
|
707
|
+
end
|
708
|
+
if s0.last
|
709
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
710
|
+
r0.extend(Text1)
|
711
|
+
else
|
712
|
+
@index = i0
|
713
|
+
r0 = nil
|
714
|
+
end
|
715
|
+
|
716
|
+
node_cache[:text][start_index] = r0
|
717
|
+
|
718
|
+
r0
|
719
|
+
end
|
720
|
+
|
721
|
+
def _nt_alphanumeric
|
722
|
+
start_index = index
|
723
|
+
if node_cache[:alphanumeric].has_key?(index)
|
724
|
+
cached = node_cache[:alphanumeric][index]
|
725
|
+
if cached
|
726
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
727
|
+
@index = cached.interval.end
|
728
|
+
end
|
729
|
+
return cached
|
730
|
+
end
|
731
|
+
|
732
|
+
s0, i0 = [], index
|
733
|
+
loop do
|
734
|
+
if has_terminal?('\G[a-zA-Z0-9_.]', true, index)
|
735
|
+
r1 = true
|
736
|
+
@index += 1
|
737
|
+
else
|
738
|
+
r1 = nil
|
739
|
+
end
|
740
|
+
if r1
|
741
|
+
s0 << r1
|
742
|
+
else
|
743
|
+
break
|
744
|
+
end
|
745
|
+
end
|
746
|
+
if s0.empty?
|
747
|
+
@index = i0
|
748
|
+
r0 = nil
|
749
|
+
else
|
750
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
751
|
+
end
|
752
|
+
|
753
|
+
node_cache[:alphanumeric][start_index] = r0
|
754
|
+
|
755
|
+
r0
|
756
|
+
end
|
757
|
+
|
758
|
+
def _nt_space
|
759
|
+
start_index = index
|
760
|
+
if node_cache[:space].has_key?(index)
|
761
|
+
cached = node_cache[:space][index]
|
762
|
+
if cached
|
763
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
764
|
+
@index = cached.interval.end
|
765
|
+
end
|
766
|
+
return cached
|
767
|
+
end
|
768
|
+
|
769
|
+
s0, i0 = [], index
|
770
|
+
loop do
|
771
|
+
if has_terminal?(' ', false, index)
|
772
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
773
|
+
@index += 1
|
774
|
+
else
|
775
|
+
terminal_parse_failure(' ')
|
776
|
+
r1 = nil
|
777
|
+
end
|
778
|
+
if r1
|
779
|
+
s0 << r1
|
780
|
+
else
|
781
|
+
break
|
782
|
+
end
|
783
|
+
end
|
784
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
785
|
+
|
786
|
+
node_cache[:space][start_index] = r0
|
787
|
+
|
788
|
+
r0
|
789
|
+
end
|
790
|
+
|
791
|
+
def _nt_symbol
|
792
|
+
start_index = index
|
793
|
+
if node_cache[:symbol].has_key?(index)
|
794
|
+
cached = node_cache[:symbol][index]
|
795
|
+
if cached
|
796
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
797
|
+
@index = cached.interval.end
|
798
|
+
end
|
799
|
+
return cached
|
800
|
+
end
|
801
|
+
|
802
|
+
if has_terminal?('\G[><=+-\\/\\\\@#$%!?:]', true, index)
|
803
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
804
|
+
@index += 1
|
805
|
+
else
|
806
|
+
r0 = nil
|
807
|
+
end
|
808
|
+
|
809
|
+
node_cache[:symbol][start_index] = r0
|
810
|
+
|
811
|
+
r0
|
812
|
+
end
|
813
|
+
|
814
|
+
def _nt_utf8
|
815
|
+
start_index = index
|
816
|
+
if node_cache[:utf8].has_key?(index)
|
817
|
+
cached = node_cache[:utf8][index]
|
818
|
+
if cached
|
819
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
820
|
+
@index = cached.interval.end
|
821
|
+
end
|
822
|
+
return cached
|
823
|
+
end
|
824
|
+
|
825
|
+
if has_terminal?('\G[\\u00c0\\u00c1\\u00c2\\u00c3\\u00c4\\u00c7\\u00c8\\u00c9\\u00ca\\u00cb\\u00cc\\u00cd\\u00ce\\u00cf\\u00d1\\u00d2\\u00d3\\u00d4\\u00d5\\u00d6\\u00d9\\u00da\\u00db\\u00dc\\u00e0\\u00e1\\u00e2\\u00e3\\u00e4\\u00e7\\u00e8\\u00e9\\u00ea\\u00eb\\u00ec\\u00ed\\u00ee\\u00ef\\u00f1\\u00f2\\u00f3\\u00f4\\u00f5\\u00f6\\u00f9\\u00fa\\u00fb\\u00fc]', true, index)
|
826
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
827
|
+
@index += 1
|
828
|
+
else
|
829
|
+
r0 = nil
|
830
|
+
end
|
831
|
+
|
832
|
+
node_cache[:utf8][start_index] = r0
|
833
|
+
|
834
|
+
r0
|
835
|
+
end
|
836
|
+
|
837
|
+
end
|
838
|
+
|
839
|
+
class SyntaxParser < Treetop::Runtime::CompiledParser
|
840
|
+
include Syntax
|
841
|
+
end
|
842
|
+
|
761
843
|
end
|