From 76260a7696319d840724bd89923b28d22654ed3f Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 18 Feb 2009 01:57:50 +0000 Subject: [PATCH] bison yyerror() passing yylloc to errFunc() but line number is coming out as 1 git-svn-id: svn://anubis/fart/trunk@128 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- parser/parser.lex | 2 ++ parser/parser.yy | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/parser/parser.lex b/parser/parser.lex index 04b5295..7018fbd 100644 --- a/parser/parser.lex +++ b/parser/parser.lex @@ -71,4 +71,6 @@ width return WIDTH; \n /* ignore newlines */ [ \t\v] /* ignore whitespace */ +. return -1; + %% diff --git a/parser/parser.yy b/parser/parser.yy index 4656c28..b99dd86 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -10,14 +10,13 @@ #include "parser.tab.hh" /* bison-generated header with YY[SL]TYPE */ using namespace std; +#define yyerror(msg) errFunc(msg, &yylloc) + int yylex(YYSTYPE *, YYLTYPE *); extern FILE * yyin; -void yyerror(const char * str) -{ - fprintf(stderr, "error: %s\n", str); -} +void errFunc(const char * str, YYLTYPE * yyllocp); int yywrap() { @@ -398,6 +397,18 @@ refptr parse(const char * fileName) cerr << "Failed to open file '" << fileName << "'" << endl; return refptr(NULL); } - yyparse(); + if (yyparse()) + { + cerr << "Aborting." << endl; + exit(1); + } return parsed_scene_node; } + +void errFunc(const char * str, YYLTYPE * yyllocp) +{ + fprintf(stderr, "error: %s: line %d, column %d\n", + str, + yyllocp->first_line, + yyllocp->first_column); +}