diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh
index 0c21db3b6aa58a68a0333569358aada9d73e1968..a4aee28b10ce59a820dd9a95ba0e366278e8bffc 100644
--- a/src/ParsingDriver.hh
+++ b/src/ParsingDriver.hh
@@ -75,7 +75,7 @@ public:
   string filename;
 
   //! Increment the location counter given a token
-  void location_increment(Dynare::parser::location_type *yylloc, const char *yytext);
+  static void location_increment(Dynare::parser::location_type *yylloc, const char *yytext);
 
   //! Count parens in dates statement
   int dates_parens_nb;
diff --git a/src/macro/Driver.hh b/src/macro/Driver.hh
index 5f1367f390e52f4f60044cb94d76110804a94d29..4d600a800a81b9486586e5c7b0db56a24ef6199d 100644
--- a/src/macro/Driver.hh
+++ b/src/macro/Driver.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019-2020 Dynare Team
+ * Copyright © 2019-2021 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -56,6 +56,7 @@ namespace macro
     Tokenizer::parser::token_type lex(Tokenizer::parser::semantic_type *yylval,
                                       Tokenizer::parser::location_type *yylloc,
                                       macro::Driver &driver);
+    static void location_increment(Tokenizer::parser::location_type *yylloc, const char *yytext);
   };
 
   //! Implements the macro expansion using a Flex scanner and a Bison parser
diff --git a/src/macro/Tokenizer.ll b/src/macro/Tokenizer.ll
index c72561e4ef30fb9001c39ea8426b1b64c1de39be..c930cc5468ee6eee2f8ecee9bd0350a44a0c6fc4 100644
--- a/src/macro/Tokenizer.ll
+++ b/src/macro/Tokenizer.ll
@@ -50,7 +50,7 @@ using token = Tokenizer::parser::token;
 
 %{
   // Increments location counter for every token read
-  # define YY_USER_ACTION yylloc->columns(yyleng);
+  #define YY_USER_ACTION location_increment(yylloc, yytext);
 %}
 
 SPC  [ \t]+
@@ -175,22 +175,15 @@ CONT \\\\{SPC}*
 }
 
 <expr,eval>{SPC}+                         { }
-<eval>{EOL}+                              { yylloc->lines(yyleng); yylloc->lines(yyleng); }
+<eval>{EOL}+                              { }
 <eval>\}                                  { BEGIN(INITIAL); return token::END_EVAL; }
 
-<expr,end_line>{CONT}("//".*)?{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); }
-<expr,end_line>{SPC}*("//".*)?{EOL}       {
-                                            yylloc->lines(1);
-                                            BEGIN(INITIAL);
-                                            return token::EOL;
-                                          }
+<expr,end_line>{CONT}("//".*)?{SPC}*{EOL} { yylloc->step(); }
+<expr,end_line>{SPC}*("//".*)?{EOL}       { BEGIN(INITIAL); return token::EOL; }
 
 <INITIAL>^{SPC}*@#{SPC}*                  { BEGIN(directive); }
 <INITIAL>@\{                              { BEGIN(eval); return token::BEGIN_EVAL; }
-<INITIAL>{EOL}                            {
-                                            yylloc->lines(1);
-                                            return token::EOL;
-                                          }
+<INITIAL>{EOL}                            { return token::EOL; }
 <INITIAL><<EOF>>                          { yyterminate(); }
 
 <directive,expr,eval,end_line><<EOF>>     { driver.error(*yylloc, "unexpected end of file"); }
@@ -200,6 +193,16 @@ CONT \\\\{SPC}*
 
 %%
 
+void
+TokenizerFlex::location_increment(Tokenizer::parser::location_type *yylloc, const char *yytext)
+{
+  while (*yytext != 0)
+    if (*yytext++ == '\n')
+      yylloc->lines(1);
+    else
+      yylloc->columns(1);
+}
+
 /* This implementation of TokenizerFlexLexer::yylex() is required to fill the
  * vtable of the class TokenizerFlexLexer. We define the scanner's main yylex
  * function via YY_DECL to reside in the TokenizerFlex class instead. */