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
cee3be29
Commit
cee3be29
authored
Feb 21, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a lexeme for a string pipeline expression
parent
9954928c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
15 deletions
+35
-15
lib/gitlab/ci/pipeline/expression/lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+16
-14
lib/gitlab/ci/pipeline/expression/string.rb
lib/gitlab/ci/pipeline/expression/string.rb
+1
-1
lib/gitlab/ci/pipeline/expression/token.rb
lib/gitlab/ci/pipeline/expression/token.rb
+2
-0
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
+16
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
cee3be29
...
@@ -2,20 +2,21 @@ module Gitlab
...
@@ -2,20 +2,21 @@ module Gitlab
module
Ci
module
Ci
module
Pipeline
module
Pipeline
module
Expression
module
Expression
class
Lexer
LEXEMES
=
[
LEXEMES
=
[
Expression
::
Variable
Expression
::
Variable
,
Expression
::
String
]
]
MAX_CYCLES
=
5
MAX_CYCLES
=
5
SyntaxError
=
Class
.
new
(
StandardError
)
class
Lexer
def
initialize
(
statement
)
def
initialize
(
statement
)
@scanner
=
StringScanner
.
new
(
statement
)
@scanner
=
StringScanner
.
new
(
statement
)
@tokens
=
[]
@tokens
=
[]
end
end
def
tokenize
def
tokenize
@tokens
.
tap
do
MAX_CYCLES
.
times
do
MAX_CYCLES
.
times
do
LEXEMES
.
each
do
|
lexeme
|
LEXEMES
.
each
do
|
lexeme
|
@scanner
.
scan
(
/\s+/
)
# ignore whitespace
@scanner
.
scan
(
/\s+/
)
# ignore whitespace
...
@@ -27,7 +28,8 @@ module Gitlab
...
@@ -27,7 +28,8 @@ module Gitlab
return
@tokens
if
@scanner
.
eos?
return
@tokens
if
@scanner
.
eos?
end
end
end
end
end
raise
Lexer
::
SyntaxError
unless
@scanner
.
eos?
end
end
end
end
end
end
...
...
lib/gitlab/ci/pipeline/expression/string.rb
View file @
cee3be29
...
@@ -3,7 +3,7 @@ module Gitlab
...
@@ -3,7 +3,7 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Expression
module
Expression
class
String
<
Expression
::
Lexeme
class
String
<
Expression
::
Lexeme
PATTERN
=
/
("|')(?<value>.+)('|")
/
.
freeze
PATTERN
=
/
"(?<string>.+?)"
/
.
freeze
def
initialize
(
value
)
def
initialize
(
value
)
@value
=
value
@value
=
value
...
...
lib/gitlab/ci/pipeline/expression/token.rb
View file @
cee3be29
...
@@ -3,6 +3,8 @@ module Gitlab
...
@@ -3,6 +3,8 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Expression
module
Expression
class
Token
class
Token
attr_reader
:value
,
:type
def
initialize
(
value
,
type
)
def
initialize
(
value
,
type
)
@value
=
value
@value
=
value
@type
=
type
@type
=
type
...
...
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
View file @
cee3be29
...
@@ -26,5 +26,21 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
...
@@ -26,5 +26,21 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
expect
(
tokens
.
size
).
to
eq
2
expect
(
tokens
.
size
).
to
eq
2
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
end
end
it
'tokenizes multiple values with different tokens'
do
tokens
=
described_class
.
new
(
'$VARIABLE "text" "value"'
).
tokenize
expect
(
tokens
.
size
).
to
eq
3
expect
(
tokens
.
first
.
value
).
to
eq
'$VARIABLE'
expect
(
tokens
.
second
.
value
).
to
eq
'"text"'
expect
(
tokens
.
third
.
value
).
to
eq
'"value"'
end
it
'limits statement to 5 tokens'
do
lexer
=
described_class
.
new
(
"$V1 $V2 $V3 $V4 $V5 $V6"
)
expect
{
lexer
.
tokenize
}
.
to
raise_error
described_class
::
SyntaxError
end
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