-%{
/*
* clippy (CLI preparator in python) C pseudo-lexer
* Copyright (C) 2016-2017 David Lamparter for NetDEF, Inc.
* code documentation in it.
*/
-/* ignore harmless bug in old versions of flex */
+%top{
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+}
+%{
+/* ignore harmless bugs in old versions of flex */
#pragma GCC diagnostic ignored "-Wsign-compare"
+#pragma GCC diagnostic ignored "-Wunused-value"
#include "config.h"
#include <Python.h>
%option noyywrap
%option noinput
%option nounput
-%option outfile="defun_lex.c"
+%option outfile="lib/defun_lex.c"
%option prefix="def_yy"
%option 8bit
"DEFUN_NOSH" value = strdup(yytext); return DEFUNNY;
"DEFUN_HIDDEN" value = strdup(yytext); return DEFUNNY;
"DEFPY" value = strdup(yytext); return DEFUNNY;
+"DEFPY_NOSH" value = strdup(yytext); return DEFUNNY;
+"DEFPY_ATTR" value = strdup(yytext); return DEFUNNY;
+"DEFPY_HIDDEN" value = strdup(yytext); return DEFUNNY;
"ALIAS" value = strdup(yytext); return DEFUNNY;
"ALIAS_HIDDEN" value = strdup(yytext); return DEFUNNY;
"install_element" value = strdup(yytext); return INSTALL;
return rv;
}
-static PyObject *get_args(void)
+static PyObject *get_args(const char *filename, int lineno)
{
PyObject *pyObj = PyList_New(0);
PyObject *pyArg = NULL;
free(tval);
continue;
}
+ if (token == PREPROC) {
+ free(tval);
+ Py_DECREF(pyObj);
+ return PyErr_Format(PyExc_ValueError,
+ "%s:%d: cannot process CPP directive within argument list",
+ filename, lineno);
+ }
if (token == SPECIAL) {
if (depth == 1 && (tval[0] == ',' || tval[0] == ')')) {
if (pyArg)
case DEFUNNY:
case INSTALL:
case AUXILIARY:
- pyArgs = get_args();
+ pyArgs = get_args(filename, lineno);
+ if (!pyArgs) {
+ free(tval);
+ Py_DECREF(pyCont);
+ return NULL;
+ }
pyItem = PyDict_New();
PyDict_SetItemString(pyItem, "type", PyUnicode_FromString(tval));
PyDict_SetItemString(pyItem, "args", pyArgs);
pyItem = PyDict_New();
PyDict_SetItemString(pyItem, "type", PyUnicode_FromString("PREPROC"));
PyDict_SetItemString(pyItem, "line", PyUnicode_FromString(tval));
+ lineno--;
break;
}
if (pyItem) {