Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
f50642f3dcba
Commit
3ae56767
authored
Mar 01, 2018
by
Grzegorz Bizon
Browse files
Make max tokens in expressions lexer a class-level attribute
parent
5b3a54f9f8b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
f50642f3
...
...
@@ -16,12 +16,13 @@ class Lexer
MAX_TOKENS
=
100
def
initialize
(
statement
)
def
initialize
(
statement
,
max_tokens:
MAX_TOKENS
)
@scanner
=
StringScanner
.
new
(
statement
)
@max_tokens
=
max_tokens
end
def
tokens
(
max:
MAX_TOKENS
)
strong_memoize
(
:tokens
)
{
tokenize
(
max
)
}
def
tokens
strong_memoize
(
:tokens
)
{
tokenize
}
end
def
lexemes
...
...
@@ -30,10 +31,10 @@ def lexemes
private
def
tokenize
(
max_tokens
)
def
tokenize
tokens
=
[]
max_tokens
.
times
do
@
max_tokens
.
times
do
@scanner
.
skip
(
/\s+/
)
# ignore whitespace
return
tokens
if
@scanner
.
eos?
...
...
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
View file @
f50642f3
...
...
@@ -46,9 +46,9 @@
end
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
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