Class: Gitlab::Ci::Pipeline::Expression::Parser
- Inherits:
-
Object
- Object
- Gitlab::Ci::Pipeline::Expression::Parser
- Defined in:
- lib/gitlab/ci/pipeline/expression/parser.rb
Constant Summary collapse
- ParseError =
Class.new(Expression::ExpressionError)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tokens) ⇒ Parser
constructor
A new instance of Parser.
- #tree ⇒ Object
Constructor Details
#initialize(tokens) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 |
# File 'lib/gitlab/ci/pipeline/expression/parser.rb', line 10 def initialize(tokens) @tokens = tokens.to_enum @nodes = [] end |
Class Method Details
.seed(statement) ⇒ Object
42 43 44 |
# File 'lib/gitlab/ci/pipeline/expression/parser.rb', line 42 def self.seed(statement) new(Expression::Lexer.new(statement).tokens) end |
Instance Method Details
#tree ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gitlab/ci/pipeline/expression/parser.rb', line 15 def tree results = [] tokens = tokens_rpn tokens.each do |token| case token.type when :value results.push(token.build) when :logical_operator right_operand = results.pop left_operand = results.pop token.build(left_operand, right_operand).tap do |res| results.push(res) end else raise ParseError, "Unprocessable token found in parse tree: #{token.type}" end end raise ParseError, 'Unreachable nodes in parse tree' if results.count > 1 raise ParseError, 'Empty parse tree' if results.count < 1 results.pop end |