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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
9954928c
Commit
9954928c
authored
Feb 21, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement pipeline expressions lexer
parent
523b84d4
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
7 deletions
+74
-7
lib/gitlab/ci/pipeline/expression/lexeme.rb
lib/gitlab/ci/pipeline/expression/lexeme.rb
+3
-1
lib/gitlab/ci/pipeline/expression/lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+21
-1
lib/gitlab/ci/pipeline/expression/statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+1
-0
lib/gitlab/ci/pipeline/expression/token.rb
lib/gitlab/ci/pipeline/expression/token.rb
+17
-0
lib/gitlab/ci/pipeline/expression/variable.rb
lib/gitlab/ci/pipeline/expression/variable.rb
+2
-5
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
+30
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexeme.rb
View file @
9954928c
...
@@ -8,7 +8,9 @@ module Gitlab
...
@@ -8,7 +8,9 @@ module Gitlab
end
end
def
self
.
scan
(
scanner
)
def
self
.
scan
(
scanner
)
scanner
.
scan
(
PATTERN
)
if
scanner
.
scan
(
self
::
PATTERN
)
Expression
::
Token
.
new
(
scanner
.
matched
,
self
)
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
9954928c
...
@@ -2,12 +2,32 @@ module Gitlab
...
@@ -2,12 +2,32 @@ module Gitlab
module
Ci
module
Ci
module
Pipeline
module
Pipeline
module
Expression
module
Expression
LEXEMES
=
[
Expression
::
Variable
]
MAX_CYCLES
=
5
class
Lexer
class
Lexer
def
initialize
(
statement
)
def
initialize
(
statement
)
@statement
=
statement
@scanner
=
StringScanner
.
new
(
statement
)
@tokens
=
[]
end
end
def
tokenize
def
tokenize
@tokens
.
tap
do
MAX_CYCLES
.
times
do
LEXEMES
.
each
do
|
lexeme
|
@scanner
.
scan
(
/\s+/
)
# ignore whitespace
lexeme
.
scan
(
@scanner
).
tap
do
|
token
|
@tokens
.
push
(
token
)
if
token
.
present?
end
return
@tokens
if
@scanner
.
eos?
end
end
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
View file @
9954928c
...
@@ -9,6 +9,7 @@ module Gitlab
...
@@ -9,6 +9,7 @@ module Gitlab
%w[variable equals null]
,
%w[variable equals null]
,
%w[string equals variable]
,
%w[string equals variable]
,
%w[null equals variable]
,
%w[null equals variable]
,
%w[variable]
]
]
def
initialize
(
pipeline
,
statement
)
def
initialize
(
pipeline
,
statement
)
...
...
lib/gitlab/ci/pipeline/expression/token.rb
0 → 100644
View file @
9954928c
module
Gitlab
module
Ci
module
Pipeline
module
Expression
class
Token
def
initialize
(
value
,
type
)
@value
=
value
@type
=
type
end
def
to_lexeme
end
end
end
end
end
end
lib/gitlab/ci/pipeline/expression/variable.rb
View file @
9954928c
...
@@ -2,8 +2,8 @@ module Gitlab
...
@@ -2,8 +2,8 @@ module Gitlab
module
Ci
module
Ci
module
Pipeline
module
Pipeline
module
Expression
module
Expression
class
Equality
<
Expression
::
Lexeme
class
Variable
<
Expression
::
Lexeme
PATTERN
=
/$(?<name>\w+)/
.
freeze
PATTERN
=
/
\
$(?<name>\w+)/
.
freeze
def
initialize
(
value
)
def
initialize
(
value
)
@value
=
value
@value
=
value
...
@@ -11,9 +11,6 @@ module Gitlab
...
@@ -11,9 +11,6 @@ module Gitlab
def
evaluate
(
**
variables
)
def
evaluate
(
**
variables
)
end
end
def
self
.
build
(
string
)
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
0 → 100644
View file @
9954928c
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexer
do
let
(
:token_class
)
do
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Token
end
describe
'#tokenize'
do
it
'tokenizes single value'
do
tokens
=
described_class
.
new
(
'$VARIABLE'
).
tokenize
expect
(
tokens
).
to
be_one
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
end
it
'does ignore whitespace characters'
do
tokens
=
described_class
.
new
(
"
\t
$VARIABLE "
).
tokenize
expect
(
tokens
).
to
be_one
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
end
it
'tokenizes multiple values of the same token'
do
tokens
=
described_class
.
new
(
"$VARIABLE1 $VARIABLE2"
).
tokenize
expect
(
tokens
.
size
).
to
eq
2
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
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