Skip to content

Commit

Permalink
Called wrong check routine
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Dec 11, 2024
1 parent ab22393 commit 236b904
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mathics_scanner/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def message(self, symbol_name: str, tag: str, *args) -> None:

def syntax_message(self, symbol_name: str, tag: str, *args) -> list:
"""
Append a syntax-message error message to the message queue.
Append a "Syntax" error message to the message queue.
"""

if len(args) > 3:
Expand Down
18 changes: 8 additions & 10 deletions mathics_scanner/tokeniser.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,17 @@ def incomplete(self):
self.prescanner.incomplete()
self.code += self.prescanner.replace_escape_sequences()

def sntx_message(self, pos: Optional[int] = None, tag: Optional[str] = None):
def sntx_message(self, pos: Optional[int] = None):
"""
Send a "syntx{b,f} error message to the input-reading feeder.
"""
if pos is None:
pos = self.pos
pre, post = self.code[:pos], self.code[pos:].rstrip("\n")
if tag is None:
tag = "sntxb" if pos == 0 else "sntxf"
if pos == 0:
self.feeder.message("Syntax", tag, post)
self.feeder.message("Syntax", "sntxb", post)
else:
self.feeder.message("Syntax", tag, pre, post)
self.feeder.message("Syntax", "sntxf", pre, post)

# TODO: Convert this to __next__ in the future.
def next(self) -> Token:
Expand Down Expand Up @@ -551,13 +549,13 @@ def t_String(self, match: re.Match) -> Token:
"Break out from self.code the next token which is expected to be a String"
start, end = self.pos, None
self.pos += 1 # skip opening '"'
skipped_chars = []
newlines = []
while True:
if self.pos >= len(self.code):
if end is None:
# reached end while still inside string
self.incomplete()
skipped_chars.append(self.pos)
newlines.append(self.pos)
else:
break
char = self.code[self.pos]
Expand All @@ -573,7 +571,7 @@ def t_String(self, match: re.Match) -> Token:
if self.pos + 1 == len(self.code):
# We have a \ at the end of a line.
self.incomplete()
skipped_chars.append(self.pos)
newlines.append(self.pos)

# Code below is in pre-scanner. We might decide
# later to move that code here.
Expand All @@ -586,7 +584,7 @@ def t_String(self, match: re.Match) -> Token:
# "\\" have the backslash preserved. But for other
# characters, the backslash is removed.
if self.code[self.pos + 1] not in (
"b", # bell?
"b", # word boundary?
"f", # form-feed?
"n", # newline
"r", # carrage return
Expand All @@ -604,7 +602,7 @@ def t_String(self, match: re.Match) -> Token:
else:
self.pos += 1

indices = [start] + skipped_chars + [end]
indices = [start] + newlines + [end]
result = "".join(
self.code[indices[i] : indices[i + 1]] for i in range(len(indices) - 1)
)
Expand Down
2 changes: 1 addition & 1 deletion test/test_string_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def test_string():
check_string(r'"a\"b\\c"', r'"a\"b\\c"')
incomplete_error(r'"abc', "String does not have terminating quote")
incomplete_error(r'"\"', "Unterminated escape sequence")
incomplete_error(r'"a\X"', '"X" is not a valid escape character')
scan_error(r'"a\X"', '"X" is not a valid escape character')

0 comments on commit 236b904

Please sign in to comment.