/*
* Parse and validate C declarations.
- * Copyright © 2011-2012, 2020-2021 Nick Bowler
+ * Copyright © 2011-2012, 2020-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
return true;
}
-struct cdecl *cdecl_parse_decl(const char *declstr)
+static struct cdecl *do_parse(const char *str, int english_mode)
{
- struct cdecl_declspec *norm_specs;
YY_BUFFER_STATE state;
yyscan_t scanner;
struct cdecl *decl;
- int rc;
- cdecl__init_i18n();
+#if YYDEBUG
+ extern int cdecl__yydebug;
+ cdecl__yydebug = 1;
+#endif
- rc = cdecl__yylex_init(&scanner);
- if (rc != 0)
+ cdecl__init_i18n();
+ if (cdecl__yylex_init_extra(english_mode, &scanner) != 0)
return NULL;
- state = cdecl__yy_scan_string(declstr, scanner);
- rc = cdecl__yyparse(scanner, &decl);
+ state = cdecl__yy_scan_string(str, scanner);
+ if (cdecl__yyparse(scanner, &decl) != 0)
+ decl = NULL;
cdecl__yy_delete_buffer(state, scanner);
cdecl__yylex_destroy(scanner);
- if (rc != 0)
+ return decl;
+}
+
+struct cdecl *cdecl_parse_decl(const char *declstr)
+{
+ struct cdecl_declspec *norm_specs;
+ struct cdecl *decl;
+
+ if (!(decl = do_parse(declstr, false)))
return NULL;
/*
struct cdecl *cdecl_parse_english(const char *english)
{
- YY_BUFFER_STATE state;
- yyscan_t scanner;
struct cdecl *decl;
- int rc;
-
- cdecl__init_i18n();
-
- rc = cdecl__yylex_init_extra(true, &scanner);
- if (rc != 0)
- return NULL;
-
- state = cdecl__yy_scan_string(english, scanner);
- rc = cdecl__yyparse(scanner, &decl);
- cdecl__yy_delete_buffer(state, scanner);
- cdecl__yylex_destroy(scanner);
- if (rc != 0)
+ if (!(decl = do_parse(english, true)))
return NULL;
for (struct cdecl *i = decl; i; i = i->next) {