mirror of
https://github.com/UberGames/rpgxEF.git
synced 2025-04-22 08:50:48 +00:00
some changes to bg_lex
This commit is contained in:
parent
9a7adfab67
commit
57bf980ef7
3 changed files with 45 additions and 55 deletions
|
@ -8,6 +8,11 @@
|
|||
extern char *yyget_text (void* yyscanner);
|
||||
#endif
|
||||
|
||||
#ifndef YY_TYPEDEF_YY_SCANNER_T
|
||||
#define YY_TYPEDEF_YY_SCANNER_T
|
||||
typedef void* yyscan_t;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
LSYM_OBRACE, /* ( */
|
||||
LSYM_OBRACEC, /* { */
|
||||
|
@ -119,8 +124,8 @@ struct bgLexMorphem_s {
|
|||
|
||||
typedef struct bgLex_s bgLex;
|
||||
struct bgLex_s {
|
||||
void* lex;
|
||||
bgLexMorphem* morphem;
|
||||
yyscan_t lex;
|
||||
bgLexMorphem morphem;
|
||||
void* buf;
|
||||
};
|
||||
|
||||
|
|
|
@ -737,22 +737,11 @@ int main(int argc, char* argv[]) {
|
|||
bgLex* bgLex_create(char* data) {
|
||||
bgLex* l = malloc(sizeof(bgLex));
|
||||
|
||||
/* HACK HACK HACK ... get rid of some compiler warnings */
|
||||
UNUSED(yyunput);
|
||||
UNUSED(input);
|
||||
|
||||
if(l != NULL) {
|
||||
l->morphem = malloc(sizeof(bgLexMorphemData));
|
||||
l->morphem.line = 0;
|
||||
l->morphem.column = 0;
|
||||
|
||||
if(l->morphem == NULL) {
|
||||
free(l);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l->morphem->line = 0;
|
||||
l->morphem->column = 0;
|
||||
|
||||
yylex_init_extra(l->morphem, &l->lex);
|
||||
yylex_init_extra(&l->morphem, &l->lex);
|
||||
l->buf = yy_scan_string(data,l->lex);
|
||||
}
|
||||
|
||||
|
@ -772,24 +761,20 @@ void bgLex_destroy(bgLex* lex) {
|
|||
yylex_destroy(lex->lex);
|
||||
}
|
||||
|
||||
if(lex->morphem != NULL) {
|
||||
free(lex->morphem);
|
||||
}
|
||||
|
||||
free(lex);
|
||||
}
|
||||
|
||||
int bgLex_lex(bgLex* lex) {
|
||||
int res;
|
||||
|
||||
if(lex->morphem->data.str != NULL) {
|
||||
free(lex->morphem->data.str);
|
||||
if(lex->morphem.data.str != NULL) {
|
||||
free(lex->morphem.data.str);
|
||||
}
|
||||
|
||||
/* skip LMT_IGNORE */
|
||||
while(1) {
|
||||
res = yylex(lex->lex);
|
||||
if(lex->morphem->type != LMT_IGNORE) {
|
||||
if(lex->morphem.type != LMT_IGNORE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -921,10 +921,10 @@ static void G_LoadTimedMessages(void) {
|
|||
}
|
||||
|
||||
while(bgLex_lex(lexer) != 0) {
|
||||
if(lexer->morphem->type == LMT_STRING) {
|
||||
level.timedMessages->append(level.timedMessages, lexer->morphem->data.str, LT_STRING, strlen(lexer->morphem->data.str));
|
||||
if(lexer->morphem.type == LMT_STRING) {
|
||||
level.timedMessages->append(level.timedMessages, lexer->morphem.data.str, LT_STRING, strlen(lexer->morphem.data.str));
|
||||
} else {
|
||||
G_Logger(LL_WARN, "Unexpected token in timedmessages.cfg:%d:%d!\n", lexer->morphem->line, lexer->morphem->column);
|
||||
G_Logger(LL_WARN, "Unexpected token in timedmessages.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
|
||||
}
|
||||
}
|
||||
G_Logger(LL_INFO, "Loaded %d timed messages.\n", level.timedMessages->length);
|
||||
|
@ -1129,15 +1129,15 @@ static void G_LoadServerChangeFile(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem->data.symbol != LSYM_SERVER_CHANGE_CONFIG) {
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem.data.symbol != LSYM_SERVER_CHANGE_CONFIG) {
|
||||
G_LocLogger(LL_ERROR, "Expected 'ServerChangeConfig' at beginning of %s.\n", fileRoute);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
return;
|
||||
}
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem->data.symbol != LSYM_OBRACEC) {
|
||||
G_LocLogger(LL_ERROR, "Missing '{' at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem.data.symbol != LSYM_OBRACEC) {
|
||||
G_LocLogger(LL_ERROR, "Missing '{' at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
|
@ -1145,13 +1145,13 @@ static void G_LoadServerChangeFile(void) {
|
|||
}
|
||||
|
||||
while(bgLex_lex(lex) != 0) {
|
||||
if(lex->morphem->type == LMT_SYMBOL && lex->morphem->data.symbol == LSYM_CBRACEC) {
|
||||
if(lex->morphem.type == LMT_SYMBOL && lex->morphem.data.symbol == LSYM_CBRACEC) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(lex->morphem->type == LMT_SYMBOL && lex->morphem->data.symbol == LSYM_SERVER) {
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem->data.symbol != LSYM_OBRACESQ) {
|
||||
G_LocLogger(LL_ERROR, "Missing '[' at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
if(lex->morphem.type == LMT_SYMBOL && lex->morphem.data.symbol == LSYM_SERVER) {
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem.data.symbol != LSYM_OBRACESQ) {
|
||||
G_LocLogger(LL_ERROR, "Missing '[' at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
|
@ -1159,9 +1159,9 @@ static void G_LoadServerChangeFile(void) {
|
|||
}
|
||||
|
||||
if(bgLex_lex(lex) == LMT_STRING) {
|
||||
strncpy(level.srvChangeData.ip[level.srvChangeData.count], lex->morphem->data.str, sizeof(level.srvChangeData.ip[level.srvChangeData.count]));
|
||||
strncpy(level.srvChangeData.ip[level.srvChangeData.count], lex->morphem.data.str, sizeof(level.srvChangeData.ip[level.srvChangeData.count]));
|
||||
} else {
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
|
@ -1169,9 +1169,9 @@ static void G_LoadServerChangeFile(void) {
|
|||
}
|
||||
|
||||
if(bgLex_lex(lex) == LMT_STRING) {
|
||||
strncpy(level.srvChangeData.name[level.srvChangeData.count], lex->morphem->data.str, sizeof(level.srvChangeData.name[level.srvChangeData.count]));
|
||||
strncpy(level.srvChangeData.name[level.srvChangeData.count], lex->morphem.data.str, sizeof(level.srvChangeData.name[level.srvChangeData.count]));
|
||||
} else {
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
memset(level.srvChangeData.ip[level.srvChangeData.count], 0, sizeof(level.srvChangeData.ip[level.srvChangeData.count]));
|
||||
|
@ -1181,15 +1181,15 @@ static void G_LoadServerChangeFile(void) {
|
|||
|
||||
level.srvChangeData.count++;
|
||||
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem->data.symbol != LSYM_CBRACESQ) {
|
||||
G_LocLogger(LL_ERROR, "Missing ']' at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
if(bgLex_lex(lex) != LMT_SYMBOL || lex->morphem.data.symbol != LSYM_CBRACESQ) {
|
||||
G_LocLogger(LL_ERROR, "Missing ']' at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %d:%d. Expected '}' or 'Server'\n", lex->morphem->line, lex->morphem->column);
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %d:%d. Expected '}' or 'Server'\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
|
@ -1385,8 +1385,8 @@ static void G_LoadLocationsFile( void )
|
|||
return;
|
||||
}
|
||||
|
||||
if(lex->morphem->data.symbol == LSYM_LOCATIONS_LIST || lex->morphem->data.symbol == LSYM_LOCATIONS_LIST_2) {
|
||||
if(bgLex_lex(lex) == LMT_SYMBOL && lex->morphem->data.symbol == LSYM_OBRACEC) {
|
||||
if(lex->morphem.data.symbol == LSYM_LOCATIONS_LIST || lex->morphem.data.symbol == LSYM_LOCATIONS_LIST_2) {
|
||||
if(bgLex_lex(lex) == LMT_SYMBOL && lex->morphem.data.symbol == LSYM_OBRACEC) {
|
||||
if(bgLex_lex(lex) == 0) {
|
||||
G_LocLogger(LL_ERROR, "Unexpected end of file.\n");
|
||||
free(buffer);
|
||||
|
@ -1399,14 +1399,14 @@ static void G_LoadLocationsFile( void )
|
|||
}
|
||||
|
||||
while(qtrue) {
|
||||
if(lex->morphem->type == LMT_SYMBOL && lex->morphem->data.symbol == LSYM_CBRACEC) {
|
||||
if(lex->morphem.type == LMT_SYMBOL && lex->morphem.data.symbol == LSYM_CBRACEC) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(lex->morphem->type == LMT_VECTOR3) {
|
||||
VectorCopy(lex->morphem->data.vector3, origin);
|
||||
if(lex->morphem.type == LMT_VECTOR3) {
|
||||
VectorCopy(lex->morphem.data.vector3, origin);
|
||||
} else {
|
||||
G_LocLogger(LL_ERROR, "Expected vector at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
G_LocLogger(LL_ERROR, "Expected vector at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
|
@ -1414,9 +1414,9 @@ static void G_LoadLocationsFile( void )
|
|||
}
|
||||
|
||||
if(bgLex_lex(lex) == LMT_VECTOR3) {
|
||||
VectorCopy(lex->morphem->data.vector3, angles);
|
||||
VectorCopy(lex->morphem.data.vector3, angles);
|
||||
} else {
|
||||
G_LocLogger(LL_ERROR, "Expected vector at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
G_LocLogger(LL_ERROR, "Expected vector at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
|
@ -1426,7 +1426,7 @@ static void G_LoadLocationsFile( void )
|
|||
if(bgLex_lex(lex) == LMT_STRING) {
|
||||
int result;
|
||||
|
||||
desc = G_NewString(lex->morphem->data.str);
|
||||
desc = G_NewString(lex->morphem.data.str);
|
||||
|
||||
if(desc == NULL) {
|
||||
free(buffer);
|
||||
|
@ -1436,7 +1436,7 @@ static void G_LoadLocationsFile( void )
|
|||
|
||||
if((result = bgLex_lex(lex)) == LMT_STRING) {
|
||||
rest = atoi(desc);
|
||||
desc = G_NewString(lex->morphem->data.str);
|
||||
desc = G_NewString(lex->morphem.data.str);
|
||||
|
||||
if(bgLex_lex(lex) == 0) {
|
||||
G_LocLogger(LL_ERROR, "Unexpected end of file.\n");
|
||||
|
@ -1455,7 +1455,7 @@ static void G_LoadLocationsFile( void )
|
|||
}
|
||||
}
|
||||
} else {
|
||||
G_LocLogger(LL_ERROR, "ERROR: Expected string at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
G_LocLogger(LL_ERROR, "ERROR: Expected string at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
G_LogFuncEnd();
|
||||
|
@ -1495,7 +1495,7 @@ static void G_LoadLocationsFile( void )
|
|||
ent = NULL;
|
||||
rest = 0;
|
||||
|
||||
if(lex->morphem->type == LMT_SYMBOL && lex->morphem->data.symbol == LSYM_SEMICOLON) {
|
||||
if(lex->morphem.type == LMT_SYMBOL && lex->morphem.data.symbol == LSYM_SEMICOLON) {
|
||||
if(bgLex_lex(lex) == 0) {
|
||||
G_LocLogger(LL_ERROR, "Unexpected end of file.\n");
|
||||
free(buffer);
|
||||
|
@ -1504,11 +1504,11 @@ static void G_LoadLocationsFile( void )
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
G_Logger(LL_WARN, "Missing ';' at %d:%d.\n", lex->morphem->line, lex->morphem->column);
|
||||
G_Logger(LL_WARN, "Missing ';' at %d:%d.\n", lex->morphem.line, lex->morphem.column);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %s:%d:%d.\n", fileRoute, lex->morphem->line, lex->morphem->column);
|
||||
G_LocLogger(LL_ERROR, "Unexpected token at %s:%d:%d.\n", fileRoute, lex->morphem.line, lex->morphem.column);
|
||||
G_LocLogger(LL_ERROR, "Expected 'LocationsList' or 'LocationsList2'.\n");
|
||||
free(buffer);
|
||||
bgLex_destroy(lex);
|
||||
|
@ -1516,7 +1516,7 @@ static void G_LoadLocationsFile( void )
|
|||
return;
|
||||
}
|
||||
|
||||
if(lex->morphem->type != LMT_SYMBOL || lex->morphem->data.symbol != LSYM_CBRACEC) {
|
||||
if(lex->morphem.type != LMT_SYMBOL || lex->morphem.data.symbol != LSYM_CBRACEC) {
|
||||
G_Logger(LL_WARN, "Missing closing brace '}'!\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue