From 624db9a0b0c1b12cfb5b6df01f1def7a0d284d93 Mon Sep 17 00:00:00 2001 From: Stanislav Date: Fri, 16 Oct 2026 02:48:25 +0400 Subject: [PATCH] Raise unknown named character errors with the sntufn tag parse_escape_sequence raised NamedCharacterSyntaxError("Syntax", "sntufn", ...), but SyntaxError takes the message tag as its first argument (the name is always "Syntax"). The message then came out as "Syntax::Syntax: Message Syntax::Syntax not found" instead of "Syntax::sntufn: Unknown unicode longname ...". Co-Authored-By: Claude Opus 5.5 --- mathics_scanner/escape_sequences.py | 4 ++-- test/test_escape_sequences.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mathics_scanner/escape_sequences.py b/mathics_scanner/escape_sequences.py index b0675b92..ef9b3e17 100644 --- a/mathics_scanner/escape_sequences.py +++ b/mathics_scanner/escape_sequences.py @@ -117,11 +117,11 @@ def parse_escape_sequence( if i == len(source_text): # Note: named characters do not have \n's in them. (Is this right)? # FIXME: decide what to do here. - raise NamedCharacterSyntaxError("Syntax", "sntufn", source_text[pos:]) + raise NamedCharacterSyntaxError("sntufn", source_text[pos:]) named_character = parse_named_character(source_text, pos, i) if named_character is None: - raise NamedCharacterSyntaxError("Syntax", "sntufn", source_text[pos:i]) + raise NamedCharacterSyntaxError("sntufn", source_text[pos:i]) result += named_character pos = i + 1 diff --git a/test/test_escape_sequences.py b/test/test_escape_sequences.py index f9631089..4b912e47 100644 --- a/test/test_escape_sequences.py +++ b/test/test_escape_sequences.py @@ -57,6 +57,26 @@ def test_invalid_named_character_sequences(): parse_escape_sequence(text, 1, is_in_string=False) +@pytest.mark.parametrize( + ("text", "name"), + [ + (r"\[Fake]", "Fake"), + (r"\[Alpha\]", "Alpha\\"), + (r"\[\Sigma]", "\\Sigma"), + (r"\[Theta", "Theta"), + ], +) +def test_invalid_named_character_message(text, name): + """The error carries the "sntufn" tag and the unknown name as its first argument, + which is what the Syntax::sntufn message template expects.""" + with pytest.raises(NamedCharacterSyntaxError) as excinfo: + parse_escape_sequence(text, 1, is_in_string=False) + error = excinfo.value + assert error.name == "Syntax" + assert error.tag == "sntufn" + assert error.args[0] == name + + def test_invalid_number_encoding(): for text in ( # Octal