We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 3cbbdee + c33b078 commit c044948Copy full SHA for c044948
1 file changed
src/globals.c
@@ -1448,11 +1448,16 @@ void error(char *msg)
1448
1449
strcpy(diagnostic + i, "^ Error occurs here");
1450
1451
- /* TODO: Implement line/column tracking for precise error location
1452
- * reporting. Current implementation only shows source position offset.
1453
- */
1454
- printf("[Error]: %s\nOccurs at source location %d.\n%s\n", msg,
1455
- SOURCE->size, diagnostic);
+ /* Backtrack SOURCE to find line of position */
+ int line = 1;
+ for (i = 0; i < start_idx; i++) {
+ if (SOURCE->elements[i] == '\n')
+ line++;
1456
+ }
1457
+ int column = SOURCE->size - start_idx + 1;
1458
+
1459
+ printf("[Error]: %s\nOccurs at source location %d:%d.\n%s\n", msg, line,
1460
+ column, diagnostic);
1461
abort();
1462
}
1463
0 commit comments