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
511046f9
Commit
511046f9
authored
Mar 01, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make max tokens in expressions lexer a class-level attribute
parent
c6ea7a2a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
7 deletions
+8
-7
lib/gitlab/ci/pipeline/expression/lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+6
-5
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
+2
-2
No files found.
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
511046f9
...
@@ -16,12 +16,13 @@ module Gitlab
...
@@ -16,12 +16,13 @@ module Gitlab
MAX_TOKENS
=
100
MAX_TOKENS
=
100
def
initialize
(
statement
)
def
initialize
(
statement
,
max_tokens:
MAX_TOKENS
)
@scanner
=
StringScanner
.
new
(
statement
)
@scanner
=
StringScanner
.
new
(
statement
)
@max_tokens
=
max_tokens
end
end
def
tokens
(
max:
MAX_TOKENS
)
def
tokens
strong_memoize
(
:tokens
)
{
tokenize
(
max
)
}
strong_memoize
(
:tokens
)
{
tokenize
}
end
end
def
lexemes
def
lexemes
...
@@ -30,10 +31,10 @@ module Gitlab
...
@@ -30,10 +31,10 @@ module Gitlab
private
private
def
tokenize
(
max_tokens
)
def
tokenize
tokens
=
[]
tokens
=
[]
max_tokens
.
times
do
@
max_tokens
.
times
do
@scanner
.
skip
(
/\s+/
)
# ignore whitespace
@scanner
.
skip
(
/\s+/
)
# ignore whitespace
return
tokens
if
@scanner
.
eos?
return
tokens
if
@scanner
.
eos?
...
...
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
View file @
511046f9
...
@@ -46,9 +46,9 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
...
@@ -46,9 +46,9 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
end
end
it
'limits statement to specified amount of tokens'
do
it
'limits statement to specified amount of tokens'
do
lexer
=
described_class
.
new
(
"$V1 $V2 $V3 $V4
$V5 $V6"
)
lexer
=
described_class
.
new
(
"$V1 $V2 $V3 $V4
"
,
max_tokens:
3
)
expect
{
lexer
.
tokens
(
max:
5
)
}
expect
{
lexer
.
tokens
}
.
to
raise_error
described_class
::
SyntaxError
.
to
raise_error
described_class
::
SyntaxError
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