summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/expression/lexer.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-06-06 08:34:57 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2019-06-06 08:34:57 +0000
commit502cbda11ba0c6d798b243ab6f489cd73c7bdeea (patch)
tree317a055ca33c2284212987a305bab143583463da /lib/gitlab/ci/pipeline/expression/lexer.rb
parent8501edcd465923c9c6a45abe6c863fc3cd25973a (diff)
parentcfaac7532210ef1ce03f335a3198bb7d2ad3979a (diff)
downloadgitlab-ce-502cbda11ba0c6d798b243ab6f489cd73c7bdeea.tar.gz
Merge branch 'ci-variable-expression-con-dis-junction' into 'master'
CI variable expression conjunction/disjunction See merge request gitlab-org/gitlab-ce!27925
Diffstat (limited to 'lib/gitlab/ci/pipeline/expression/lexer.rb')
-rw-r--r--lib/gitlab/ci/pipeline/expression/lexer.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/gitlab/ci/pipeline/expression/lexer.rb b/lib/gitlab/ci/pipeline/expression/lexer.rb
index e14edfae51d..22c210ae26b 100644
--- a/lib/gitlab/ci/pipeline/expression/lexer.rb
+++ b/lib/gitlab/ci/pipeline/expression/lexer.rb
@@ -20,6 +20,19 @@ module Gitlab
Expression::Lexeme::NotMatches
].freeze
+ NEW_LEXEMES = [
+ Expression::Lexeme::Variable,
+ Expression::Lexeme::String,
+ Expression::Lexeme::Pattern,
+ Expression::Lexeme::Null,
+ Expression::Lexeme::Equals,
+ Expression::Lexeme::Matches,
+ Expression::Lexeme::NotEquals,
+ Expression::Lexeme::NotMatches,
+ Expression::Lexeme::And,
+ Expression::Lexeme::Or
+ ].freeze
+
MAX_TOKENS = 100
def initialize(statement, max_tokens: MAX_TOKENS)
@@ -45,7 +58,7 @@ module Gitlab
return tokens if @scanner.eos?
- lexeme = LEXEMES.find do |type|
+ lexeme = available_lexemes.find do |type|
type.scan(@scanner).tap do |token|
tokens.push(token) if token.present?
end
@@ -58,6 +71,10 @@ module Gitlab
raise Lexer::SyntaxError, 'Too many tokens!'
end
+
+ def available_lexemes
+ Feature.enabled?(:ci_variables_complex_expressions, default_enabled: true) ? NEW_LEXEMES : LEXEMES
+ end
end
end
end