diff options
Diffstat (limited to 'lib/gitlab/ci/pipeline/expression')
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/equals.rb | 25 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexeme.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexeme/base.rb | 29 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexeme/equals.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexeme/null.rb | 22 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexeme/string.rb | 26 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexeme/variable.rb | 25 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexer.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/null.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/parser.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/string.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/variable.rb | 23 |
12 files changed, 133 insertions, 123 deletions
diff --git a/lib/gitlab/ci/pipeline/expression/equals.rb b/lib/gitlab/ci/pipeline/expression/equals.rb deleted file mode 100644 index 93883982b63..00000000000 --- a/lib/gitlab/ci/pipeline/expression/equals.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Gitlab - module Ci - module Pipeline - module Expression - class Equals < Expression::Lexeme - PATTERN = /==/.freeze - TYPE = :operator - - def initialize(left, right) - @left = left - @right = right - end - - def evaluate(**variables) - @left.evaluate(variables) == @right.evaluate(variables) - end - - def self.build(value, behind, ahead) - new(behind, ahead) - end - end - end - end - end -end diff --git a/lib/gitlab/ci/pipeline/expression/lexeme.rb b/lib/gitlab/ci/pipeline/expression/lexeme.rb deleted file mode 100644 index d44bf9e419d..00000000000 --- a/lib/gitlab/ci/pipeline/expression/lexeme.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Gitlab - module Ci - module Pipeline - module Expression - class Lexeme - def evaluate(**variables) - raise NotImplementedError - end - - def self.build(token) - raise NotImplementedError - end - - def self.type - self::TYPE - end - - def self.scan(scanner) - if scanner.scan(self::PATTERN) - Expression::Token.new(scanner.matched, self) - end - end - end - end - end - end -end diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/base.rb b/lib/gitlab/ci/pipeline/expression/lexeme/base.rb new file mode 100644 index 00000000000..29b73c94358 --- /dev/null +++ b/lib/gitlab/ci/pipeline/expression/lexeme/base.rb @@ -0,0 +1,29 @@ +module Gitlab + module Ci + module Pipeline + module Expression + module Lexeme + class Base + def evaluate(**variables) + raise NotImplementedError + end + + def self.build(token) + raise NotImplementedError + end + + def self.type + self::TYPE + end + + def self.scan(scanner) + if scanner.scan(self::PATTERN) + Expression::Token.new(scanner.matched, self) + end + end + end + end + end + end + end +end diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/equals.rb b/lib/gitlab/ci/pipeline/expression/lexeme/equals.rb new file mode 100644 index 00000000000..0cb21131d69 --- /dev/null +++ b/lib/gitlab/ci/pipeline/expression/lexeme/equals.rb @@ -0,0 +1,27 @@ +module Gitlab + module Ci + module Pipeline + module Expression + module Lexeme + class Equals < Lexeme::Base + PATTERN = /==/.freeze + TYPE = :operator + + def initialize(left, right) + @left = left + @right = right + end + + def evaluate(**variables) + @left.evaluate(variables) == @right.evaluate(variables) + end + + def self.build(_value, behind, ahead) + new(behind, ahead) + end + end + end + end + end + end +end diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/null.rb b/lib/gitlab/ci/pipeline/expression/lexeme/null.rb new file mode 100644 index 00000000000..21286151d79 --- /dev/null +++ b/lib/gitlab/ci/pipeline/expression/lexeme/null.rb @@ -0,0 +1,22 @@ +module Gitlab + module Ci + module Pipeline + module Expression + module Lexeme + class Null < Lexeme::Base + PATTERN = /null/.freeze + TYPE = :value + + def initialize(value = nil) + @value = value + end + + def evaluate(**_) + nil + end + end + end + end + end + end +end diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/string.rb b/lib/gitlab/ci/pipeline/expression/lexeme/string.rb new file mode 100644 index 00000000000..470a5a15cc1 --- /dev/null +++ b/lib/gitlab/ci/pipeline/expression/lexeme/string.rb @@ -0,0 +1,26 @@ +module Gitlab + module Ci + module Pipeline + module Expression + module Lexeme + class String < Lexeme::Base + PATTERN = /"(?<string>.+?)"/.freeze + TYPE = :value + + def initialize(value) + @value = value + end + + def evaluate(**_) + @value.to_s + end + + def self.build(string) + new(string.match(PATTERN)[:string]) + end + end + end + end + end + end +end diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/variable.rb b/lib/gitlab/ci/pipeline/expression/lexeme/variable.rb new file mode 100644 index 00000000000..5fb5dd4bbbe --- /dev/null +++ b/lib/gitlab/ci/pipeline/expression/lexeme/variable.rb @@ -0,0 +1,25 @@ +module Gitlab + module Ci + module Pipeline + module Expression + module Lexeme + class Variable < Lexeme::Base + PATTERN = /\$(?<name>\w+)/.freeze + TYPE = :value + + def initialize(name) + @name = name + end + + def evaluate(**variables) + end + + def self.build(string) + new(string.match(PATTERN)[:name]) + end + end + end + end + end + end +end diff --git a/lib/gitlab/ci/pipeline/expression/lexer.rb b/lib/gitlab/ci/pipeline/expression/lexer.rb index 9334358cd8e..038c0e7e330 100644 --- a/lib/gitlab/ci/pipeline/expression/lexer.rb +++ b/lib/gitlab/ci/pipeline/expression/lexer.rb @@ -4,9 +4,9 @@ module Gitlab module Expression class Lexer LEXEMES = [ - Expression::Variable, - Expression::String, - Expression::Equals + Expression::Lexeme::Variable, + Expression::Lexeme::String, + Expression::Lexeme::Equals ].freeze MAX_CYCLES = 5 diff --git a/lib/gitlab/ci/pipeline/expression/null.rb b/lib/gitlab/ci/pipeline/expression/null.rb deleted file mode 100644 index 31dcba05b48..00000000000 --- a/lib/gitlab/ci/pipeline/expression/null.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Gitlab - module Ci - module Pipeline - module Expression - class Null < Expression::Lexeme - PATTERN = /null/.freeze - TYPE = :value - - def initialize(value = nil) - @value = value - end - - def evaluate(**_) - nil - end - end - end - end - end -end diff --git a/lib/gitlab/ci/pipeline/expression/parser.rb b/lib/gitlab/ci/pipeline/expression/parser.rb index 350c9e543ac..b395e4692f1 100644 --- a/lib/gitlab/ci/pipeline/expression/parser.rb +++ b/lib/gitlab/ci/pipeline/expression/parser.rb @@ -22,7 +22,7 @@ module Gitlab end end rescue StopIteration - @nodes.last || Expression::Null.new + @nodes.last || Expression::Lexeme::Null.new end def self.seed(statement) diff --git a/lib/gitlab/ci/pipeline/expression/string.rb b/lib/gitlab/ci/pipeline/expression/string.rb deleted file mode 100644 index bbd75cb4632..00000000000 --- a/lib/gitlab/ci/pipeline/expression/string.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Gitlab - module Ci - module Pipeline - module Expression - class String < Expression::Lexeme - PATTERN = /"(?<string>.+?)"/.freeze - TYPE = :value - - def initialize(value) - @value = value - end - - def evaluate(**_) - @value.to_s - end - - def self.build(string) - new(string.match(PATTERN)[:string]) - end - end - end - end - end -end diff --git a/lib/gitlab/ci/pipeline/expression/variable.rb b/lib/gitlab/ci/pipeline/expression/variable.rb deleted file mode 100644 index 379f8168ca9..00000000000 --- a/lib/gitlab/ci/pipeline/expression/variable.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Gitlab - module Ci - module Pipeline - module Expression - class Variable < Expression::Lexeme - PATTERN = /\$(?<name>\w+)/.freeze - TYPE = :value - - def initialize(name) - @name = name - end - - def evaluate(**variables) - end - - def self.build(string) - new(string.match(PATTERN)[:name]) - end - end - end - end - end -end |