BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
73 additions
and
63 deletions
+73
-63
base.rb
lib/gitlab/ci/pipeline/expression/lexeme/base.rb
+15
-13
equals.rb
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
+14
-12
null.rb
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
+10
-8
string.rb
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
+13
-11
variable.rb
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
+12
-10
lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+3
-3
parser.rb
lib/gitlab/ci/pipeline/expression/parser.rb
+1
-1
equals_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexeme/equals_spec.rb
+0
-0
parser_spec.rb
spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
+3
-3
statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+2
-2
No files found.
lib/gitlab/ci/pipeline/expression/lexeme.rb
→
lib/gitlab/ci/pipeline/expression/lexeme
/base
.rb
View file @
85176274
...
...
@@ -2,22 +2,24 @@ module Gitlab
module
Ci
module
Pipeline
module
Expression
class
Lexeme
def
evaluate
(
**
variables
)
raise
NotImplementedError
end
module
Lexeme
class
Base
def
evaluate
(
**
variables
)
raise
NotImplementedError
end
def
self
.
build
(
token
)
raise
NotImplementedError
end
def
self
.
build
(
token
)
raise
NotImplementedError
end
def
self
.
type
self
::
TYPE
end
def
self
.
type
self
::
TYPE
end
def
self
.
scan
(
scanner
)
if
scanner
.
scan
(
self
::
PATTERN
)
Expression
::
Token
.
new
(
scanner
.
matched
,
self
)
def
self
.
scan
(
scanner
)
if
scanner
.
scan
(
self
::
PATTERN
)
Expression
::
Token
.
new
(
scanner
.
matched
,
self
)
end
end
end
end
...
...
lib/gitlab/ci/pipeline/expression/equals.rb
→
lib/gitlab/ci/pipeline/expression/
lexeme/
equals.rb
View file @
85176274
...
...
@@ -2,21 +2,23 @@ module Gitlab
module
Ci
module
Pipeline
module
Expression
class
Equals
<
Expression
::
Lexeme
PATTERN
=
/==/
.
freeze
TYPE
=
:operator
module
Lexeme
class
Equals
<
Lexeme
::
Base
PATTERN
=
/==/
.
freeze
TYPE
=
:operator
def
initialize
(
left
,
right
)
@left
=
left
@right
=
right
end
def
initialize
(
left
,
right
)
@left
=
left
@right
=
right
end
def
evaluate
(
**
variables
)
@left
.
evaluate
(
variables
)
==
@right
.
evaluate
(
variables
)
end
def
evaluate
(
**
variables
)
@left
.
evaluate
(
variables
)
==
@right
.
evaluate
(
variables
)
end
def
self
.
build
(
value
,
behind
,
ahead
)
new
(
behind
,
ahead
)
def
self
.
build
(
_value
,
behind
,
ahead
)
new
(
behind
,
ahead
)
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/string.rb
→
lib/gitlab/ci/pipeline/expression/
lexeme/
string.rb
View file @
85176274
...
...
@@ -2,20 +2,22 @@ module Gitlab
module
Ci
module
Pipeline
module
Expression
class
String
<
Expression
::
Lexeme
PATTERN
=
/"(?<string>.+?)"/
.
freeze
TYPE
=
:value
module
Lexeme
class
String
<
Lexeme
::
Base
PATTERN
=
/"(?<string>.+?)"/
.
freeze
TYPE
=
:value
def
initialize
(
value
)
@value
=
value
end
def
initialize
(
value
)
@value
=
value
end
def
evaluate
(
**
_
)
@value
.
to_s
end
def
evaluate
(
**
_
)
@value
.
to_s
end
def
self
.
build
(
string
)
new
(
string
.
match
(
PATTERN
)[
:string
])
def
self
.
build
(
string
)
new
(
string
.
match
(
PATTERN
)[
:string
])
end
end
end
end
...
...
lib/gitlab/ci/pipeline/expression/variable.rb
→
lib/gitlab/ci/pipeline/expression/
lexeme/
variable.rb
View file @
85176274
...
...
@@ -2,19 +2,21 @@ module Gitlab
module
Ci
module
Pipeline
module
Expression
class
Variable
<
Expression
::
Lexeme
PATTERN
=
/\$(?<name>\w+)/
.
freeze
TYPE
=
:value
module
Lexeme
class
Variable
<
Lexeme
::
Base
PATTERN
=
/\$(?<name>\w+)/
.
freeze
TYPE
=
:value
def
initialize
(
name
)
@name
=
name
end
def
initialize
(
name
)
@name
=
name
end
def
evaluate
(
**
variables
)
end
def
evaluate
(
**
variables
)
end
def
self
.
build
(
string
)
new
(
string
.
match
(
PATTERN
)[
:name
])
def
self
.
build
(
string
)
new
(
string
.
match
(
PATTERN
)[
:name
])
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
)
...
...
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