diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-02-23 09:52:08 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-02-23 09:52:34 +0100 |
commit | 5ee43097fde03ac2fabb655f14aa15c8fe8ed631 (patch) | |
tree | 3140bfb9fd62fdb7ccf0f00ddd23ab80e8fc24ae /lib | |
parent | 6fe4d2c6f0439153017a7ede20ce52a5643eeec2 (diff) | |
download | gitlab-ce-5ee43097fde03ac2fabb655f14aa15c8fe8ed631.tar.gz |
Simplify pipelines expression parser
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/null.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/parser.rb | 15 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/statement.rb | 2 |
3 files changed, 9 insertions, 10 deletions
diff --git a/lib/gitlab/ci/pipeline/expression/null.rb b/lib/gitlab/ci/pipeline/expression/null.rb index a70cdd5fc73..31dcba05b48 100644 --- a/lib/gitlab/ci/pipeline/expression/null.rb +++ b/lib/gitlab/ci/pipeline/expression/null.rb @@ -6,7 +6,7 @@ module Gitlab PATTERN = /null/.freeze TYPE = :value - def initialize(value) + def initialize(value = nil) @value = value end diff --git a/lib/gitlab/ci/pipeline/expression/parser.rb b/lib/gitlab/ci/pipeline/expression/parser.rb index 6eb77351dcf..350c9e543ac 100644 --- a/lib/gitlab/ci/pipeline/expression/parser.rb +++ b/lib/gitlab/ci/pipeline/expression/parser.rb @@ -4,9 +4,7 @@ module Gitlab module Expression class Parser def initialize(tokens) - # raise ArgumentError unless tokens.enumerator? - - @tokens = tokens + @tokens = tokens.to_enum @nodes = [] end @@ -14,10 +12,7 @@ module Gitlab while token = @tokens.next case token.type when :operator - lookbehind = @nodes.last - lookahead = Parser.new(@tokens).tree - - token.build(lookbehind, lookahead).tap do |node| + token.build(@nodes.last, tree).tap do |node| @nodes.push(node) end when :value @@ -27,7 +22,11 @@ module Gitlab end end rescue StopIteration - @nodes.last + @nodes.last || Expression::Null.new + end + + def self.seed(statement) + new(Expression::Lexer.new(statement).tokens) end end end diff --git a/lib/gitlab/ci/pipeline/expression/statement.rb b/lib/gitlab/ci/pipeline/expression/statement.rb index 07b84c89899..cb76bc00764 100644 --- a/lib/gitlab/ci/pipeline/expression/statement.rb +++ b/lib/gitlab/ci/pipeline/expression/statement.rb @@ -29,7 +29,7 @@ module Gitlab raise StatementError, 'Unknown pipeline expression!' end - Expression::Parser.new(@lexer.tokens.to_enum).tree + Expression::Parser.new(@lexer.tokens).tree end def evaluate |