logical_query_parser 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8005a57b1dd4e044f6755066a55bc40f1435e6a
4
- data.tar.gz: 063e0c5f78b1ca4440203cce18769cfe90f6cde4
3
+ metadata.gz: 8f62acc3ca3efe725b46798c405985136dcd0702
4
+ data.tar.gz: 56e9d416089645c652649782a1c3d320a6bedc05
5
5
  SHA512:
6
- metadata.gz: c5c6e4b62fc124139ada278d98e6a6fcd5cfb630d01d55a5bae29c578929e0628a704db17982e88173d52e59d91db1d4e0eaf7aeaa6d3563fd75315aa0d0737d
7
- data.tar.gz: 37d9daf9cbbc43eb052b3e1574bd120102618cb376b851271f4ff5929573c891352473f391697857a31c977f75fa3f4a59fca7a022db277a43d2e95401ae3733
6
+ metadata.gz: 83df4ab258dce60d775a4d0548b4f20e25ac26d0f424fc734ea70cc579a9664ecaeaefcb3c593901629428d8954ce7ac60a3682bc32c523232c0c5de0f804ac1
7
+ data.tar.gz: 1ac865f2c09148e70e0da1ba31c964b53ebdf6fc31dbedb5cd602c1b5dceb74f46177ee6bb9442511ffe6679696035e9ffb287e9cf354685c873be1a6b93f69c
data/.travis.yml CHANGED
@@ -1,5 +1,12 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.12.5
4
+ - 2.3.4
5
+ - 2.4.1
6
+ gemfile:
7
+ - gemfiles/rails42.gemfile
8
+ - gemfiles/rails50.gemfile
9
+ - gemfiles/rails51.gemfile
10
+ before_install:
11
+ - gem install bundler -v 1.15.3
12
+ script: bundle exec rspec
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  A parser to generate a tree structure from a logical search query string using treetop.
4
4
 
5
- ## Requirements
5
+ ## Dependencies
6
6
 
7
- * ruby 2.3 or lator
8
- * treetop 1.6 or lator
9
- * activerecord 4.2 or lator (optional)
7
+ * ruby 2.3+
8
+ * treetop 1.6+
9
+ * activerecord 4.2+ (optional)
10
10
 
11
11
  ## Installation
12
12
 
@@ -28,17 +28,11 @@ Or install it yourself as:
28
28
 
29
29
  You can parse a logical query string as follows:
30
30
 
31
- ```ruby
32
- parser = LogicalQueryParser.new
33
- parser.parse('a AND b')
34
- ```
35
-
36
- Return value is a syntax tree of treetop:
37
-
38
31
  ```ruby
39
32
  parser = LogicalQueryParser.new
40
33
  parser.parse('a AND b')
41
34
 
35
+ # return value is a syntax tree of treetop
42
36
  => SyntaxNode+Exp0+ExpNode offset=0, "a AND b" (any):
43
37
  SyntaxNode+Cond0+CondNode offset=0, "a AND b" (lexp,logic,rexp):
44
38
  SyntaxNode+Literal0+LiteralNode offset=0, "a" (word,negative):
@@ -72,16 +66,14 @@ You can also parse negative conditions:
72
66
 
73
67
  ```
74
68
  parser = LogicalQueryParser.new
