Skip to content

Commit 270705c

Browse files
authored
Merge pull request #42 from lucacome/fix-quotes-take-2
Treat quotes inside a token like any other char
2 parents 984a091 + 3120b7d commit 270705c

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

crossplane/lexer.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def _lex_file_object(file_obj):
2828
token = '' # the token buffer
2929
token_line = 0 # the line the token starts on
3030
next_token_is_directive = True
31-
quote_inside_token = False
3231

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

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

8080
quote = char
8181
char, line = next(it)
8282
while char != quote:
8383
token += quote if char == '\\' + quote else char
8484
char, line = next(it)
8585

86-
if quote_inside_token:
87-
token += quote
88-
quote_inside_token = False
89-
continue
90-
9186
yield (token, token_line)
9287
if next_token_is_directive and token in EXTERNAL_LEXERS:
9388
for custom_lexer_token in EXTERNAL_LEXERS[token](it, token):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"outer-quote" "left"-quote right-"quote" inner"-"quote;
2-
"" ""left-empty right-empty"" inner""empty;
2+
"" ""left-empty right-empty"" inner""empty right-empty-single";

tests/test_lex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ def test_quote_behavior():
7575
tokens = crossplane.lex(config)
7676
assert list(token for token, line in tokens) == [
7777
'outer-quote', 'left', '-quote', 'right-"quote"', 'inner"-"quote', ';',
78-
'', '', 'left-empty', 'right-empty""', 'inner""empty', ';',
78+
'', '', 'left-empty', 'right-empty""', 'inner""empty', 'right-empty-single"', ';',
7979
]

0 commit comments

Comments
 (0)