aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-09-05 22:39:11 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-09-05 22:39:11 +0200
commit789fe077a5a2c9846ab8b2f930833d9e9acf32f9 (patch)
treebb016f53ec9aa9c1baa3cbb85e94d5c11cce75ed /src
parentf76f7eaf0a41449a2e3c88c1a240e37e2d741ec2 (diff)
Use more accurate position information
Diffstat (limited to 'src')
-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);
}