#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); \
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;
}
}
}
- lex_error(_("syntax error, unexpected '%s'"), buf);
+ cdecl__err(CDECL_ENOPARSE, _("syntax error, unexpected '%s'"), buf);
+ return T_LEX_ERROR;
}