]> git.draconx.ca Git - cdecl99.git/blobdiff - src/parse.y
Rework library error reporting.
[cdecl99.git] / src / parse.y
index 11ae6bb824cea90073c64d158a2a9d49ccfaf4cb..bf2a596b1a4a037fee49fe36cd724454e11d8f27 100644 (file)
 
 #define ALLOC(ptr, size) do { \
        (ptr) = malloc(size); \
-       if (!(ptr)) \
-               FAIL("failed to allocate memory"); \
+       if (!(ptr)) { \
+               cdecl__err(CDECL_ENOMEM); \
+               YYERROR; \
+       } \
 } while (0)
 
 #define ALLOC_STRUCT(ptr, type, ...) do { \
@@ -58,7 +60,6 @@
 
 %code provides {
 void cdecl__free(struct cdecl *);
-void cdecl__yyerror(YYLTYPE *, void *, struct cdecl **, const char *);
 int cdecl__yyparse(void *scanner, struct cdecl **out);
 }
 
@@ -138,6 +139,15 @@ void cdecl__free(struct cdecl *decl)
 {
        free_decl(decl);
 }
+
+static void
+yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err)
+{
+       if (strstr(err, "T_LEX_ERROR"))
+               return;
+
+       cdecl__err(CDECL_ENOPARSE, "%s", err);
+}
 %}
 
 %destructor { free($$); }            <strval>
@@ -336,7 +346,7 @@ vla_ident: T_IDENT | T_ASTERISK {
 
 array: T_LBRACKET T_UINT T_RBRACKET {
        if ($2 == 0)
-               FAIL("array length must be positive");
+               FAIL(_("array length must be positive"));
 
        ALLOC_STRUCT($$, struct cdecl_declarator,
                .type = CDECL_DECL_ARRAY,
@@ -563,7 +573,7 @@ english_array: T_VLA T_ARRAY english_vla T_OF {
                .u.array.vla = $3);
 } | T_ARRAY T_UINT T_OF {
        if ($2 == 0)
-               FAIL("array length must be positive");
+               FAIL(_("array length must be positive"));
 
        ALLOC_STRUCT($$, struct cdecl_declarator,
                .type = CDECL_DECL_ARRAY,
@@ -578,16 +588,3 @@ english_vla: T_IDENT | {
        ALLOC($$, sizeof "");
        strcpy($$, "");
 }
-
-%%
-void
-yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err)
-{
-       if (strstr(err, "T_LEX_ERROR"))
-               return;
-
-       cdecl__set_error(&(const struct cdecl_error){
-               .code = CDECL_ENOPARSE,
-               .str  = err,
-       });
-}