Class: Cucumber::TagExpressions::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/tag_expressions/parser.rb

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



8
9
10
11
# File 'lib/cucumber/tag_expressions/parser.rb', line 8

def initialize
  @expressions = []
  @operators = []
end

Instance Method Details

#parse(infix_expression) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cucumber/tag_expressions/parser.rb', line 13

def parse(infix_expression)
  expected_token_type = :operand
  tokens = tokenize(infix_expression)
  return True.new if tokens.empty?

  tokens.each { |token| expected_token_type = handle_sequential_tokens(token, infix_expression, expected_token_type) }
  while @operators.any?
    raise "Tag expression \"#{infix_expression}\" could not be parsed because of syntax error: Unmatched (." if @operators.last == '('
    push_expression(infix_expression, @operators.pop)
  end
  @expressions.pop
end