More descriptive character escape syntax error messages (bug#63436)

* src/lread.c (invalid_escape_syntax_error): Remove.
(read_char_escape): Make certain messages more specific
than just "Invalid escape character syntax" to help finding
and understanding the error.
This commit is contained in:
Mattias Engdegård 2023-05-11 11:49:06 +02:00
parent e4c8ba6c05
commit 1174e8ba4d

View file

@ -2639,12 +2639,6 @@ character_name_to_code (char const *name, ptrdiff_t name_len,
Unicode 9.0.0 the maximum is 83, so this should be safe. */
enum { UNICODE_CHARACTER_NAME_LENGTH_BOUND = 200 };
static AVOID
invalid_escape_syntax_error (void)
{
error ("Invalid escape character syntax");
}
/* Read a character escape sequence, assuming we just read a backslash
and one more character (next_char). */
static int
@ -2676,7 +2670,7 @@ read_char_escape (Lisp_Object readcharfun, int next_char)
case '\n':
/* ?\LF is an error; it's probably a user mistake. */
error ("Invalid escape character syntax");
error ("Invalid escape char syntax: \\<newline>");
/* \M-x etc: set modifier bit and parse the char to which it applies,
allowing for chains such as \M-\S-\A-\H-\s-\C-q. */
@ -2700,7 +2694,7 @@ read_char_escape (Lisp_Object readcharfun, int next_char)
}
else
/* \M, \S, \H, \A not followed by a hyphen is an error. */
invalid_escape_syntax_error ();
error ("Invalid escape char syntax: \\%c not followed by -", c);
}
modifiers |= mod;
c1 = READCHAR;
@ -2720,7 +2714,7 @@ read_char_escape (Lisp_Object readcharfun, int next_char)
{
int c1 = READCHAR;
if (c1 != '-')
invalid_escape_syntax_error ();
error ("Invalid escape char syntax: \\%c not followed by -", c);
}
FALLTHROUGH;
/* The prefixes \C- and \^ are equivalent. */
@ -2785,7 +2779,7 @@ read_char_escape (Lisp_Object readcharfun, int next_char)
}
if (count == 0)
invalid_escape_syntax_error ();
error ("Invalid escape char syntax: \\x not followed by hex digit");
if (count < 3 && i >= 0x80)
i = BYTE8_TO_CHAR (i);
modifiers |= i & CHAR_MODIFIER_MASK;