rgviz 0.34 → 0.35
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rgviz/nodes.rb +26 -2
- data/lib/rgviz/parser.rb +10 -6
- data/lib/rgviz/visitor.rb +1 -1
- data/spec/rgviz/parser_spec.rb +12 -6
- metadata +3 -3
data/lib/rgviz/nodes.rb
CHANGED
@@ -203,9 +203,33 @@ module Rgviz
|
|
203
203
|
end
|
204
204
|
|
205
205
|
end
|
206
|
+
|
207
|
+
class LogicalExpression
|
208
|
+
And = Token::And
|
209
|
+
Or = Token::Or
|
210
|
+
|
211
|
+
attr_accessor :operator
|
212
|
+
attr_accessor :operands
|
213
|
+
|
214
|
+
def initialize(operator, operands)
|
215
|
+
@operator = operator
|
216
|
+
@operands = operands
|
217
|
+
end
|
218
|
+
|
219
|
+
def accept(visitor)
|
220
|
+
if visitor.visit_logical_expression(self)
|
221
|
+
operands.each{|x| x.accept visitor}
|
222
|
+
end
|
223
|
+
visitor.end_visit_logical_expression self
|
224
|
+
end
|
225
|
+
|
226
|
+
def to_s
|
227
|
+
operands.map(&:to_s).join(" #{operator} ")
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
206
231
|
|
207
232
|
class BinaryExpression
|
208
|
-
And = Token::And
|
209
233
|
Contains = Token::Contains
|
210
234
|
EndsWith = :'ends with'
|
211
235
|
Eq = Token::EQ
|
@@ -216,7 +240,7 @@ module Rgviz
|
|
216
240
|
Lte = Token::LTE
|
217
241
|
Matches = Token::Matches
|
218
242
|
Neq = Token::NEQ
|
219
|
-
|
243
|
+
|
220
244
|
StartsWith = :'starts with'
|
221
245
|
|
222
246
|
attr_accessor :operator
|
data/lib/rgviz/parser.rb
CHANGED
@@ -196,24 +196,28 @@ module Rgviz
|
|
196
196
|
|
197
197
|
def parse_or_expression
|
198
198
|
left = parse_and_expression
|
199
|
+
return left unless token_is? Token::Or
|
200
|
+
|
201
|
+
operands = [left]
|
199
202
|
while true
|
200
203
|
if token_is! Token::Or
|
201
|
-
|
202
|
-
left = BinaryExpression.new left, BinaryExpression::Or, right
|
204
|
+
operands << parse_and_expression
|
203
205
|
else
|
204
|
-
return
|
206
|
+
return LogicalExpression.new(LogicalExpression::Or, operands)
|
205
207
|
end
|
206
208
|
end
|
207
209
|
end
|
208
210
|
|
209
211
|
def parse_and_expression
|
210
212
|
left = parse_not_expression
|
213
|
+
return left unless token_is? Token::And
|
214
|
+
|
215
|
+
operands = [left]
|
211
216
|
while true
|
212
217
|
if token_is! Token::And
|
213
|
-
|
214
|
-
left = BinaryExpression.new left, BinaryExpression::And, right
|
218
|
+
operands << parse_not_expression
|
215
219
|
else
|
216
|
-
return
|
220
|
+
return LogicalExpression.new(LogicalExpression::And, operands)
|
217
221
|
end
|
218
222
|
end
|
219
223
|
end
|
data/lib/rgviz/visitor.rb
CHANGED
@@ -2,7 +2,7 @@ module Rgviz
|
|
2
2
|
class Visitor
|
3
3
|
['query', 'select', 'group_by', 'pivot', 'order_by',
|
4
4
|
'sort', 'where', 'label', 'format',
|
5
|
-
'binary_expression', 'unary_expression',
|
5
|
+
'logical_expression', 'binary_expression', 'unary_expression',
|
6
6
|
'id_column', 'number_column', 'string_column',
|
7
7
|
'boolean_column', 'date_column', 'date_time_column',
|
8
8
|
'time_of_day_column', 'scalar_function_column', 'aggregate_column'].each do |name|
|
data/spec/rgviz/parser_spec.rb
CHANGED
@@ -331,12 +331,18 @@ describe Parser do
|
|
331
331
|
options.no_format.should be_true
|
332
332
|
end
|
333
333
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
334
|
+
[
|
335
|
+
['and', LogicalExpression::And],
|
336
|
+
['or', LogicalExpression::Or]
|
337
|
+
].each do |str, op|
|
338
|
+
it "parses where with two #{str}" do
|
339
|
+
query = parse "where 1 = 1 #{str} 1 = 2 #{str} 1 = 3"
|
340
|
+
exp = query.where.expression
|
341
|
+
|
342
|
+
exp.should be_a_kind_of LogicalExpression
|
343
|
+
exp.operator.should == op
|
344
|
+
exp.operands.length.should == 3
|
345
|
+
end
|
340
346
|
end
|
341
347
|
|
342
348
|
['+', '-', '*', '/'].each do |op|
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgviz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 77
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 35
|
9
|
+
version: "0.35"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ary Borenszweig
|