use last_column instead of first_column for error column tracking

This commit is contained in:
Josh Holtrop 2018-04-23 23:26:43 -04:00
parent 45de80c852
commit 49afce6095
2 changed files with 7 additions and 6 deletions

View File

@ -85,7 +85,7 @@ static void display_error_source(int line, int column)
{
file[i] = '\0';
fprintf(stderr, "%s\n", line_begin);
for (int i = 0; i < column; i++)
for (int i = 0; i < (column - 1); i++)
{
fprintf(stderr, " ");
}
@ -101,7 +101,7 @@ void handle_parse_error(const char * str, const YYLTYPE * yylloc)
{
fprintf(stderr, "error: %s (line %d, column %d)\n",
str,
yylloc->first_line,
yylloc->first_column);
display_error_source(yylloc->first_line, yylloc->first_column);
yylloc->last_line,
yylloc->last_column);
display_error_source(yylloc->last_line, yylloc->last_column);
}

View File

@ -11,6 +11,7 @@
#define YY_USER_ACTION \
do { \
yylloc->first_column += yyleng; \
yylloc->last_column += yyleng; \
*yylval = Node_new(NODE_TYPE_TOKEN); \
(*yylval)->token.fname = current_file; \
(*yylval)->token.line = current_line; \
@ -181,9 +182,9 @@ L?\" {
}
\n {
yylloc->first_line++;
yylloc->first_column = 0;
yylloc->first_column = 1;
yylloc->last_line++;
yylloc->last_column = 0;
yylloc->last_column = 1;
current_line++;
}
[ \t\v] /* ignore whitespace */