From 0da173cfd8e18946a1b5b7d44bc104c14f293300 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Sun, 6 Jun 2021 12:42:26 +0100 Subject: [PATCH] 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. --- simgear/nasal/lex.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/simgear/nasal/lex.c b/simgear/nasal/lex.c index 00777e97..1068a90a 100644 --- a/simgear/nasal/lex.c +++ b/simgear/nasal/lex.c @@ -1,5 +1,7 @@ #include "parse.h" +#include + // Static table of recognized lexemes in the language static const struct Lexeme { char* str; @@ -391,6 +393,21 @@ void naLex(struct Parser* p) newToken(p, i, TOK_SYMBOL, p->buf+i, symlen, 0); i += symlen; } else { + //const char* line_begin = p->buf; + int line = 1; + int column = 0; + for (int j=0; jbuf[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); } }