From 789fe077a5a2c9846ab8b2f930833d9e9acf32f9 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 5 Sep 2024 22:39:11 +0200 Subject: Use more accurate position information --- src/lexer.l | 13 ++++++++++++- src/parser.y | 3 ++- 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); } -- cgit v1.2.3