Pino Toscano
2014-Apr-02 16:13 UTC
[Libguestfs] [PATCH] builder: better handle some index parsing errors
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
Richard W.M. Jones
2014-Apr-03 08:00 UTC
[Libguestfs] [PATCH] builder: better handle some index parsing errors
On Wed, Apr 02, 2014 at 06:13:59PM +0200, Pino Toscano wrote:> 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).Seems OK, but is the patch incomplete? Should something in the parser handle the new symbol by displaying a better error? While looking at this I realized that we didn't have any tests of the parser. See the patch I just posted. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Pino Toscano
2014-Apr-03 08:59 UTC
Re: [Libguestfs] [PATCH] builder: better handle some index parsing errors
On Thursday 03 April 2014 09:00:43 Richard W.M. Jones wrote:> On Wed, Apr 02, 2014 at 06:13:59PM +0200, Pino Toscano wrote: > > 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). > > Seems OK, but is the patch incomplete? Should something in the parser > handle the new symbol by displaying a better error?The parser should now just error out when it is given a token it doesn't handle- Or, at least, it is how I got it working to try to cleanly handle faults in the lexer without resorting to call yyerror manually. Instead of "unexpected character in input" now there is "syntax error" as message. -- Pino Toscano