Show name on scanner errors for context

This commit is contained in:
Fernando Carmona Varo 2019-10-12 03:00:07 +02:00
parent 80ac8aa94d
commit 25f0f7b278
4 changed files with 8 additions and 5 deletions

View File

@ -332,7 +332,7 @@ static int ParseMapEntry(u_scanner_t *s, mapentry_t *val)
int U_ParseMapInfo(const char *buffer, size_t length)
{
unsigned int i;
u_scanner_t scanner = U_ScanOpen(buffer, length);
u_scanner_t scanner = U_ScanOpen(buffer, length, "UMAPINFO");
while (U_HasTokensLeft(&scanner))
{

View File

@ -86,7 +86,7 @@ void U_ParseMusInfo(const char *mapid)
int lumpnum;
int inMap = false;
u_scanner_t s = U_ScanOpen(data, datalength);
u_scanner_t s = U_ScanOpen(data, datalength, "MUSINFO");
while (U_HasTokensLeft(&s))
{
if (inMap || U_CheckToken(&s, TK_Identifier))

View File

@ -54,7 +54,7 @@ void U_ExpandState(u_scanner_t* scanner);
void U_Unescape(char *str);
void U_SetString(char **ptr, const char *start, int length);
u_scanner_t U_ScanOpen(const char* data, int length)
u_scanner_t U_ScanOpen(const char* data, int length, const char* name)
{
u_scanner_t scanner;
scanner.lineStart = scanner.logicalPosition = scanner.scanPos = scanner.tokenLinePosition = 0;
@ -62,6 +62,7 @@ u_scanner_t U_ScanOpen(const char* data, int length)
scanner.needNext = TRUE;
scanner.string = NULL;
scanner.nextState.string = NULL;
scanner.name = name;
if(length == -1)
length = strlen(data);
@ -470,7 +471,7 @@ void U_Error(u_scanner_t* s, const char *msg, ...)
va_start(ap, msg);
vsnprintf(buffer, 1024, msg, ap);
va_end(ap);
I_Error("%d:%d:%s.", s->tokenLine, s->tokenLinePosition, buffer);
I_Error("%s:%d:%d:%s.", s->name, s->tokenLine, s->tokenLinePosition, buffer);
}
boolean U_MustGetToken(u_scanner_t* s, char token)

View File

@ -63,6 +63,8 @@ typedef struct
typedef struct
{
const char* name;
u_parserstate_t nextState;
char* data;
@ -86,7 +88,7 @@ typedef struct
} u_scanner_t;
u_scanner_t U_ScanOpen(const char* data, int length);
u_scanner_t U_ScanOpen(const char* data, int length, const char *name);
void U_ScanClose(u_scanner_t* scanner);
boolean U_GetNextToken(u_scanner_t* scanner, boolean expandState);
boolean U_HasTokensLeft(u_scanner_t* scanner);