diff options
author | Stefan Kost <ensonic@users.sf.net> | 2009-12-05 23:00:32 +0200 |
---|---|---|
committer | Stefan Kost <ensonic@users.sf.net> | 2009-12-05 23:00:32 +0200 |
commit | 58de797638c54954d56862b58c4ec78a57485131 (patch) | |
tree | fa75dc7229b1a1101fbe34e07753458637c70897 /giscanner | |
parent | 531442faea054507f7d50e36464ea1737e2423ac (diff) | |
download | gobject-introspection-58de797638c54954d56862b58c4ec78a57485131.tar.gz |
scanner: more verbose parser error messages
Keep track of the current line (the first 2000 chars of it) and include that in
syntax error messages. Also print that failed token in the error message.
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/scannerlexer.l | 8 | ||||
-rw-r--r-- | giscanner/scannerparser.y | 5 |
2 files changed, 10 insertions, 3 deletions
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l index cee91608..ff1ee0ff 100644 --- a/giscanner/scannerlexer.l +++ b/giscanner/scannerlexer.l @@ -37,6 +37,7 @@ #include "grealpath.h" int lineno; +char linebuf[2000]; #undef YY_BUF_SIZE #define YY_BUF_SIZE 1048576 @@ -61,7 +62,12 @@ stringtext ([^\\\"])|(\\.) %% -"\n" { ++lineno; } /* " */ +\n.* { strncpy(linebuf, yytext+1, sizeof(linebuf)); /* save the next line */ + linebuf[sizeof(linebuf)-1]='\0'; + /* printf("%4d:%s\n",lineno,linebuf); */ + yyless(1); /* give back all but the \n to rescan */ + ++lineno; + } "\\\n" { ++lineno; } [\t\f\v\r ]+ { /* Ignore whitespace. */ } diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y index c92a5381..7b18f941 100644 --- a/giscanner/scannerparser.y +++ b/giscanner/scannerparser.y @@ -38,6 +38,7 @@ extern FILE *yyin; extern int lineno; +extern char linebuf[2000]; extern char *yytext; extern int yylex (GISourceScanner *scanner); @@ -1281,8 +1282,8 @@ yyerror (GISourceScanner *scanner, const char *s) * have valid expressions */ if (!scanner->macro_scan) { - fprintf(stderr, "%s:%d: %s\n", - scanner->current_filename, lineno, s); + fprintf(stderr, "%s:%d: %s in '%s' at '%s'\n", + scanner->current_filename, lineno, s, linebuf, yytext); } } |