summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--discover/grub2/lexer.l7
-rw-r--r--discover/grub2/parser.y25
-rw-r--r--discover/grub2/script.c3
-rw-r--r--test/parser/Makefile.am2
-rw-r--r--test/parser/test-grub2-lexer-error.c13
-rw-r--r--test/parser/test-grub2-parser-error.c13
6 files changed, 47 insertions, 16 deletions
diff --git a/discover/grub2/lexer.l b/discover/grub2/lexer.l
index 0558ed9..e1aad99 100644
--- a/discover/grub2/lexer.l
+++ b/discover/grub2/lexer.l
@@ -3,6 +3,8 @@
#include "grub2.h"
#include "parser.h"
#include <talloc/talloc.h>
+
+void yyerror(struct grub2_parser *parser, const char *fmt, ...);
%}
%option nounput noinput
@@ -118,7 +120,10 @@ VARNAME ([[:alpha:]][_[:alnum:]]*|[0-9]|[\?@\*#])
/* strip comments */
#.* ;
-. printf("unknown token '%s'\n", yytext); exit(1);
+. {
+ yyerror(yyget_extra(yyscanner), "unknown token '%s'\n", yytext);
+ yyterminate();
+ }
%%
diff --git a/discover/grub2/parser.y b/discover/grub2/parser.y
index 02ca7b2..8ab17a6 100644
--- a/discover/grub2/parser.y
+++ b/discover/grub2/parser.y
@@ -6,17 +6,15 @@
%{
#include <talloc/talloc.h>
+#include <log/log.h>
#include "grub2.h"
#include "parser.h"
#include "lexer.h"
-static void print_token(FILE *fp, int type, YYSTYPE value);
-
#define YYLEX_PARAM parser->scanner
-#define YYPRINT(f, t, v) print_token(f, t, v)
-static void yyerror(struct grub2_parser *, char const *s);
+void yyerror(struct grub2_parser *parser, const char *fmt, ...);
%}
%union {
@@ -148,18 +146,17 @@ word: TOKEN_WORD
}
%%
-void yyerror(struct grub2_parser *parser, char const *s)
+void yyerror(struct grub2_parser *parser, const char *fmt, ...)
{
- fprintf(stderr, "%d: error: %s '%s'\n",
- yyget_lineno(parser->scanner),
- s, yyget_text(parser->scanner));
-}
+ const char *str;
+ va_list ap;
-static void print_token(FILE *fp, int type, YYSTYPE value)
-{
- if (type != TOKEN_WORD)
- return;
- fprintf(fp, "%s", value.word->text);
+ va_start(ap, fmt);
+ str = talloc_vasprintf(parser, fmt, ap);
+ va_end(ap);
+
+ pb_log("parse error: %d('%s'): %s\n", yyget_lineno(parser->scanner),
+ yyget_text(parser->scanner), str);
}
struct grub2_statements *create_statements(struct grub2_parser *parser)
diff --git a/discover/grub2/script.c b/discover/grub2/script.c
index 0cf2196..d0b824a 100644
--- a/discover/grub2/script.c
+++ b/discover/grub2/script.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
+#include <log/log.h>
#include <types/types.h>
#include <talloc/talloc.h>
@@ -278,7 +279,7 @@ int statement_simple_execute(struct grub2_script *script,
entry = script_lookup_function(script, st->argv->argv[0]);
if (!entry) {
- fprintf(stderr, "undefined function '%s'\n", st->argv->argv[0]);
+ pb_log("grub2: undefined function '%s'\n", st->argv->argv[0]);
return 1;
}
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am
index 8159bd6..e7146c5 100644
--- a/test/parser/Makefile.am
+++ b/test/parser/Makefile.am
@@ -35,6 +35,8 @@ TESTS = \
test-grub2-single-line-if \
test-grub2-f18-ppc64 \
test-grub2-ubuntu-13_04-x86 \
+ test-grub2-lexer-error \
+ test-grub2-parser-error \
test-kboot-single \
test-yaboot-single \
test-yaboot-partition \
diff --git a/test/parser/test-grub2-lexer-error.c b/test/parser/test-grub2-lexer-error.c
new file mode 100644
index 0000000..503ec99
--- /dev/null
+++ b/test/parser/test-grub2-lexer-error.c
@@ -0,0 +1,13 @@
+
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+&
+#endif
+
+void run_test(struct parser_test *test)
+{
+ test_read_conf_embedded(test);
+ test_run_parser(test, "grub2");
+ check_boot_option_count(test->ctx, 0);
+}
diff --git a/test/parser/test-grub2-parser-error.c b/test/parser/test-grub2-parser-error.c
new file mode 100644
index 0000000..a7a00a4
--- /dev/null
+++ b/test/parser/test-grub2-parser-error.c
@@ -0,0 +1,13 @@
+
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+{
+#endif
+
+void run_test(struct parser_test *test)
+{
+ test_read_conf_embedded(test);
+ test_run_parser(test, "grub2");
+ check_boot_option_count(test->ctx, 0);
+}
OpenPOWER on IntegriCloud