rgviz 0.36 → 0.37

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rgviz/lexer.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Rgviz
2
2
  class Lexer
3
- def initialize(str)
3
+ def initialize(str, options = {})
4
4
  @str = (str || '').scan(/./)
5
5
  @len = @str.length
6
6
  @token = Token.new
7
+ @extensions = options[:extensions]
7
8
  @p = 0
8
9
  end
9
10
 
@@ -120,9 +121,11 @@ module Rgviz
120
121
  when 'n', 'N'
121
122
  case c!
122
123
  when 'c', 'C'
123
- case c! when 'a', 'A'
124
- case c! when 't', 'T'
125
- return keyword(Token::Concat) if end_of_identifier!
124
+ if @extensions
125
+ case c! when 'a', 'A'
126
+ case c! when 't', 'T'
127
+ return keyword(Token::Concat) if end_of_identifier!
128
+ end
126
129
  end
127
130
  end
128
131
  when 't', 'T'
data/lib/rgviz/parser.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  module Rgviz
2
2
  class Parser < Lexer
3
- def initialize(string)
3
+ def initialize(string, options = {})
4
4
  super
5
5
  @query = Query.new
6
6
  next_token
7
7
  end
8
8
 
9
- def self.parse(string)
10
- Parser.new(string).parse
9
+ def self.parse(string, options = {})
10
+ Parser.new(string, options).parse
11
11
  end
12
12
 
13
13
  def parse
@@ -22,7 +22,7 @@ module Rgviz
22
22
  parse_format
23
23
  parse_options
24
24
 
25
- raise ParseException.new("Expecting end of query") if @token.value != Token::EOF
25
+ raise ParseException.new("Expecting end of query, got: #{@token.string}") if @token.value != Token::EOF
26
26
  @query
27
27
  end
28
28
 
@@ -3,15 +3,15 @@ require 'rgviz'
3
3
  include Rgviz
4
4
 
5
5
  describe Lexer do
6
- def self.it_lexes_keyword(str, token_value)
6
+ def self.it_lexes_keyword(str, token_value, options = {})
7
7
  it "lexes #{str}" do
8
- lex = Lexer.new str
8
+ lex = Lexer.new str, options
9
9
  tok = lex.next_token
10
10
  tok.value.should == token_value
11
11
  end
12
12
 
13
13
  it "lexes #{str} upcase" do
14
- lex = Lexer.new str.upcase
14
+ lex = Lexer.new str.upcase, options
15
15
  tok = lex.next_token
16
16
  tok.value.should == token_value
17
17
  end
@@ -83,7 +83,6 @@ describe Lexer do
83
83
  it_lexes_keyword 'asc', Token::Asc
84
84
  it_lexes_keyword 'avg', Token::Avg
85
85
  it_lexes_keyword 'by', Token::By
86
- it_lexes_keyword 'concat', Token::Concat
87
86
  it_lexes_keyword 'contains', Token::Contains
88
87
  it_lexes_keyword 'count', Token::Count
89
88
  it_lexes_keyword 'date', Token::Date
@@ -169,4 +168,7 @@ describe Lexer do
169
168
  it_lexes_error '!'
170
169
  it_lexes_error '?'
171
170
  it_lexes_error ':'
171
+
172
+ it_lexes_id 'concat'
173
+ it_lexes_keyword 'concat', Token::Concat, :extensions => true
172
174
  end
@@ -3,12 +3,12 @@ require 'rgviz'
3
3
  include Rgviz
4
4
 
5
5
  describe Parser do
6
- def parse(string)
7
- Parser.new(string).parse
6
+ def parse(string, options = {})
7
+ Parser.parse(string, options)
8
8
  end
9
9
 
10
- def parse_select_single_column(string)
11
- query = parse "select #{string}"
10
+ def parse_select_single_column(string, options = {})
11
+ query = parse "select #{string}", options
12
12
  select = query.select
13
13
  select.columns.length.should == 1
14
14
 
@@ -200,10 +200,10 @@ describe Parser do
200
200
  ['quarter', ScalarFunctionColumn::Quarter],
201
201
  ['dayofweek', ScalarFunctionColumn::DayOfWeek],
202
202
  ['todate', ScalarFunctionColumn::ToDate],
203
- ['concat', ScalarFunctionColumn::Concat],
204
- ].each do |str, function|
203
+ ['concat', ScalarFunctionColumn::Concat, true],
204
+ ].each do |str, function, extensions|
205
205
  it "parses #{str} function" do
206
- col = parse_select_single_column "#{str}(col)"
206
+ col = parse_select_single_column "#{str}(col)", :extensions => extensions
207
207
  col.should be_a_kind_of ScalarFunctionColumn
208
208
  col.function.should == function
209
209
 
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: 67
4
+ hash: 65
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 36
9
- version: "0.36"
8
+ - 37
9
+ version: "0.37"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ary Borenszweig