Skip to content

Commit f208708

Browse files
committed
Don't treat an empty string literal as special case
1 parent c1b6bd6 commit f208708

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

jsonpath_rfc9535/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __str__(self) -> str:
2727
if not self.token:
2828
return msg
2929

30+
# TODO: Pretty error messages with current line and visual pointer.
3031
line, column = self.token.position()
3132
return f"{msg}, line {line}, column {column}"
3233

jsonpath_rfc9535/lex.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,13 @@ def accept_match(self, pattern: Pattern[str]) -> bool:
134134
def accept_string_literal(self, quote: str, token_type: TokenType) -> bool:
135135
"""Scan and emit a string literal token.
136136
137-
Return `True` is successful, or `False` otherwise, in which case an error token
138-
will have been emitted.
137+
Assumes the next character is equal to `quote`.
138+
139+
Return `True` is successful or `False` otherwise, in which case an error token
140+
will have been emitted. The caller should treat `False` as an error condition.
139141
"""
140142
self.ignore() # ignore opening quote
141143

142-
if self.peek() == "":
143-
# an empty string
144-
self.emit(token_type)
145-
self.next()
146-
self.ignore()
147-
return True
148-
149144
while True:
150145
c = self.next()
151146

@@ -162,7 +157,7 @@ def accept_string_literal(self, quote: str, token_type: TokenType) -> bool:
162157
return False
163158

164159
if c == quote:
165-
self.backup()
160+
self.backup() # don't emit the closing quote
166161
self.emit(token_type)
167162
self.next()
168163
self.ignore() # ignore closing quote
@@ -186,7 +181,6 @@ def ignore_whitespace(self) -> bool:
186181

187182
def error(self, msg: str) -> None:
188183
"""Emit an error token."""
189-
# TODO: better error messages.
190184
self.tokens.append(
191185
Token(
192186
TokenType.ERROR,

0 commit comments

Comments
 (0)