simgear/nasal/lex.c: show line and column if illegal character is found.
Makes it easier to track down e.g. missing quotes in Nasal source within .xml files.
This commit is contained in:
parent
95239fea87
commit
0da173cfd8
@ -1,5 +1,7 @@
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
// Static table of recognized lexemes in the language
|
// Static table of recognized lexemes in the language
|
||||||
static const struct Lexeme {
|
static const struct Lexeme {
|
||||||
char* str;
|
char* str;
|
||||||
@ -391,6 +393,21 @@ void naLex(struct Parser* p)
|
|||||||
newToken(p, i, TOK_SYMBOL, p->buf+i, symlen, 0);
|
newToken(p, i, TOK_SYMBOL, p->buf+i, symlen, 0);
|
||||||
i += symlen;
|
i += symlen;
|
||||||
} else {
|
} else {
|
||||||
|
//const char* line_begin = p->buf;
|
||||||
|
int line = 1;
|
||||||
|
int column = 0;
|
||||||
|
for (int j=0; j<i; ++j) {
|
||||||
|
if (p->buf[j] == '\n') {
|
||||||
|
line += 1;
|
||||||
|
column = 0;
|
||||||
|
//line_begin = p->buf + j + 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
column += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(stderr, "%s:%i: illegal character 0x%x at line=%i column=%i.\n",
|
||||||
|
__FILE__, __LINE__, c, line, column);
|
||||||
error(p, "illegal character", i);
|
error(p, "illegal character", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user