%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
#include "scan.h"
#include "cdecl.h"
#include "cdecl-internal.h"
+#include "errmsg.h"
#define FAIL(msg) do { \
yyerror(&yylloc, NULL, NULL, msg); \
#define ALLOC(ptr, size) do { \
(ptr) = malloc(size); \
if (!(ptr)) { \
- cdecl__err(CDECL_ENOMEM); \
+ cdecl__errmsg(CDECL__ENOMEM); \
YYERROR; \
} \
} while (0)
%code provides {
void cdecl__free(struct cdecl *);
int cdecl__yyparse(void *scanner, struct cdecl **out);
+const char *cdecl__token_name(unsigned token);
}
%union {
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)];
+}