Class: SQLTree::Parser
- Inherits:
-
Object
- Object
- SQLTree::Parser
- Defined in:
- lib/sql_tree/parser.rb
Defined Under Namespace
Classes: UnexpectedToken
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #consume(*checks) ⇒ Object
- #current ⇒ Object
- #debug ⇒ Object
-
#initialize(tokens, options) ⇒ Parser
constructor
A new instance of Parser.
- #next ⇒ Object
- #parse! ⇒ Object
- #peek(distance = 1) ⇒ Object
- #peek_tokens(amount) ⇒ Object
Constructor Details
#initialize(tokens, options) ⇒ Parser
Returns a new instance of Parser.
22 23 24 25 26 27 28 29 |
# File 'lib/sql_tree/parser.rb', line 22 def initialize(tokens, ) if tokens.kind_of?(String) @tokens = SQLTree::Tokenizer.new.tokenize(tokens) else @tokens = tokens end = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/sql_tree/parser.rb', line 20 def end |
Class Method Details
.parse(sql_string, options = {}) ⇒ Object
16 17 18 |
# File 'lib/sql_tree/parser.rb', line 16 def self.parse(sql_string, = {}) self.new(sql_string, ).parse! end |
Instance Method Details
#consume(*checks) ⇒ Object
39 40 41 42 43 |
# File 'lib/sql_tree/parser.rb', line 39 def consume(*checks) checks.each do |check| raise UnexpectedToken.new(self.current, check) unless check == self.next end end |
#current ⇒ Object
31 32 33 |
# File 'lib/sql_tree/parser.rb', line 31 def current @current_token end |
#debug ⇒ Object
53 54 55 |
# File 'lib/sql_tree/parser.rb', line 53 def debug puts @tokens.inspect end |
#next ⇒ Object
35 36 37 |
# File 'lib/sql_tree/parser.rb', line 35 def next @current_token = @tokens.shift end |
#parse! ⇒ Object
57 58 59 60 61 62 |
# File 'lib/sql_tree/parser.rb', line 57 def parse! case self.peek when SQLTree::Token::SELECT then SQLTree::Node::SelectQuery.parse(self) else raise UnexpectedToken.new(self.peek) end end |
#peek(distance = 1) ⇒ Object
45 46 47 |
# File 'lib/sql_tree/parser.rb', line 45 def peek(distance = 1) @tokens[distance - 1] end |
#peek_tokens(amount) ⇒ Object
49 50 51 |
# File 'lib/sql_tree/parser.rb', line 49 def peek_tokens(amount) @tokens[0, amount] end |