Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions crossplane/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def _lex_file_object(file_obj):
token = '' # the token buffer
token_line = 0 # the line the token starts on
next_token_is_directive = True
quote_inside_token = False

it = itertools.chain.from_iterable(file_obj)
it = _iterescape(it) # treat escaped characters differently
Expand Down Expand Up @@ -73,21 +72,17 @@ def _lex_file_object(file_obj):

# if a quote is found, add the whole string to the token buffer
if char in ('"', "'"):
# if a quote is inside a token, treat it like any other char
if token:
token += char
quote_inside_token = True
continue

quote = char
char, line = next(it)
while char != quote:
token += quote if char == '\\' + quote else char
char, line = next(it)

if quote_inside_token:
token += quote
quote_inside_token = False
continue

yield (token, token_line)
if next_token_is_directive and token in EXTERNAL_LEXERS:
for custom_lexer_token in EXTERNAL_LEXERS[token](it, token):
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/quote-behavior/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"outer-quote" "left"-quote right-"quote" inner"-"quote;
"" ""left-empty right-empty"" inner""empty;
"" ""left-empty right-empty"" inner""empty right-empty-single";
2 changes: 1 addition & 1 deletion tests/test_lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ def test_quote_behavior():
tokens = crossplane.lex(config)
assert list(token for token, line in tokens) == [
'outer-quote', 'left', '-quote', 'right-"quote"', 'inner"-"quote', ';',
'', '', 'left-empty', 'right-empty""', 'inner""empty', ';',
'', '', 'left-empty', 'right-empty""', 'inner""empty', 'right-empty-single"', ';',
]