[Libguestfs] [PATCH] builder: better handle some index parsing errors

Pino Toscano ptoscano at redhat.com
Wed Apr 2 16:13:59 UTC 2014


Add a new lexer token, unused in the grammar, for the unknown lines in
index files; this should allow to better handle such kind of parsing
errors, removing the need to exit() directly (and leave things in an
unclean state).
---
 builder/index-parse.y | 1 +
 builder/index-scan.l  | 5 +----
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/builder/index-parse.y b/builder/index-parse.y
index f08a683..310870d 100644
--- a/builder/index-parse.y
+++ b/builder/index-parse.y
@@ -78,6 +78,7 @@ typedef void *yyscan_t;
 %token         EMPTY_LINE
 %token         PGP_PROLOGUE
 %token         PGP_EPILOGUE
+%token         UNKNOWN_LINE
 
 %type <section> sections section
 %type <field>   fields field
diff --git a/builder/index-scan.l b/builder/index-scan.l
index 073d85f..e3fe377 100644
--- a/builder/index-scan.l
+++ b/builder/index-scan.l
@@ -29,8 +29,6 @@
 #define YY_EXTRA_TYPE struct parse_context *
 #define YY_USER_ACTION yylloc->first_line = yylloc->last_line = yylineno;
 
-extern void yyerror (YYLTYPE * yylloc, yyscan_t scanner, struct parse_context *context, const char *msg);
-
 %}
 
 %option nounput
@@ -110,8 +108,7 @@ extern void yyerror (YYLTYPE * yylloc, yyscan_t scanner, struct parse_context *c
 
  /* anything else is an error */
 . {
-  yyerror (yylloc, yyscanner, yyextra, "unexpected character in input");
-  exit (EXIT_FAILURE);
+  return UNKNOWN_LINE;
 }
 
 %%
-- 
1.9.0




More information about the Libguestfs mailing list