Class: Cucumber::TagExpressions::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/lib/cucumber/tag_expressions/parser.rb

Overview

Ruby tag expression parser

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/lib/cucumber/tag_expressions/parser.rb', line 7

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

  @operator_types = {
    'or'  => { type: :binary_operator,    precedence: 0, assoc: :left },
    'and' => { type: :binary_operator,   precedence: 1, assoc: :left },
    'not' => { type: :unary_operator,   precedence: 2, assoc: :right },
    ')'   => { type: :close_paren,       precedence: -1 },
    '('   => { type: :open_paren,        precedence: 1 }
  }
end

Instance Method Details

#parse(infix_expression) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/lib/cucumber/tag_expressions/parser.rb', line 20

def parse(infix_expression)
  process_tokens!(infix_expression)
  while @operators.any?
    raise 'Syntax error. Unmatched (' if @operators.last == '('
    push_expression(pop(@operators))
  end
  expression = pop(@expressions)
  @expressions.empty? ? expression : raise('Not empty')
end