nql 0.0.3 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: tyUx6a4cZK6H9VorUnDSz798WfDILLXUb
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
@@ -0,0 +1 @@
1
+ nql
@@ -0,0 +1 @@
1
+ ruby-2.5.0
@@ -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
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in nql.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nql.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
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
- Natural Query Language built on top of ActiveRecord and Ransack
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'nql'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install nql
18
-
19
- ## Supported comparators
20
-
21
- ----------------------------------
22
- | Symbol | Description |
23
- ----------------------------------
24
- | : | Contains |
25
- | = | Equals |
26
- | != | Not equals |
27
- | > | Grater than |
28
- | >= | Grater or equals than |
29
- | < | Less than |
30
- | <= | Less or equals than |
31
- ----------------------------------
32
-
33
-
34
- ## Usage
35
-
36
- Converts from natural language to query expression
37
-
38
- q = '(name: arg | name: br) & region = south'
39
- Country.search(NQL.to_ransack(q)).result.to_sql
40
- => "SELECT coutries.* FROM countries WHERE (countries.name LIKE '%arg%' OR countries.name LIKE '%br%') AND region = 'south'"
41
-
42
- ### Joins support
43
-
44
- q = 'cities.name: buenos'
45
- Country.search(NQL.to_ransack(q)).result.to_sql
46
- => "SELECT countries.* FROM countries LEFT OUTER JOIN cities ON countries.id = cities.country_id WHERE cities.name LIKE '%buenos%'"
47
-
48
- ## Contributing
49
-
50
- 1. Fork it
51
- 2. Create your feature branch (`git checkout -b my-new-feature`)
52
- 3. Commit your changes (`git commit -am 'Added some feature'`)
53
- 4. Push to the branch (`git push origin my-new-feature`)
54
- 5. Create new Pull Request
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
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
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/grammar'
8
- require 'nql/invalid_expression_error'
9
-
10
- module NQL
11
-
12
- def self.to_ransack(query)
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'
@@ -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
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Visitors
3
+ class ToSql
4
+ alias :visit_Integer :literal
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def deep_symbolize_keys
3
+ inject({}) { |result, (key, value)|
4
+ value = value.deep_symbolize_keys if value.is_a?(Hash)
5
+ result[(key.to_sym rescue key) || key] = value
6
+ result
7
+ }
8
+ end unless Hash.method_defined?(:deep_symbolize_keys)
9
+ end
@@ -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 expression
149
- elements[2]
150
- end
151
-
152
- def space2
153
- elements[3]
154
- end
155
-
156
- end
157
-
158
- module Primary2
159
- def to_ransack
160
- detect_node.to_ransack
161
- end
162
-
163
- def detect_node
164
- self.send %w(comparison expression).detect { |m| self.respond_to? m }
165
- end
166
-
167
- def is_node?(node_type)
168
- detect_node.is_node?(node_type)
169
- end
170
- end
171
-
172
- def _nt_primary
173
- start_index = index
174
- if node_cache[:primary].has_key?(index)
175
- cached = node_cache[:primary][index]
176
- if cached
177
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
178
- @index = cached.interval.end
179
- end
180
- return cached
181
- end
182
-
183
- i0 = index
184
- i1, s1 = index, []
185
- r2 = _nt_space
186
- s1 << r2
187
- if r2
188
- r3 = _nt_comparison
189
- s1 << r3
190
- if r3
191
- r4 = _nt_space
192
- s1 << r4
193
- end
194
- end
195
- if s1.last
196
- r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
197
- r1.extend(Primary0)
198
- else
199
- @index = i1
200
- r1 = nil
201
- end
202
- if r1
203
- r0 = r1
204
- r0.extend(Primary2)
205
- else
206
- i5, s5 = index, []
207
- if has_terminal?('(', false, index)
208
- r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
209
- @index += 1
210
- else
211
- terminal_parse_failure('(')
212
- r6 = nil
213
- end
214
- s5 << r6
215
- if r6
216
- r7 = _nt_space
217
- s5 << r7
218
- if r7
219
- r8 = _nt_expression
220
- s5 << r8
221
- if r8
222
- r9 = _nt_space
223
- s5 << r9
224
- if r9
225
- if has_terminal?(')', false, index)
226
- r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
227
- @index += 1
228
- else
229
- terminal_parse_failure(')')
230
- r10 = nil
231
- end
232
- s5 << r10
233
- end
234
- end
235
- end
236
- end
237
- if s5.last
238
- r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
239
- r5.extend(Primary1)
240
- else
241
- @index = i5
242
- r5 = nil
243
- end
244
- if r5
245
- r0 = r5
246
- r0.extend(Primary2)
247
- else
248
- @index = i0
249
- r0 = nil
250
- end
251
- end
252
-
253
- node_cache[:primary][start_index] = r0
254
-
255
- r0
256
- end
257
-
258
- module Coordinator0
259
- def to_ransack
260
- coordinators = {'|' => 'or', '&' => 'and'}
261
- coordinators[text_value]
262
- end
263
- end
264
-
265
- def _nt_coordinator
266
- start_index = index
267
- if node_cache[:coordinator].has_key?(index)
268
- cached = node_cache[:coordinator][index]
269
- if cached
270
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
271
- @index = cached.interval.end
272
- end
273
- return cached
274
- end
275
-
276
- i0 = index
277
- if has_terminal?('|', false, index)
278
- r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
279
- @index += 1
280
- else
281
- terminal_parse_failure('|')
282
- r1 = nil
283
- end
284
- if r1
285
- r0 = r1
286
- r0.extend(Coordinator0)
287
- else
288
- if has_terminal?('&', false, index)
289
- r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
290
- @index += 1
291
- else
292
- terminal_parse_failure('&')
293
- r2 = nil
294
- end
295
- if r2
296
- r0 = r2
297
- r0.extend(Coordinator0)
298
- else
299
- @index = i0
300
- r0 = nil
301
- end
302
- end
303
-
304
- node_cache[:coordinator][start_index] = r0
305
-
306
- r0
307
- end
308
-
309
- module Comparison0
310
- def variable
311
- elements[0]
312
- end
313
-
314
- def space1
315
- elements[1]
316
- end
317
-
318
- def comparator
319
- elements[2]
320
- end
321
-
322
- def space2
323
- elements[3]
324
- end
325
-
326
- def value
327
- elements[4]
328
- end
329
- end
330
-
331
- module Comparison1
332
- def to_ransack
333
- hash = {a: {'0' => {name: self.variable.text_value.gsub('.', '_')}}, p: self.comparator.to_ransack, v: {'0' => {value: self.value.text_value}}}
334
- hash = {c: [hash]} if !parent || !parent.parent || text_value == parent.parent.text_value
335
- hash
336
- end
337
-
338
- def is_node?(node_type)
339
- node_type.to_sym == :comparison
340
- end
341
- end
342
-
343
- def _nt_comparison
344
- start_index = index
345
- if node_cache[:comparison].has_key?(index)
346
- cached = node_cache[:comparison][index]
347
- if cached
348
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
349
- @index = cached.interval.end
350
- end
351
- return cached
352
- end
353
-
354
- i0, s0 = index, []
355
- r1 = _nt_alphanumeric
356
- s0 << r1
357
- if r1
358
- r2 = _nt_space
359
- s0 << r2
360
- if r2
361
- r3 = _nt_comparator
362
- s0 << r3
363
- if r3
364
- r4 = _nt_space
365
- s0 << r4
366
- if r4
367
- r5 = _nt_text
368
- s0 << r5
369
- end
370
- end
371
- end
372
- end
373
- if s0.last
374
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
375
- r0.extend(Comparison0)
376
- r0.extend(Comparison1)
377
- else
378
- @index = i0
379
- r0 = nil
380
- end
381
-
382
- node_cache[:comparison][start_index] = r0
383
-
384
- r0
385
- end
386
-
387
- module Comparator0
388
- def to_ransack
389
- comparators = {
390
- '=' => 'eq',
391
- '!=' => 'not_eq',
392
- '>' => 'gt',
393
- '>=' => 'gteq',
394
- '<' => 'lt',
395
- '<=' => 'lteq',
396
- ':' => 'cont'
397
- }
398
- comparators[text_value]
399
- end
400
- end
401
-
402
- def _nt_comparator
403
- start_index = index
404
- if node_cache[:comparator].has_key?(index)
405
- cached = node_cache[:comparator][index]
406
- if cached
407
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
408
- @index = cached.interval.end
409
- end
410
- return cached
411
- end
412
-
413
- s0, i0 = [], index
414
- loop do
415
- i1 = index
416
- if has_terminal?('=', false, index)
417
- r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
418
- @index += 1
419
- else
420
- terminal_parse_failure('=')
421
- r2 = nil
422
- end
423
- if r2
424
- r1 = r2
425
- else
426
- if has_terminal?('!=', false, index)
427
- r3 = instantiate_node(SyntaxNode,input, index...(index + 2))
428
- @index += 2
429
- else
430
- terminal_parse_failure('!=')
431
- r3 = nil
432
- end
433
- if r3
434
- r1 = r3
435
- else
436
- if has_terminal?('>', false, index)
437
- r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
438
- @index += 1
439
- else
440
- terminal_parse_failure('>')
441
- r4 = nil
442
- end
443
- if r4
444
- r1 = r4
445
- else
446
- if has_terminal?('>=', false, index)
447
- r5 = instantiate_node(SyntaxNode,input, index...(index + 2))
448
- @index += 2
449
- else
450
- terminal_parse_failure('>=')
451
- r5 = nil
452
- end
453
- if r5
454
- r1 = r5
455
- else
456
- if has_terminal?('<', false, index)
457
- r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
458
- @index += 1
459
- else
460
- terminal_parse_failure('<')
461
- r6 = nil
462
- end
463
- if r6
464
- r1 = r6
465
- else
466
- if has_terminal?('<=', false, index)
467
- r7 = instantiate_node(SyntaxNode,input, index...(index + 2))
468
- @index += 2
469
- else
470
- terminal_parse_failure('<=')
471
- r7 = nil
472
- end
473
- if r7
474
- r1 = r7
475
- else
476
- if has_terminal?(':', false, index)
477
- r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
478
- @index += 1
479
- else
480
- terminal_parse_failure(':')
481
- r8 = nil
482
- end
483
- if r8
484
- r1 = r8
485
- else
486
- @index = i1
487
- r1 = nil
488
- end
489
- end
490
- end
491
- end
492
- end
493
- end
494
- end
495
- if r1
496
- s0 << r1
497
- else
498
- break
499
- end
500
- end
501
- if s0.empty?
502
- @index = i0
503
- r0 = nil
504
- else
505
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
506
- r0.extend(Comparator0)
507
- end
508
-
509
- node_cache[:comparator][start_index] = r0
510
-
511
- r0
512
- end
513
-
514
- module Text0
515
- def space
516
- elements[0]
517
- end
518
-
519
- end
520
-
521
- module Text1
522
- end
523
-
524
- def _nt_text
525
- start_index = index
526
- if node_cache[:text].has_key?(index)
527
- cached = node_cache[:text][index]
528
- if cached
529
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
530
- @index = cached.interval.end
531
- end
532
- return cached
533
- end
534
-
535
- i0, s0 = index, []
536
- s1, i1 = [], index
537
- loop do
538
- i2 = index
539
- r3 = _nt_alphanumeric
540
- if r3
541
- r2 = r3
542
- else
543
- r4 = _nt_utf8
544
- if r4
545
- r2 = r4
546
- else
547
- r5 = _nt_symbol
548
- if r5
549
- r2 = r5
550
- else
551
- @index = i2
552
- r2 = nil
553
- end
554
- end
555
- end
556
- if r2
557
- s1 << r2
558
- else
559
- break
560
- end
561
- end
562
- if s1.empty?
563
- @index = i1
564
- r1 = nil
565
- else
566
- r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
567
- end
568
- s0 << r1
569
- if r1
570
- s6, i6 = [], index
571
- loop do
572
- i7, s7 = index, []
573
- r8 = _nt_space
574
- s7 << r8
575
- if r8
576
- s9, i9 = [], index
577
- loop do
578
- i10 = index
579
- r11 = _nt_alphanumeric
580
- if r11
581
- r10 = r11
582
- else
583
- r12 = _nt_utf8
584
- if r12
585
- r10 = r12
586
- else
587
- r13 = _nt_symbol
588
- if r13
589
- r10 = r13
590
- else
591
- @index = i10
592
- r10 = nil
593
- end
594
- end
595
- end
596
- if r10
597
- s9 << r10
598
- else
599
- break
600
- end
601
- end
602
- if s9.empty?
603
- @index = i9
604
- r9 = nil
605
- else
606
- r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
607
- end
608
- s7 << r9
609
- end
610
- if s7.last
611
- r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
612
- r7.extend(Text0)
613
- else
614
- @index = i7
615
- r7 = nil
616
- end
617
- if r7
618
- s6 << r7
619
- else
620
- break
621
- end
622
- end
623
- r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
624
- s0 << r6
625
- end
626
- if s0.last
627
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
628
- r0.extend(Text1)
629
- else
630
- @index = i0
631
- r0 = nil
632
- end
633
-
634
- node_cache[:text][start_index] = r0
635
-
636
- r0
637
- end
638
-
639
- def _nt_alphanumeric
640
- start_index = index
641
- if node_cache[:alphanumeric].has_key?(index)
642
- cached = node_cache[:alphanumeric][index]
643
- if cached
644
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
645
- @index = cached.interval.end
646
- end
647
- return cached
648
- end
649
-
650
- s0, i0 = [], index
651
- loop do
652
- if has_terminal?('\G[a-zA-Z0-9_.]', true, index)
653
- r1 = true
654
- @index += 1
655
- else
656
- r1 = nil
657
- end
658
- if r1
659
- s0 << r1
660
- else
661
- break
662
- end
663
- end
664
- if s0.empty?
665
- @index = i0
666
- r0 = nil
667
- else
668
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
669
- end
670
-
671
- node_cache[:alphanumeric][start_index] = r0
672
-
673
- r0
674
- end
675
-
676
- def _nt_space
677
- start_index = index
678
- if node_cache[:space].has_key?(index)
679
- cached = node_cache[:space][index]
680
- if cached
681
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
682
- @index = cached.interval.end
683
- end
684
- return cached
685
- end
686
-
687
- s0, i0 = [], index
688
- loop do
689
- if has_terminal?(' ', false, index)
690
- r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
691
- @index += 1
692
- else
693
- terminal_parse_failure(' ')
694
- r1 = nil
695
- end
696
- if r1
697
- s0 << r1
698
- else
699
- break
700
- end
701
- end
702
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
703
-
704
- node_cache[:space][start_index] = r0
705
-
706
- r0
707
- end
708
-
709
- def _nt_symbol
710
- start_index = index
711
- if node_cache[:symbol].has_key?(index)
712
- cached = node_cache[:symbol][index]
713
- if cached
714
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
715
- @index = cached.interval.end
716
- end
717
- return cached
718
- end
719
-
720
- if has_terminal?('\G[><=+-\\/\\\\@#$%!?:]', true, index)
721
- r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
722
- @index += 1
723
- else
724
- r0 = nil
725
- end
726
-
727
- node_cache[:symbol][start_index] = r0
728
-
729
- r0
730
- end
731
-
732
- def _nt_utf8
733
- start_index = index
734
- if node_cache[:utf8].has_key?(index)
735
- cached = node_cache[:utf8][index]
736
- if cached
737
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
738
- @index = cached.interval.end
739
- end
740
- return cached
741
- end
742
-
743
- if has_terminal?('\G[\\u00c1\\u00c0\\u00c9\\u00c8\\u00cd\\u00cc\\u00d3\\u00d2\\u00da\\u00d9\\u00dc\\u00d1\\u00c7\\u00e1\\u00e0\\u00e9\\u00e8\\u00ed\\u00ec\\u00f3\\u00f2\\u00fa\\u00f9\\u00fc\\u00f1\\u00e7]', true, index)
744
- r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
745
- @index += 1
746
- else
747
- r0 = nil
748
- end
749
-
750
- node_cache[:utf8][start_index] = r0
751
-
752
- r0
753
- end
754
-
755
- end
756
-
757
- class SyntaxParser < Treetop::Runtime::CompiledParser
758
- include Syntax
759
- end
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