Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
85176274
Commit
85176274
authored
Feb 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move pipeline expression lexemes to a separate module
parent
5ee43097
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
138 additions
and
108 deletions
+138
-108
lib/gitlab/ci/pipeline/expression/equals.rb
lib/gitlab/ci/pipeline/expression/equals.rb
+0
-25
lib/gitlab/ci/pipeline/expression/lexeme.rb
lib/gitlab/ci/pipeline/expression/lexeme.rb
+0
-27
lib/gitlab/ci/pipeline/expression/lexeme/base.rb
lib/gitlab/ci/pipeline/expression/lexeme/base.rb
+29
-0
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
+27
-0
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
+22
-0
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
+26
-0
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
+25
-0
lib/gitlab/ci/pipeline/expression/lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+3
-3
lib/gitlab/ci/pipeline/expression/parser.rb
lib/gitlab/ci/pipeline/expression/parser.rb
+1
-1
lib/gitlab/ci/pipeline/expression/string.rb
lib/gitlab/ci/pipeline/expression/string.rb
+0
-24
lib/gitlab/ci/pipeline/expression/variable.rb
lib/gitlab/ci/pipeline/expression/variable.rb
+0
-23
spec/lib/gitlab/ci/pipeline/expression/lexeme/equals_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexeme/equals_spec.rb
+0
-0
spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
+3
-3
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+2
-2
No files found.
lib/gitlab/ci/pipeline/expression/equals.rb
deleted
100644 → 0
View file @
5ee43097
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
lib/gitlab/ci/pipeline/expression/lexeme.rb
deleted
100644 → 0
View file @
5ee43097
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
lib/gitlab/ci/pipeline/expression/lexeme/base.rb
0 → 100644
View file @
85176274
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
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
0 → 100644
View file @
85176274
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
lib/gitlab/ci/pipeline/expression/null.rb
→
lib/gitlab/ci/pipeline/expression/
lexeme/
null.rb
View file @
85176274
...
...
@@ -2,16 +2,18 @@ module Gitlab
module
Ci
module
Pipeline
module
Expression
class
Null
<
Expression
::
Lexeme
PATTERN
=
/null/
.
freeze
TYPE
=
:value
module
Lexeme
class
Null
<
Lexeme
::
Base
PATTERN
=
/null/
.
freeze
TYPE
=
:value
def
initialize
(
value
=
nil
)
@value
=
value
end
def
initialize
(
value
=
nil
)
@value
=
value
end
def
evaluate
(
**
_
)
nil
def
evaluate
(
**
_
)
nil
end
end
end
end
...
...
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
0 → 100644
View file @
85176274
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
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
0 → 100644
View file @
85176274
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
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
85176274
...
...
@@ -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
...
...
lib/gitlab/ci/pipeline/expression/parser.rb
View file @
85176274
...
...
@@ -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
)
...
...
lib/gitlab/ci/pipeline/expression/string.rb
deleted
100644 → 0
View file @
5ee43097
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
lib/gitlab/ci/pipeline/expression/variable.rb
deleted
100644 → 0
View file @
5ee43097
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
spec/lib/gitlab/ci/pipeline/expression/equals_spec.rb
→
spec/lib/gitlab/ci/pipeline/expression/
lexeme/
equals_spec.rb
View file @
85176274
File moved
spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
View file @
85176274
...
...
@@ -5,21 +5,21 @@ describe Gitlab::Ci::Pipeline::Expression::Parser do
context
'when using operators'
do
it
'returns a reverse descent parse tree'
do
expect
(
described_class
.
seed
(
'$VAR1 == "123" == $VAR2'
).
tree
)
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Equals
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Equals
end
end
context
'when using a single token'
do
it
'returns a single token instance'
do
expect
(
described_class
.
seed
(
'$VAR'
).
tree
)
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Variable
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Variable
end
end
context
'when expression is empty'
do
it
'returns a null token'
do
expect
(
described_class
.
seed
(
''
).
tree
)
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Null
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Null
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
View file @
85176274
...
...
@@ -37,7 +37,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
it
'returns a reverse descent parse tree'
do
expect
(
subject
.
parse_tree
)
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Equals
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Equals
end
end
...
...
@@ -46,7 +46,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
it
'returns a single token instance'
do
expect
(
subject
.
parse_tree
)
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Variable
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Variable
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment