rgviz 0.29 → 0.30
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rgviz/parser.rb +42 -34
- data/spec/rgviz/parser_spec.rb +14 -0
- metadata +3 -3
data/lib/rgviz/parser.rb
CHANGED
@@ -192,21 +192,25 @@ module Rgviz
|
|
192
192
|
|
193
193
|
def parse_or_expression
|
194
194
|
left = parse_and_expression
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
195
|
+
while true
|
196
|
+
if token_is! Token::Or
|
197
|
+
right = parse_and_expression
|
198
|
+
left = BinaryExpression.new left, BinaryExpression::Or, right
|
199
|
+
else
|
200
|
+
return left
|
201
|
+
end
|
200
202
|
end
|
201
203
|
end
|
202
204
|
|
203
205
|
def parse_and_expression
|
204
206
|
left = parse_not_expression
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
207
|
+
while true
|
208
|
+
if token_is! Token::And
|
209
|
+
right = parse_not_expression
|
210
|
+
left = BinaryExpression.new left, BinaryExpression::And, right
|
211
|
+
else
|
212
|
+
return left
|
213
|
+
end
|
210
214
|
end
|
211
215
|
end
|
212
216
|
|
@@ -281,34 +285,38 @@ module Rgviz
|
|
281
285
|
end
|
282
286
|
|
283
287
|
def parse_summation_or_substraction
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
288
|
+
left = parse_multiplication_or_divition
|
289
|
+
while true
|
290
|
+
case @token.value
|
291
|
+
when Token::PLUS
|
292
|
+
next_token
|
293
|
+
right = parse_multiplication_or_divition
|
294
|
+
left = ScalarFunctionColumn.new ScalarFunctionColumn::Sum, left, right
|
295
|
+
when Token::MINUS
|
296
|
+
next_token
|
297
|
+
right = parse_multiplication_or_divition
|
298
|
+
left = ScalarFunctionColumn.new ScalarFunctionColumn::Difference, left, right
|
299
|
+
else
|
300
|
+
return left
|
301
|
+
end
|
296
302
|
end
|
297
303
|
end
|
298
304
|
|
299
305
|
def parse_multiplication_or_divition
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
306
|
+
left = parse_atomic_column
|
307
|
+
while true
|
308
|
+
case @token.value
|
309
|
+
when Token::STAR
|
310
|
+
next_token
|
311
|
+
right = parse_atomic_column
|
312
|
+
left = ScalarFunctionColumn.new ScalarFunctionColumn::Product, left, right
|
313
|
+
when Token::SLASH
|
314
|
+
next_token
|
315
|
+
right = parse_atomic_column
|
316
|
+
left = ScalarFunctionColumn.new ScalarFunctionColumn::Quotient, left, right
|
317
|
+
else
|
318
|
+
return left
|
319
|
+
end
|
312
320
|
end
|
313
321
|
end
|
314
322
|
|
data/spec/rgviz/parser_spec.rb
CHANGED
@@ -331,6 +331,20 @@ describe Parser do
|
|
331
331
|
options.no_format.should be_true
|
332
332
|
end
|
333
333
|
|
334
|
+
it "parses where with two ands" do
|
335
|
+
parse "where 1 = 1 and 1 = 1 and 1 = 1"
|
336
|
+
end
|
337
|
+
|
338
|
+
it "parses where with two ors" do
|
339
|
+
parse "where 1 = 1 or 1 = 1 or 1 = 1"
|
340
|
+
end
|
341
|
+
|
342
|
+
['+', '-', '*', '/'].each do |op|
|
343
|
+
it "parses where with two #{op}" do
|
344
|
+
parse "where 1 #{op} 2 #{op} 3 = 4"
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
334
348
|
it_raises_on 'select'
|
335
349
|
it_raises_on 'where'
|
336
350
|
it_raises_on 'where 1'
|
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: 55
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 30
|
9
|
+
version: "0.30"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ary Borenszweig
|