aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lexer.l13
-rw-r--r--src/parser.y3
2 files changed, 14 insertions, 2 deletions
diff --git a/src/lexer.l b/src/lexer.l
index 5242af0..8715932 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -5,7 +5,18 @@
#include "parser.h"
#include "pinocchio.h"
-#define YY_USER_ACTION yylloc.first_line = yylloc.last_line = yylineno;
+#define YY_USER_ACTION \
+ do { \
+ yylloc.first_column = yylloc.last_column; \
+ yylloc.first_line = yylloc.last_line; \
+ for (int i = 0; i < yyleng; i++) { \
+ if (yytext[i] == '\n') { \
+ yylloc.last_column = 1; \
+ yylloc.last_line++; \
+ } else \
+ yylloc.last_column++; \
+ } \
+ } while (0);
extern const char *current_file;
%}
diff --git a/src/parser.y b/src/parser.y
index 827005d..2474213 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -124,5 +124,6 @@ mkbinop(yytoken_kind_t op, ast_t lhs, ast_t rhs)
void
yyerror(const char *s)
{
- user_error("%s:%d: %s", current_file, yylloc.first_line, s);
+ user_error("%s:%d:%d: %s", current_file, yylloc.first_line,
+ yylloc.first_column, s);
}