From 79b8219a7b8a786740a6c57b2d819953bcf261de Mon Sep 17 00:00:00 2001 From: Teddy Date: Tue, 25 Mar 2014 06:57:44 +0800 Subject: verbose error reporting --- cibic.l | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'cibic.l') diff --git a/cibic.l b/cibic.l index cd9b6eb..75244a0 100644 --- a/cibic.l +++ b/cibic.l @@ -1,12 +1,20 @@ %{ #include "cibic.tab.h" +int yycolumn = 1; +#define YY_USER_ACTION \ + yylloc.first_line = yylloc.last_line = yylineno; \ + yylloc.first_column = yycolumn; yylloc.last_column = yycolumn + yyleng - 1; \ + yycolumn += yyleng; + %} letter [a-zA-Z_$] digit [0-9] %s IN_BLOCK_COMMENT IN_INLINE_COMMENT IN_DIRECTIVE +%option yylineno %% + { "/*" BEGIN(IN_BLOCK_COMMENT); } @@ -14,22 +22,22 @@ digit [0-9] "*/" BEGIN(INITIAL); [^*\n]+ // eat comment in chunks "*" // eat the lone star -\n +\n { yycolumn = 1; } } { "//" BEGIN(IN_INLINE_COMMENT); } { -\n BEGIN(INITIAL); +\n { yycolumn = 1; BEGIN(INITIAL); } [^\n]+ } { -"#" BEGIN(IN_INLINE_COMMENT); +"#" BEGIN(IN_DIRECTIVE); } { -\n BEGIN(INITIAL); +\n { yycolumn = 1; BEGIN(INITIAL); } [^\n]+ } @@ -99,6 +107,7 @@ digit [0-9] [();,={}\[\]*|\^&<>+\-*//%~!.] { return *yytext; } -[ \t\n\r] /* skip whitespaces */ +[ \t\r] /* skip whitespaces */ +\n { yycolumn = 1; } . { return UNKNOWN; } %% -- cgit v1.2.3