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
5ee43097
Commit
5ee43097
authored
Feb 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify pipelines expression parser
parent
6fe4d2c6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
17 deletions
+18
-17
null.rb
lib/gitlab/ci/pipeline/expression/null.rb
+1
-1
parser.rb
lib/gitlab/ci/pipeline/expression/parser.rb
+7
-8
statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+1
-1
lexer_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
+0
-1
parser_spec.rb
spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
+9
-6
No files found.
lib/gitlab/ci/pipeline/expression/null.rb
View file @
5ee43097
...
...
@@ -6,7 +6,7 @@ module Gitlab
PATTERN
=
/null/
.
freeze
TYPE
=
:value
def
initialize
(
value
)
def
initialize
(
value
=
nil
)
@value
=
value
end
...
...
lib/gitlab/ci/pipeline/expression/parser.rb
View file @
5ee43097
...
...
@@ -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
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
View file @
5ee43097
...
...
@@ -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
...
...
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
View file @
5ee43097
...
...
@@ -67,5 +67,4 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
expect
(
lexer
.
lexemes
).
to
eq
%w[variable string]
end
end
end
spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
View file @
5ee43097
...
...
@@ -2,22 +2,25 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Parser
do
describe
'#tree'
do
context
'when using
an operator
'
do
context
'when using
operators
'
do
it
'returns a reverse descent parse tree'
do
expect
(
described_class
.
new
(
tokens
(
'$VAR == "123"'
)
).
tree
)
expect
(
described_class
.
seed
(
'$VAR1 == "123" == $VAR2'
).
tree
)
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Equals
end
end
context
'when using a single token'
do
it
'returns a single token instance'
do
expect
(
described_class
.
new
(
tokens
(
'$VAR'
)
).
tree
)
expect
(
described_class
.
seed
(
'$VAR'
).
tree
)
.
to
be_a
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Variable
end
end
end
def
tokens
(
statement
)
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexer
.
new
(
statement
).
tokens
.
to_enum
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
end
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