Keep track of line number and filename from preprocessor output for error messages
This commit is contained in:
parent
74031d18d7
commit
b2072de717
@ -6,10 +6,14 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "parser.tab.h"
|
#include "parser.tab.h"
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define YY_USER_ACTION yylloc->first_column += yyleng;
|
#define YY_USER_ACTION yylloc->first_column += yyleng;
|
||||||
|
|
||||||
static String * build_string = NULL;
|
static String * build_string = NULL;
|
||||||
|
static size_t current_line = 1u;
|
||||||
|
static String * current_file = NULL;
|
||||||
|
void handle_loc(const char * input);
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@ -164,13 +168,36 @@ L?\" {
|
|||||||
[a-zA-Z_][a-zA-Z_0-9]* return TOK_IDENTIFIER;
|
[a-zA-Z_][a-zA-Z_0-9]* return TOK_IDENTIFIER;
|
||||||
|
|
||||||
^[ ]*#[ ]+[0-9]+[ ]+\".+\".*$ {
|
^[ ]*#[ ]+[0-9]+[ ]+\".+\".*$ {
|
||||||
|
handle_loc(yytext);
|
||||||
}
|
}
|
||||||
\n {
|
\n {
|
||||||
yylloc->first_line++;
|
yylloc->first_line++;
|
||||||
yylloc->first_column = 0;
|
yylloc->first_column = 0;
|
||||||
yylloc->last_line++;
|
yylloc->last_line++;
|
||||||
yylloc->last_column = 0;
|
yylloc->last_column = 0;
|
||||||
|
current_line++;
|
||||||
}
|
}
|
||||||
[ \t\v] /* ignore whitespace */
|
[ \t\v] /* ignore whitespace */
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
void handle_loc(const char * input)
|
||||||
|
{
|
||||||
|
while ((*input < '0') || (*input > '9'))
|
||||||
|
{
|
||||||
|
input++;
|
||||||
|
}
|
||||||
|
current_line = (size_t)atol(input) - 1u;
|
||||||
|
while (*input != '"')
|
||||||
|
{
|
||||||
|
input++;
|
||||||
|
}
|
||||||
|
input++;
|
||||||
|
const char * fname_start = input;
|
||||||
|
while (*input != '"')
|
||||||
|
{
|
||||||
|
input++;
|
||||||
|
}
|
||||||
|
size_t fname_len = (input - fname_start);
|
||||||
|
current_file = String_new_size(fname_start, fname_len);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user