75
- parser.parse('("a a" AND -"b b") OR (c AND -d)')
69
+ parser.parse('("a a" AND NOT "b b") OR (c AND -d)')
76
70
  ```
77
71
 
78
72
  ### Supported operators
79
73
 
80
- You can parse a query string with following operators:
81
-
82
- * AND / and: represents an AND logic.
83
- * OR / or: represents an OR logic.
84
- * \-: represents a NOT logic. This should precede to a word.
74
+ * AND / and / &: represents an AND logic.
75
+ * OR / or / |: represents an OR logic.
76
+ * NOT / \-: represents a NOT logic. This should precede to a word or a parenthesis.
85
77
  * (: represents beginning of a nested expression.
86
78
  * ): represents end of a nested expression.
87
79
  * ": represents beginning or end of a quoted word.
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "activerecord", "~> 4.2.9"
4
+
5
+ # Specify your gem's dependencies in params_keeper_rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "activerecord", "~> 5.0.5"
4
+
5
+ # Specify your gem's dependencies in params_keeper_rails.gemspec
6
+ gemspec path: "../"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "activerecord", "~> 5.1.3"
4
+
5
+ # Specify your gem's dependencies in params_keeper_rails.gemspec
6
+ gemspec path: "../"
@@ -1,22 +1,22 @@
1
1
  grammar LogicalQuery
2
2
  rule exp
3
- any:(cond / exp_paren / literal_seq / literal) <ExpNode>
3
+ sp* exp:(logic_exp / paren_exp / literal_exp / literal) sp* <ExpNode>
4
4
  end
5
5
 
6
- rule exp_paren
7
- lparen sp* exp sp* rparen <ExpParenNode>
6
+ rule logic_exp
7
+ lexp:(paren_exp / literal_exp / literal) logic:(and / or) rexp:exp <LogicExpNode>
8
8
  end
9
9
 
10
- rule cond
11
- lexp:(exp_paren / literal) sp+ logic:(land / lor) sp+ rexp:exp <CondNode>
10
+ rule paren_exp
11
+ negative:not* lparen exp rparen rexp:exp* <ParenExpNode>
12
12
  end
13
13
 
14
- rule literal_seq
15
- lliteral:literal sp+ rliteral:(literal_seq / literal) <LiteralSeqNode>
14
+ rule literal_exp
15
+ literal sp+ exp <LiteralExpNode>
16
16
  end
17
17
 
18
18
  rule literal
19
- negative:negative* word <LiteralNode>
19
+ negative:not* word <LiteralNode>
20
20
  end
21
21
 
22
22
  rule word
@@ -31,14 +31,6 @@ grammar LogicalQuery
31
31
  atom+
32
32
  end
33
33
 
34
- rule land
35
- ('AND' / 'and') <AndNode>
36
- end
37
-
38
- rule lor
39
- ('OR' / 'or') <OrNode>
40
- end
41
-
42
34
  rule lparen
43
35
  '(' <LParenNode>
44
36
  end
@@ -47,8 +39,32 @@ grammar LogicalQuery
47
39
  ')' <RParenNode>
48
40
  end
49
41
 
50
- rule negative
51
- ('-' / '-' / '-') <NegativeNode>
42
+ rule and
43
+ sp+ and_ope sp+ <AndNode>
44
+ end
45
+
46
+ rule or
47
+ sp+ or_ope sp+ <OrNode>
48
+ end
49
+
50
+ rule not
51
+ (not_ope sp+ / not_sym sp*) <NotNode>
52
+ end
53
+
54
+ rule and_ope
55
+ 'AND' / 'and' / '&&' / '&'
56
+ end
57
+
58
+ rule or_ope
59
+ 'OR' / 'or' / '||' / '|'
60
+ end
61
+
62
+ rule not_ope
63
+ 'NOT' / 'not'
64
+ end
65
+
66
+ rule not_sym
67
+ '-' / '-' / '-'
52
68
  end
53
69
 
54
70
  rule sp
@@ -56,7 +72,6 @@ grammar LogicalQuery
56
72
  end
57
73
 
58
74
  rule atom
59
- !(lparen / rparen / negative / sp) .
75
+ !(lparen / rparen /and_ope / or_ope / not_ope / not_sym / sp) .
60
76
  end
61
77
  end
62
-
@@ -1,19 +1,27 @@
1
1
  module LogicalQuery
2
2
  module ExpNode
3
3
  def to_sql(opts = {}, sql = '')
4
- any.to_sql(opts, sql)
4
+ exp.to_sql(opts, sql)
5
5
  end
6
6
  end
7
7
 
8
- module ExpParenNode
8
+ module ParenExpNode
9
9
  def to_sql(opts, sql = '')
10
+ if negative.elements.size > 0
11
+ negative.elements[0].to_sql(opts, sql)
12
+ end
10
13
  lparen.to_sql(opts, sql)
11
14
  exp.to_sql(opts, sql)
12
15
  rparen.to_sql(opts, sql)
16
+ if rexp.elements.size > 0
17
+ sql += ' AND '
18
+ rexp.elements[0].to_sql(opts, sql)
19
+ end
20
+ sql
13
21
  end
14
22
  end
15
23
 
16
- module CondNode
24
+ module LogicExpNode
17
25
  def to_sql(opts, sql = '')
18
26
  lexp.to_sql(opts, sql)
19
27
  logic.to_sql(opts, sql)
@@ -21,6 +29,14 @@ module LogicalQuery
21
29
  end
22
30
  end
23
31
 
32
+ module LiteralExpNode
33
+ def to_sql(opts, sql = '')
34
+ literal.to_sql(opts, sql)
35
+ sql << ' AND '
36
+ exp.to_sql(opts, sql)
37
+ end
38
+ end
39
+
24
40
  module LParenNode
25
41
  def to_sql(opts, sql = '')
26
42
  sql << '('
@@ -45,11 +61,9 @@ module LogicalQuery
45
61
  end
46
62
  end
47
63
 
48
- module LiteralSeqNode
64
+ module NotNode
49
65
  def to_sql(opts, sql = '')
50
- lliteral.to_sql(opts, sql)
51
- sql << ' AND '
52
- rliteral.to_sql(opts, sql)
66
+ sql << 'NOT '
53
67
  end
54
68
  end
55
69
 
@@ -58,9 +72,10 @@ module LogicalQuery
58
72
  operator, logic = negative.elements.size > 0 ? [:does_not_match, :and] : [:matches, :or]
59
73
  unquoted = LogicalQuery.unquote(word.text_value)
60
74
 
61
- arel_table = opts[:model].arel_table
62
- relations = opts[:columns].map { |c| arel_table[c].send(operator, "%#{unquoted}%") }.reduce(logic)
63
- sql << relations.to_sql
75
+ arel = opts[:model].arel_table
76
+ ss = opts[:columns].map { |c| arel[c].send(operator, "%#{unquoted}%") }.reduce(logic).to_sql
77
+ ss = "(#{ss})" if ss[0] != '(' && ss[-1] != ')'
78
+ sql << ss
64
79
  end
65
80
  end
66
81
 
@@ -2,13 +2,13 @@ module LogicalQuery
2
2
  module ExpNode
3
3
  end
4
4
 
5
- module ExpParenNode
5
+ module ParenExpNode
6
6
  end
7
7
 
8
- module CondNode
8
+ module LogicExpNode
9
9
  end
10
10
 
11
- module LiteralSeqNode
11
+ module LiteralExpNode
12
12
  end
13
13
 
14
14
  module LiteralNode
@@ -23,12 +23,12 @@ module LogicalQuery
23
23
  module OrNode
24
24
  end
25
25
 
26
- module LParenNode
26
+ module NotNode
27
27
  end
28
28
 
29
- module RParenNode
29
+ module LParenNode
30
30
  end
31
31
 
32
- module NegativeNode
32
+ module RParenNode
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module LogicalQuery
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,9 +1,10 @@
1
1
  require 'treetop'
2
- require 'logical_query'
3
2
  require 'logical_query_parser/version'
4
3
  require 'logical_query_parser/nodes/base'
5
4
  require 'logical_query_parser/nodes/active_record' if defined? ActiveRecord::Base
6
5
 
6
+ Treetop.load File.expand_path("../logical_query.treetop", __FILE__)
7
+
7
8
  class LogicalQueryParser < Treetop::Runtime::CompiledParser
8
9
  class << self
9
10
  def walk_tree(node, &block)
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "treetop", "~> 1.6.8"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.12"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.0"
27
- spec.add_development_dependency "simplecov", "~> 0.12.0"
28
- spec.add_development_dependency "activerecord", ">= 4.2"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "activerecord"
29
29
  spec.add_development_dependency "sqlite3"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logical_query_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshikazu Kaneta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2017-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop
@@ -28,72 +28,72 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.12'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.12.0
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.12.0
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '4.2'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '4.2'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +126,9 @@ files:
126
126
  - Rakefile
127
127
  - bin/console
128
128
  - bin/setup
129
- - lib/logical_query.rb
129
+ - gemfiles/rails42.gemfile
130
+ - gemfiles/rails50.gemfile
131
+ - gemfiles/rails51.gemfile
130
132
  - lib/logical_query.treetop
131
133
  - lib/logical_query_parser.rb
132
134
  - lib/logical_query_parser/nodes/active_record.rb
@@ -153,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  version: '0'
154
156
  requirements: []
155
157
  rubyforge_project:
156
- rubygems_version: 2.5.1
158
+ rubygems_version: 2.6.12
157
159
  signing_key:
158
160
  specification_version: 4
159
161
  summary: A parser for a logical query string.
data/lib/logical_query.rb DELETED
@@ -1,889 +0,0 @@
1
- # Autogenerated from a Treetop grammar. Edits may be lost.
2
-
3
-
4
- module LogicalQuery
5
- include Treetop::Runtime
6
-
7
- def root
8
- @root ||= :exp
9
- end
10
-
11
- module Exp0
12
- def any
13
- elements[0]
14
- end
15
- end
16
-
17
- def _nt_exp
18
- start_index = index
19
- if node_cache[:exp].has_key?(index)
20
- cached = node_cache[:exp][index]
21
- if cached
22
- node_cache[:exp][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
23
- @index = cached.interval.end
24
- end
25
- return cached
26
- end
27
-
28
- i0, s0 = index, []
29
- i1 = index
30
- r2 = _nt_cond
31
- if r2
32
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
33
- r1 = r2
34
- else
35
- r3 = _nt_exp_paren
36
- if r3
37
- r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
38
- r1 = r3
39
- else
40
- r4 = _nt_literal_seq
41
- if r4
42
- r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
43
- r1 = r4
44
- else
45
- r5 = _nt_literal
46
- if r5
47
- r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
48
- r1 = r5
49
- else
50
- @index = i1
51
- r1 = nil
52
- end
53
- end
54
- end
55
- end
56
- s0 << r1
57
- if s0.last
58
- r0 = instantiate_node(ExpNode,input, i0...index, s0)
59
- r0.extend(Exp0)
60
- else
61
- @index = i0
62
- r0 = nil
63
- end
64
-
65
- node_cache[:exp][start_index] = r0
66
-
67
- r0
68
- end
69
-
70
- module ExpParen0
71
- def lparen
72
- elements[0]
73
- end
74
-
75
- def exp
76
- elements[2]
77
- end
78
-
79
- def rparen
80
- elements[4]
81
- end
82
- end
83
-
84
- def _nt_exp_paren
85
- start_index = index
86
- if node_cache[:exp_paren].has_key?(index)
87
- cached = node_cache[:exp_paren][index]
88
- if cached
89
- node_cache[:exp_paren][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
90
- @index = cached.interval.end
91
- end
92
- return cached
93
- end
94
-
95
- i0, s0 = index, []
96
- r1 = _nt_lparen
97
- s0 << r1
98
- if r1
99
- s2, i2 = [], index
100
- loop do
101
- r3 = _nt_sp
102
- if r3
103
- s2 << r3
104
- else
105
- break
106
- end
107
- end
108
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
109
- s0 << r2
110
- if r2
111
- r4 = _nt_exp
112
- s0 << r4
113
- if r4
114
- s5, i5 = [], index
115
- loop do
116
- r6 = _nt_sp
117
- if r6
118
- s5 << r6
119
- else
120
- break
121
- end
122
- end
123
- r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
124
- s0 << r5
125
- if r5
126
- r7 = _nt_rparen
127
- s0 << r7
128
- end
129
- end
130
- end
131
- end
132
- if s0.last
133
- r0 = instantiate_node(ExpParenNode,input, i0...index, s0)
134
- r0.extend(ExpParen0)
135
- else
136
- @index = i0
137
- r0 = nil
138
- end
139
-
140
- node_cache[:exp_paren][start_index] = r0
141
-
142
- r0
143
- end
144
-
145
- module Cond0
146
- def lexp
147
- elements[0]
148
- end
149
-
150
- def logic
151
- elements[2]
152
- end
153
-
154
- def rexp
155
- elements[4]
156
- end
157
- end
158
-
159
- def _nt_cond
160
- start_index = index
161
- if node_cache[:cond].has_key?(index)
162
- cached = node_cache[:cond][index]
163
- if cached
164
- node_cache[:cond][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
165
- @index = cached.interval.end
166
- end
167
- return cached
168
- end
169
-
170
- i0, s0 = index, []
171
- i1 = index
172
- r2 = _nt_exp_paren
173
- if r2
174
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
175
- r1 = r2
176
- else
177
- r3 = _nt_literal
178
- if r3
179
- r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
180
- r1 = r3
181
- else
182
- @index = i1
183
- r1 = nil
184
- end
185
- end
186
- s0 << r1
187
- if r1
188
- s4, i4 = [], index
189
- loop do
190
- r5 = _nt_sp
191
- if r5
192
- s4 << r5
193
- else
194
- break
195
- end
196
- end
197
- if s4.empty?
198
- @index = i4
199
- r4 = nil
200
- else
201
- r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
202
- end
203
- s0 << r4
204
- if r4
205
- i6 = index
206
- r7 = _nt_land
207
- if r7
208
- r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
209
- r6 = r7
210
- else
211
- r8 = _nt_lor
212
- if r8
213
- r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
214
- r6 = r8
215
- else
216
- @index = i6
217
- r6 = nil
218
- end
219
- end
220
- s0 << r6
221
- if r6
222
- s9, i9 = [], index
223
- loop do
224
- r10 = _nt_sp
225
- if r10
226
- s9 << r10
227
- else
228
- break
229
- end
230
- end
231
- if s9.empty?
232
- @index = i9
233
- r9 = nil
234
- else
235
- r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
236
- end
237
- s0 << r9
238
- if r9
239
- r11 = _nt_exp
240
- s0 << r11
241
- end
242
- end
243
- end
244
- end
245
- if s0.last
246
- r0 = instantiate_node(CondNode,input, i0...index, s0)
247
- r0.extend(Cond0)
248
- else
249
- @index = i0
250
- r0 = nil
251
- end
252
-
253
- node_cache[:cond][start_index] = r0
254
-
255
- r0
256
- end
257
-
258
- module LiteralSeq0
259
- def lliteral
260
- elements[0]
261
- end
262
-
263
- def rliteral
264
- elements[2]
265
- end
266
- end
267
-
268
- def _nt_literal_seq
269
- start_index = index
270
- if node_cache[:literal_seq].has_key?(index)
271
- cached = node_cache[:literal_seq][index]
272
- if cached
273
- node_cache[:literal_seq][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
274
- @index = cached.interval.end
275
- end
276
- return cached
277
- end
278
-
279
- i0, s0 = index, []
280
- r1 = _nt_literal
281
- s0 << r1
282
- if r1
283
- s2, i2 = [], index
284
- loop do
285
- r3 = _nt_sp
286
- if r3
287
- s2 << r3
288
- else
289
- break
290
- end
291
- end
292
- if s2.empty?
293
- @index = i2
294
- r2 = nil
295
- else
296
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
297
- end
298
- s0 << r2
299
- if r2
300
- i4 = index
301
- r5 = _nt_literal_seq
302
- if r5
303
- r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
304
- r4 = r5
305
- else
306
- r6 = _nt_literal
307
- if r6
308
- r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
309
- r4 = r6
310
- else
311
- @index = i4
312
- r4 = nil
313
- end
314
- end
315
- s0 << r4
316
- end
317
- end
318
- if s0.last
319
- r0 = instantiate_node(LiteralSeqNode,input, i0...index, s0)
320
- r0.extend(LiteralSeq0)
321
- else
322
- @index = i0
323
- r0 = nil
324
- end
325
-
326
- node_cache[:literal_seq][start_index] = r0
327
-
328
- r0
329
- end
330
-
331
- module Literal0
332
- def negative
333
- elements[0]
334
- end
335
-
336
- def word
337
- elements[1]
338
- end
339
- end
340
-
341
- def _nt_literal
342
- start_index = index
343
- if node_cache[:literal].has_key?(index)
344
- cached = node_cache[:literal][index]
345
- if cached
346
- node_cache[:literal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
347
- @index = cached.interval.end
348
- end
349
- return cached
350
- end
351
-
352
- i0, s0 = index, []
353
- s1, i1 = [], index
354
- loop do
355
- r2 = _nt_negative
356
- if r2
357
- s1 << r2
358
- else
359
- break
360
- end
361
- end
362
- r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
363
- s0 << r1
364
- if r1
365
- r3 = _nt_word
366
- s0 << r3
367
- end
368
- if s0.last
369
- r0 = instantiate_node(LiteralNode,input, i0...index, s0)
370
- r0.extend(Literal0)
371
- else
372
- @index = i0
373
- r0 = nil
374
- end
375
-
376
- node_cache[:literal][start_index] = r0
377
-
378
- r0
379
- end
380
-
381
- def _nt_word
382
- start_index = index
383
- if node_cache[:word].has_key?(index)
384
- cached = node_cache[:word][index]
385
- if cached
386
- node_cache[:word][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
387
- @index = cached.interval.end
388
- end
389
- return cached
390
- end
391
-
392
- i0 = index
393
- r1 = _nt_quoted_word
394
- if r1
395
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
396
- r0 = r1
397
- r0.extend(WordNode)
398
- else
399
- r2 = _nt_unquoted_word
400
- if r2
401
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
402
- r0 = r2
403
- r0.extend(WordNode)
404
- else
405
- @index = i0
406
- r0 = nil
407
- end
408
- end
409
-
410
- node_cache[:word][start_index] = r0
411
-
412
- r0
413
- end
414
-
415
- module QuotedWord0
416
- end
417
-
418
- module QuotedWord1
419
- end
420
-
421
- def _nt_quoted_word
422
- start_index = index
423
- if node_cache[:quoted_word].has_key?(index)
424
- cached = node_cache[:quoted_word][index]
425
- if cached
426
- node_cache[:quoted_word][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
427
- @index = cached.interval.end
428
- end
429
- return cached
430
- end
431
-
432
- i0, s0 = index, []
433
- if (match_len = has_terminal?('"', false, index))
434
- r1 = true
435
- @index += match_len
436
- else
437
- terminal_parse_failure('\'"\'')
438
- r1 = nil
439
- end
440
- s0 << r1
441
- if r1
442
- s2, i2 = [], index
443
- loop do
444
- i3 = index
445
- if (match_len = has_terminal?('\"', false, index))
446
- r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
447
- @index += match_len
448
- else
449
- terminal_parse_failure('\'\\"\'')
450
- r4 = nil
451
- end
452
- if r4
453
- r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
454
- r3 = r4
455
- else
456
- i5, s5 = index, []
457
- i6 = index
458
- if (match_len = has_terminal?('"', false, index))
459
- r7 = true
460
- @index += match_len
461
- else
462
- terminal_parse_failure('\'"\'')
463
- r7 = nil
464
- end
465
- if r7
466
- @index = i6
467
- r6 = nil
468
- terminal_parse_failure('\'"\'', true)
469
- else
470
- @terminal_failures.pop
471
- @index = i6
472
- r6 = instantiate_node(SyntaxNode,input, index...index)
473
- end
474
- s5 << r6
475
- if r6
476
- if index < input_length
477
- r8 = true
478
- @index += 1
479
- else
480
- terminal_parse_failure("any character")
481
- r8 = nil
482
- end
483
- s5 << r8
484
- end
485
- if s5.last
486
- r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
487
- r5.extend(QuotedWord0)
488
- else
489
- @index = i5
490
- r5 = nil
491
- end
492
- if r5
493
- r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
494
- r3 = r5
495
- else
496
- @index = i3
497
- r3 = nil
498
- end
499
- end
500
- if r3
501
- s2 << r3
502
- else
503
- break
504
- end
505
- end
506
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
507
- s0 << r2
508
- if r2
509
- if (match_len = has_terminal?('"', false, index))
510
- r9 = true
511
- @index += match_len
512
- else
513
- terminal_parse_failure('\'"\'')
514
- r9 = nil
515
- end
516
- s0 << r9
517
- end
518
- end
519
- if s0.last
520
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
521
- r0.extend(QuotedWord1)
522
- else
523
- @index = i0
524
- r0 = nil
525
- end
526
-
527
- node_cache[:quoted_word][start_index] = r0
528
-
529
- r0
530
- end
531
-
532
- def _nt_unquoted_word
533
- start_index = index
534
- if node_cache[:unquoted_word].has_key?(index)
535
- cached = node_cache[:unquoted_word][index]
536
- if cached
537
- node_cache[:unquoted_word][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
538
- @index = cached.interval.end
539
- end
540
- return cached
541
- end
542
-
543
- s0, i0 = [], index
544
- loop do
545
- r1 = _nt_atom
546
- if r1
547
- s0 << r1
548
- else
549
- break
550
- end
551
- end
552
- if s0.empty?
553
- @index = i0
554
- r0 = nil
555
- else
556
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
557
- end
558
-
559
- node_cache[:unquoted_word][start_index] = r0
560
-
561
- r0
562
- end
563
-
564
- def _nt_land
565
- start_index = index
566
- if node_cache[:land].has_key?(index)
567
- cached = node_cache[:land][index]
568
- if cached
569
- node_cache[:land][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
570
- @index = cached.interval.end
571
- end
572
- return cached
573
- end
574
-
575
- i0 = index
576
- if (match_len = has_terminal?('AND', false, index))
577
- r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
578
- @index += match_len
579
- else
580
- terminal_parse_failure('\'AND\'')
581
- r1 = nil
582
- end
583
- if r1
584
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
585
- r0 = r1
586
- r0.extend(AndNode)
587
- else
588
- if (match_len = has_terminal?('and', false, index))
589
- r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
590
- @index += match_len
591
- else
592
- terminal_parse_failure('\'and\'')
593
- r2 = nil
594
- end
595
- if r2
596
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
597
- r0 = r2
598
- r0.extend(AndNode)
599
- else
600
- @index = i0
601
- r0 = nil
602
- end
603
- end
604
-
605
- node_cache[:land][start_index] = r0
606
-
607
- r0
608
- end
609
-
610
- def _nt_lor
611
- start_index = index
612
- if node_cache[:lor].has_key?(index)
613
- cached = node_cache[:lor][index]
614
- if cached
615
- node_cache[:lor][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
616
- @index = cached.interval.end
617
- end
618
- return cached
619
- end
620
-
621
- i0 = index
622
- if (match_len = has_terminal?('OR', false, index))
623
- r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
624
- @index += match_len
625
- else
626
- terminal_parse_failure('\'OR\'')
627
- r1 = nil
628
- end
629
- if r1
630
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
631
- r0 = r1
632
- r0.extend(OrNode)
633
- else
634
- if (match_len = has_terminal?('or', false, index))
635
- r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
636
- @index += match_len
637
- else
638
- terminal_parse_failure('\'or\'')
639
- r2 = nil
640
- end
641
- if r2
642
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
643
- r0 = r2
644
- r0.extend(OrNode)
645
- else
646
- @index = i0
647
- r0 = nil
648
- end
649
- end
650
-
651
- node_cache[:lor][start_index] = r0
652
-
653
- r0
654
- end
655
-
656
- def _nt_lparen
657
- start_index = index
658
- if node_cache[:lparen].has_key?(index)
659
- cached = node_cache[:lparen][index]
660
- if cached
661
- node_cache[:lparen][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
662
- @index = cached.interval.end
663
- end
664
- return cached
665
- end
666
-
667
- if (match_len = has_terminal?('(', false, index))
668
- r0 = instantiate_node(LParenNode,input, index...(index + match_len))
669
- @index += match_len
670
- else
671
- terminal_parse_failure('\'(\'')
672
- r0 = nil
673
- end
674
-
675
- node_cache[:lparen][start_index] = r0
676
-
677
- r0
678
- end
679
-
680
- def _nt_rparen
681
- start_index = index
682
- if node_cache[:rparen].has_key?(index)
683
- cached = node_cache[:rparen][index]
684
- if cached
685
- node_cache[:rparen][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
686
- @index = cached.interval.end
687
- end
688
- return cached
689
- end
690
-
691
- if (match_len = has_terminal?(')', false, index))
692
- r0 = instantiate_node(RParenNode,input, index...(index + match_len))
693
- @index += match_len
694
- else
695
- terminal_parse_failure('\')\'')
696
- r0 = nil
697
- end
698
-
699
- node_cache[:rparen][start_index] = r0
700
-
701
- r0
702
- end
703
-
704
- def _nt_negative
705
- start_index = index
706
- if node_cache[:negative].has_key?(index)
707
- cached = node_cache[:negative][index]
708
- if cached
709
- node_cache[:negative][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
710
- @index = cached.interval.end
711
- end
712
- return cached
713
- end
714
-
715
- i0 = index
716
- if (match_len = has_terminal?('-', false, index))
717
- r1 = true
718
- @index += match_len
719
- else
720
- terminal_parse_failure('\'-\'')
721
- r1 = nil
722
- end
723
- if r1
724
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
725
- r0 = r1
726
- r0.extend(NegativeNode)
727
- else
728
- if (match_len = has_terminal?('-', false, index))
729
- r2 = true
730
- @index += match_len
731
- else
732
- terminal_parse_failure('\'-\'')
733
- r2 = nil
734
- end
735
- if r2
736
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
737
- r0 = r2
738
- r0.extend(NegativeNode)
739
- else
740
- if (match_len = has_terminal?('-', false, index))
741
- r3 = true
742
- @index += match_len
743
- else
744
- terminal_parse_failure('\'-\'')
745
- r3 = nil
746
- end
747
- if r3
748
- r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
749
- r0 = r3
750
- r0.extend(NegativeNode)
751
- else
752
- @index = i0
753
- r0 = nil
754
- end
755
- end
756
- end
757
-
758
- node_cache[:negative][start_index] = r0
759
-
760
- r0
761
- end
762
-
763
- def _nt_sp
764
- start_index = index
765
- if node_cache[:sp].has_key?(index)
766
- cached = node_cache[:sp][index]
767
- if cached
768
- node_cache[:sp][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
769
- @index = cached.interval.end
770
- end
771
- return cached
772
- end
773
-
774
- i0 = index
775
- if (match_len = has_terminal?(' ', false, index))
776
- r1 = true
777
- @index += match_len
778
- else
779
- terminal_parse_failure('\' \'')
780
- r1 = nil
781
- end
782
- if r1
783
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
784
- r0 = r1
785
- else
786
- if (match_len = has_terminal?(' ', false, index))
787
- r2 = true
788
- @index += match_len
789
- else
790
- terminal_parse_failure('\' \'')
791
- r2 = nil
792
- end
793
- if r2
794
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
795
- r0 = r2
796
- else
797
- @index = i0
798
- r0 = nil
799
- end
800
- end
801
-
802
- node_cache[:sp][start_index] = r0
803
-
804
- r0
805
- end
806
-
807
- module Atom0
808
- end
809
-
810
- def _nt_atom
811
- start_index = index
812
- if node_cache[:atom].has_key?(index)
813
- cached = node_cache[:atom][index]
814
- if cached
815
- node_cache[:atom][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
816
- @index = cached.interval.end
817
- end
818
- return cached
819
- end
820
-
821
- i0, s0 = index, []
822
- i1 = index
823
- i2 = index
824
- r3 = _nt_lparen
825
- if r3
826
- r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
827
- r2 = r3
828
- else
829
- r4 = _nt_rparen
830
- if r4
831
- r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
832
- r2 = r4
833
- else
834
- r5 = _nt_negative
835
- if r5
836
- r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
837
- r2 = r5
838
- else
839
- r6 = _nt_sp
840
- if r6
841
- r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
842
- r2 = r6
843
- else
844
- @index = i2
845
- r2 = nil
846
- end
847
- end
848
- end
849
- end
850
- if r2
851
- @index = i1
852
- r1 = nil
853
- terminal_parse_failure("(any alternative)", true)
854
- else
855
- @terminal_failures.pop
856
- @index = i1
857
- r1 = instantiate_node(SyntaxNode,input, index...index)
858
- end
859
- s0 << r1
860
- if r1
861
- if index < input_length
862
- r7 = true
863
- @index += 1
864
- else
865
- terminal_parse_failure("any character")
866
- r7 = nil
867
- end
868
- s0 << r7
869
- end
870
- if s0.last
871
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
872
- r0.extend(Atom0)
873
- else
874
- @index = i0
875
- r0 = nil
876
- end
877
-
878
- node_cache[:atom][start_index] = r0
879
-
880
- r0
881
- end
882
-
883
- end
884
-
885
- class LogicalQueryParser < Treetop::Runtime::CompiledParser
886
- include LogicalQuery
887
- end
888
-
889
-