File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -1448,11 +1448,16 @@ void error(char *msg)
14481448
14491449 strcpy (diagnostic + i , "^ Error occurs here" );
14501450
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 );
1451+ /* Backtrack SOURCE to find line of position */
1452+ int line = 1 ;
1453+ for (i = 0 ; i < start_idx ; i ++ ) {
1454+ if (SOURCE -> elements [i ] == '\n' )
1455+ 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 );
14561461 abort ();
14571462}
14581463
You can’t perform that action at this time.
0 commit comments