]> git.draconx.ca Git - cdecl99.git/blobdiff - src/scan.l
libcdecl: Consolidate most error messages.
[cdecl99.git] / src / scan.l
index 1688873eea7a98744f68041bd16a858cfd82b332..5610dc30fb7c5b891c59fd4c042ab05b85cde04c 100644 (file)
@@ -29,6 +29,7 @@
 #include <ctype.h>
 #include "cdecl-internal.h"
 #include "cdecl.h"
+#include "errmsg.h"
 
 #if HAVE_STRTOUMAX
 /* Best case, implementation provides strtoumax. */
 #define STRTOUMAX strtoul
 #endif
 
-#define lex_error(...) do { \
-       cdecl__err(CDECL_ENOPARSE, __VA_ARGS__); \
-       return T_LEX_ERROR; \
-} while(0)
-
 #define dup_token() do { \
        yylval->strval = malloc(yyleng+1); \
        if (!yylval->strval) { \
-               cdecl__err(CDECL_ENOMEM); \
+               cdecl__errmsg(CDECL__ENOMEM); \
                return T_LEX_ERROR; \
        } \
        strcpy(yylval->strval, yytext); \
@@ -117,10 +113,14 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
 
        errno = 0;
        yylval->uintval = STRTOUMAX(yytext, &end, 0);
-       if (errno == ERANGE)
-               lex_error(_("integer constant out of range"));
-       if (*end)
-               lex_error(_("invalid integer constant"));
+       if (errno == ERANGE) {
+               cdecl__errmsg(CDECL__ERANGE);
+               return T_LEX_ERROR;
+       }
+       if (*end) {
+               cdecl__errmsg(CDECL__EBADINT);
+               return T_LEX_ERROR;
+       }
 
        return T_UINT;
 }
@@ -165,5 +165,6 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
                }
        }
 
-       lex_error(_("syntax error, unexpected '%s'"), buf);
+       cdecl__err(CDECL_ENOPARSE, _("syntax error, unexpected '%s'"), buf);
+       return T_LEX_ERROR;
 }