]> git.eshelyaron.com Git - emacs.git/commitdiff
More descriptive character escape syntax error messages (bug#63436)
authorMattias Engdegård <mattiase@acm.org>
Thu, 11 May 2023 09:49:06 +0000 (11:49 +0200)
committerMattias Engdegård <mattiase@acm.org>
Thu, 11 May 2023 09:52:47 +0000 (11:52 +0200)
* 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.

src/lread.c

index 273120315df9f96978e4dd13a17a407fabe9badf..67cd7185d043795ebeed6b7f6e613bf35026b80a 100644 (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;