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 ba02e6f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 4 additions & 2 deletions mathics_scanner/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def empty(self) -> bool:
def message(self, symbol_name: str, tag: str, *args) -> None:
"""
A Generic message appending routine. the ``self.messages`` message queue.
A Generic routine for appending a message to the ``self.messages`` message
queue.
``symbol_name`` is usually the string symbol name of the built-in function that
is recording the error. "Syntax" error is the exception to this rule.
Expand All @@ -63,6 +64,7 @@ def message(self, symbol_name: str, tag: str, *args) -> None:
"Part" is the symbol_name, "partw" is the tag and args is:
(<ListExpression: (<Integer: 10>,)>, <String: "abcde">)
"""

if symbol_name == "Syntax":
Expand All @@ -74,7 +76,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
6 changes: 3 additions & 3 deletions test/test_string_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def get_tokens(source_text: str):


def test_string():
for ctrl_char in ("\b", "\f", "\n", "\r", "\t"):
check_string(f'"a{ctrl_char}"', f'"a{ctrl_char}"')
for escape_string in ("\b", "\f", "\n", "\r", "\t"):
check_string(f'"a{escape_string}"', f'"a{escape_string}"')

# Broken:
# "a\050", "a\051" "a\052"
Expand All @@ -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 ba02e6f

Please sign in to comment.