aboutsummaryrefslogtreecommitdiff
path: root/cibic.l
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2014-03-25 06:57:44 +0800
committerTeddy <ted.sybil@gmail.com>2014-03-25 06:57:44 +0800
commit79b8219a7b8a786740a6c57b2d819953bcf261de (patch)
treea0e81987d32f5748ff99de2c67dd543abd42417f /cibic.l
parent04ee9c8bef572f4351090b768413e5b6a3ac4a77 (diff)
verbose error reporting
Diffstat (limited to 'cibic.l')
-rw-r--r--cibic.l19
1 files changed, 14 insertions, 5 deletions
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
%%
+
<INITIAL>{
"/*" 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; }
}
<INITIAL>{
"//" BEGIN(IN_INLINE_COMMENT);
}
<IN_INLINE_COMMENT>{
-\n BEGIN(INITIAL);
+\n { yycolumn = 1; BEGIN(INITIAL); }
[^\n]+
}
<INITIAL>{
-"#" BEGIN(IN_INLINE_COMMENT);
+"#" BEGIN(IN_DIRECTIVE);
}
<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; }
%%