Line numbers now properly counted when there are comments.
Before, yyloc->lines() not called on newlines in comments. This resulted
in syntax errors to be reported at the wrong lines if files contained
comments.
Change-Id: I196142f30e2f6a98d480c4c866ba974066184c65
diff --git a/hidl-gen_l.ll b/hidl-gen_l.ll
index 750f426..578ec47 100644
--- a/hidl-gen_l.ll
+++ b/hidl-gen_l.ll
@@ -46,7 +46,6 @@
using namespace android;
using token = yy::parser::token;
-void comment(yyscan_t yyscanner, struct yyguts_t *yyg);
int check_type(yyscan_t yyscanner, struct yyguts_t *yyg);
#define SCALAR_TYPE(kind) \
@@ -68,10 +67,16 @@
%option bison-bridge
%option bison-locations
+%x COMMENT_STATE
+
%%
-"/*" { comment(yyscanner, yyg); }
-"//"[^\r\n]* { /* skip C++ style comment */ }
+"/*" { BEGIN(COMMENT_STATE); }
+<COMMENT_STATE>"*/" { BEGIN(INITIAL); }
+<COMMENT_STATE>[\n] { yylloc->lines(); }
+<COMMENT_STATE>. { }
+
+"//"[^\r\n]* { /* skip C++ style comment */ }
"enum" { return token::ENUM; }
"extends" { return token::EXTENDS; }
@@ -157,20 +162,6 @@
#pragma clang diagnostic pop
-void comment(yyscan_t yyscanner, yyguts_t *yyg) {
- char c, c1;
-
-loop:
- while ((c = yyinput(yyscanner)) != '*' && c != 0) {
- }
-
- if ((c1 = yyinput(yyscanner)) != '/' && c != 0)
- {
- unput(c1);
- goto loop;
- }
-}
-
status_t parseFile(AST *ast) {
FILE *file = fopen(ast->getFilename().c_str(), "rb");