Only run the script if the parse succeeded, and and improve the
error reporting by enabling verbose errors and line numbers.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
%option stack noyy_top_state
%option reentrant
%option bison-bridge
+%option yylineno
%option noyyalloc noyyfree noyyrealloc
%option extra-type="struct grub2_parser *"
%option header-file="lexer.h"
%pure-parser
%lex-param { yyscan_t scanner }
%parse-param { struct grub2_parser *parser }
+%error-verbose
%{
#include <talloc/talloc.h>
void grub2_parser_parse(struct grub2_parser *parser, char *buf, int len)
{
YY_BUFFER_STATE bufstate;
+ int rc;
bufstate = yy_scan_bytes(buf, len - 1, parser->scanner);
- yyparse(parser);
+ rc = yyparse(parser);
yy_delete_buffer(bufstate, parser->scanner);
- script_execute(parser->script);
+ if (!rc)
+ script_execute(parser->script);
}