More error reporting improvemnts.
[pspp] / src / language / lexer / lexer.c
index 1025414a7c4407bf265519af144b255c1d836629..562fcc5827d3a4662d237633cb3785dee6e0cf33 100644 (file)
@@ -1606,21 +1606,26 @@ lex_source_error_valist (struct lex_source *src, int n0, int n1,
   msg_emit (m);
 }
 
-static void PRINTF_FORMAT (2, 3)
-lex_get_error (struct lex_source *src, const char *format, ...)
+static void PRINTF_FORMAT (4, 5)
+lex_source_error (struct lex_source *src, int n0, int n1,
+                  const char *format, ...)
 {
   va_list args;
   va_start (args, format);
+  lex_source_error_valist (src, n0, n1, format, args);
+  va_end (args);
+}
 
+static void
+lex_get_error (struct lex_source *src, const char *s)
+{
   size_t old_middle = src->middle;
   src->middle = src->front;
   size_t n = src->front - src->back - 1;
-  lex_source_error_valist (src, n, n, format, args);
+  lex_source_error (src, n, n, "%s", s);
   src->middle = old_middle;
 
   lex_source_pop_front (src);
-
-  va_end (args);
 }
 
 /* Attempts to append an additional token at the front of SRC, reading more
@@ -1772,44 +1777,17 @@ lex_source_try_get__ (struct lex_source *src)
       return true;
 
     case SCAN_BAD_HEX_LENGTH:
-      lex_get_error (src, _("String of hex digits has %d characters, which "
-                            "is not a multiple of 2"),
-                     (int) token->token.number);
-      return false;
-
     case SCAN_BAD_HEX_DIGIT:
     case SCAN_BAD_UNICODE_DIGIT:
-      lex_get_error (src, _("`%c' is not a valid hex digit"),
-                     (int) token->token.number);
-      return false;
-
     case SCAN_BAD_UNICODE_LENGTH:
-      lex_get_error (src, _("Unicode string contains %d bytes, which is "
-                            "not in the valid range of 1 to 8 bytes"),
-                     (int) token->token.number);
-      return false;
-
     case SCAN_BAD_UNICODE_CODE_POINT:
-      lex_get_error (src, _("U+%04X is not a valid Unicode code point"),
-                     (int) token->token.number);
-      return false;
-
     case SCAN_EXPECTED_QUOTE:
-      lex_get_error (src, _("Unterminated string constant"));
-      return false;
-
     case SCAN_EXPECTED_EXPONENT:
-      lex_get_error (src, _("Missing exponent following `%s'"),
-                     token->token.string.string);
-      return false;
-
     case SCAN_UNEXPECTED_CHAR:
-      {
-        char c_name[16];
-        lex_get_error (src, _("Bad character %s in input"),
-                       uc_name (token->token.number, c_name));
-        return false;
-      }
+      char *msg = scan_token_to_error (&token->token);
+      lex_get_error (src, msg);
+      free (msg);
+      return false;
 
     case SCAN_SKIP:
       lex_source_pop_front (src);
@@ -1917,7 +1895,7 @@ lex_source_get (const struct lex_source *src_)
 
   /* Now expand the macro. */
   struct macro_tokens expansion = { .n = 0 };
-  macro_expander_get_expansion (me, &expansion);
+  macro_expander_get_expansion (me, src->reader->syntax, &expansion);
   macro_expander_destroy (me);
 
   /* Convert the macro expansion into syntax for possible error messages later. */