]> 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 6faf2d2b8b0d6eb4755491a43952b4659ebea9a4..263129cea8d6f3f9cc9a4b35c2341fa139d14d5f 100644 (file)
@@ -62,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 {
@@ -589,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)];
+}