]> git.draconx.ca Git - cdecl99.git/blobdiff - src/parse.y
libcdecl: Re-use strings from parser in spec_string.
[cdecl99.git] / src / parse.y
index bf2a596b1a4a037fee49fe36cd724454e11d8f27..263129cea8d6f3f9cc9a4b35c2341fa139d14d5f 100644 (file)
@@ -1,7 +1,7 @@
 %code top {
 /*
  *  Parser for C declarations.
- *  Copyright © 2011-2012, 2021 Nick Bowler
+ *  Copyright © 2011-2012, 2021, 2023 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -34,6 +34,7 @@
 #include "scan.h"
 #include "cdecl.h"
 #include "cdecl-internal.h"
+#include "errmsg.h"
 
 #define FAIL(msg) do { \
        yyerror(&yylloc, NULL, NULL, msg); \
@@ -43,7 +44,7 @@
 #define ALLOC(ptr, size) do { \
        (ptr) = malloc(size); \
        if (!(ptr)) { \
-               cdecl__err(CDECL_ENOMEM); \
+               cdecl__errmsg(CDECL__ENOMEM); \
                YYERROR; \
        } \
 } while (0)
@@ -61,6 +62,7 @@
 %code provides {
 void cdecl__free(struct cdecl *);
 int cdecl__yyparse(void *scanner, struct cdecl **out);
+const char *cdecl__token_name(unsigned token);
 }
 
 %union {
@@ -588,3 +590,18 @@ english_vla: T_IDENT | {
        ALLOC($$, sizeof "");
        strcpy($$, "");
 }
+
+%%
+
+/*
+ * Expose the token string table to the rest of the library, in order to
+ * produce strings that match parser keywords.
+ *
+ * In order for this to work properly, the Bison output must be postprocessed
+ * by fix-yytname.awk to remove pointless quotation marks from the keyword
+ * strings.
+ */
+const char *cdecl__token_name(unsigned token)
+{
+       return yytname[YYTRANSLATE(token)];
+}