Class: TokenStream
- Inherits:
-
Array
- Object
- Array
- TokenStream
- Defined in:
- lib/tsql_shparser/tsql_stmt.rb
Overview
A facade class which adds helper methods to the Array class and converts it into a TokenStream
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #+(arr) ⇒ Object
- #-(arr) ⇒ Object
- #find_matching_paran(from) ⇒ Object
- #find_matching_word(words, from = 0) ⇒ Object
-
#initialize(arr = []) ⇒ TokenStream
constructor
A new instance of TokenStream.
- #slice(range) ⇒ Object
- #to_arr ⇒ Object
Constructor Details
#initialize(arr = []) ⇒ TokenStream
Returns a new instance of TokenStream.
20 21 22 |
# File 'lib/tsql_shparser/tsql_stmt.rb', line 20 def initialize(arr=[]) @arr = super(arr) end |
Instance Method Details
#+(arr) ⇒ Object
24 |
# File 'lib/tsql_shparser/tsql_stmt.rb', line 24 def +(arr); TokenStream.new(super); end |
#-(arr) ⇒ Object
25 |
# File 'lib/tsql_shparser/tsql_stmt.rb', line 25 def -(arr); TokenStream.new(super); end |
#find_matching_paran(from) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tsql_shparser/tsql_stmt.rb', line 32 def find_matching_paran(from) list = self.slice(from..-1).to_arr m = level = 0 if (list[0] == LEFT_PARAN) list.each_index { |i| level += 1 if (list[i] == LEFT_PARAN) level -= 1 if (list[i] == RIGHT_PARAN) (m = i; break) if (level == 0) } end return m end |
#find_matching_word(words, from = 0) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tsql_shparser/tsql_stmt.rb', line 48 def find_matching_word(words,from=0) list = self.slice(from..-1).to_arr pos = 0 # assume that the word will NEVER be the first word in the list words.each{|word| m = level = 0 list.each_index { |i| level += 1 if list[i] == LEFT_PARAN level -= 1 if list[i] == RIGHT_PARAN (m = i; break) if ((list[i] == word) and (level == 0)) p [i,level,m] if $DEBUG } (pos = m; break) if m > 0 } pos end |
#slice(range) ⇒ Object
26 |
# File 'lib/tsql_shparser/tsql_stmt.rb', line 26 def slice(range); TokenStream.new(super); end |
#to_arr ⇒ Object
28 29 30 |
# File 'lib/tsql_shparser/tsql_stmt.rb', line 28 def to_arr (@arr ? @arr.collect{|t| t.token_value} : @arr) end |