diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-09-05 22:39:11 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-09-05 22:39:11 +0200 |
commit | 789fe077a5a2c9846ab8b2f930833d9e9acf32f9 (patch) | |
tree | bb016f53ec9aa9c1baa3cbb85e94d5c11cce75ed | |
parent | f76f7eaf0a41449a2e3c88c1a240e37e2d741ec2 (diff) |
Use more accurate position information
-rw-r--r-- | src/lexer.l | 13 | ||||
-rw-r--r-- | 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); } |