From 9d3b2face7c01dd40e659da5b93ed2045b52b352 Mon Sep 17 00:00:00 2001 From: Walter Julius Hennecke Date: Mon, 18 Aug 2014 00:31:54 +0200 Subject: [PATCH] Added additional parse functionality. #12 --- code/game/bg_lex.h | 3 + code/game/bg_lex.lex | 12 ++ code/game/bg_lex.yy.c | 12 ++ code/game/g_weapon.c | 332 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 355 insertions(+), 4 deletions(-) diff --git a/code/game/bg_lex.h b/code/game/bg_lex.h index 6b606ed..3e30c43 100644 --- a/code/game/bg_lex.h +++ b/code/game/bg_lex.h @@ -104,6 +104,9 @@ typedef enum { LSYM_WCONF_VARIATION, LSYM_WCONF_RADIUS, LSYM_WCONF_SIZE, + LSYM_WCONF_TIME, + LSYM_WCONF_VELOCITY, + LSYM_WCONF_SPLASH, LSYM_POINT, LSYM_UNKNOWN diff --git a/code/game/bg_lex.lex b/code/game/bg_lex.lex index 008aeca..a5065c6 100644 --- a/code/game/bg_lex.lex +++ b/code/game/bg_lex.lex @@ -1124,6 +1124,18 @@ bgLexSymbol bgLex_textToSymbol(char* text) { return LSYM_WCONF_SIZE; } + if(strcmp("time", text) == 0) { + return LSYM_WCONF_TIME; + } + + if(strcmp("velocity", text) == 0) { + return LSYM_WCONF_VELOCITY; + } + + if(strcmp("splash", text) == 0) { + return LSYM_WCONF_SPLASH; + } + return LSYM_UNKNOWN; } diff --git a/code/game/bg_lex.yy.c b/code/game/bg_lex.yy.c index e9aef66..412b9ae 100644 --- a/code/game/bg_lex.yy.c +++ b/code/game/bg_lex.yy.c @@ -3534,6 +3534,18 @@ bgLexSymbol bgLex_textToSymbol(char* text) { return LSYM_WCONF_SIZE; } + if(strcmp("time", text) == 0) { + return LSYM_WCONF_TIME; + } + + if(strcmp("velocity", text) == 0) { + return LSYM_WCONF_VELOCITY; + } + + if(strcmp("splash", text) == 0) { + return LSYM_WCONF_SPLASH; + } + return LSYM_UNKNOWN; } diff --git a/code/game/g_weapon.c b/code/game/g_weapon.c index 8a46038..b7f1d53 100644 --- a/code/game/g_weapon.c +++ b/code/game/g_weapon.c @@ -238,7 +238,7 @@ static qboolean G_Weapon_ParseWeaponConfig(bgLex* lexer) { return qfalse; } break; - default: + default: G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); G_LogFuncEnd(); return qfalse; @@ -287,7 +287,7 @@ static qboolean G_Weapon_ParseWeaponConfig(bgLex* lexer) { return qfalse; } break; - default: + default: G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); G_LogFuncEnd(); return qfalse; @@ -301,20 +301,344 @@ static qboolean G_Weapon_ParseWeaponConfig(bgLex* lexer) { } break; case LSYM_WCONF_DISRUPTOR: - + while (bgLex_lex(lexer) != 0) { + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } else { + if (lexer->morphem.data.symbol == LSYM_WCONF_PRIMARY) { + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL || lexer->morphem.data.symbol != LSYM_POINT) { + G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + switch (lexer->morphem.data.symbol) { + case LSYM_WCONF_DAMAGE: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.disruptor.primary.damage = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_RANGE: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_DOUBLE) { + weaponConfig.disruptor.primary.range = lexer->morphem.data.numDouble; + } else { + G_Logger(LL_ERROR, "Expected double value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + default: + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else if (lexer->morphem.data.symbol == LSYM_WCONF_SECONDARY) { + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL || lexer->morphem.data.symbol != LSYM_POINT) { + G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + switch (lexer->morphem.data.symbol) { + case LSYM_WCONF_DAMAGE: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.disruptor.secondary.damage = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_SIZE: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.disruptor.secondary.size = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + default: + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Expected 'primary' or 'secondary' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } + } break; case LSYM_WCONF_GRENADE: - + while (bgLex_lex(lexer) != 0) { + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } else { + if (lexer->morphem.data.symbol == LSYM_WCONF_PRIMARY) { + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL || lexer->morphem.data.symbol != LSYM_POINT) { + G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + switch (lexer->morphem.data.symbol) { + case LSYM_WCONF_DAMAGE: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.primary.damage = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_SIZE: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_DOUBLE) { + weaponConfig.grenade.primary.size = lexer->morphem.data.numDouble; + } else { + G_Logger(LL_ERROR, "Expected double value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_TIME: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.primary.time = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_VELOCITY: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_DOUBLE) { + weaponConfig.grenade.primary.velocity = lexer->morphem.data.numDouble; + } else { + G_Logger(LL_ERROR, "Expected double value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_SPLASH: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_SYMBOL && lexer->morphem.data.symbol == LSYM_POINT) { + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_SYMBOL) { + if (lexer->morphem.data.symbol == LSYM_WCONF_DAMAGE) { + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.primary.splash.damage = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else if(lexer->morphem.data.symbol == LSYM_WCONF_RADIUS) { + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.primary.splash.radius = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Expected 'damage' or 'radius' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + default: + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else if (lexer->morphem.data.symbol == LSYM_WCONF_SECONDARY) { + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL || lexer->morphem.data.symbol != LSYM_POINT) { + G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + bgLex_lex(lexer); + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + switch (lexer->morphem.data.symbol) { + case LSYM_WCONF_DAMAGE: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.secondary.damage = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_TIME: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.secondary.time = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + case LSYM_WCONF_SPLASH: + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_SYMBOL && lexer->morphem.data.symbol == LSYM_POINT) { + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_SYMBOL) { + if (lexer->morphem.data.symbol == LSYM_WCONF_DAMAGE) { + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.secondary.splash.damage = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else if (lexer->morphem.data.symbol == LSYM_WCONF_RADIUS) { + bgLex_lex(lexer); + if (lexer->morphem.type == LMT_INT) { + weaponConfig.grenade.secondary.splash.radius = lexer->morphem.data.numInteger; + } else { + G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Expected 'damage' or 'radius' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + break; + default: + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } else { + G_Logger(LL_ERROR, "Expected 'primary' or 'secondary' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } + } break; case LSYM_WCONF_HYPERSPANNER: + while (bgLex_lex(lexer) != 0) { + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } else { + if (lexer->morphem.data.symbol == LSYM_WCONF_PRIMARY) { + + } else if (lexer->morphem.data.symbol == LSYM_WCONF_SECONDARY) { + } else { + G_Logger(LL_ERROR, "Expected 'primary' or 'secondary' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } + } break; case LSYM_WCONF_QUANTUM: + while (bgLex_lex(lexer) != 0) { + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } else { + if (lexer->morphem.data.symbol == LSYM_WCONF_PRIMARY) { + + } else if (lexer->morphem.data.symbol == LSYM_WCONF_SECONDARY) { + } else { + G_Logger(LL_ERROR, "Expected 'primary' or 'secondary' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } + } break; case LSYM_WCONF_TR116: + while (bgLex_lex(lexer) != 0) { + if (lexer->morphem.type != LMT_SYMBOL) { + G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } else { + if (lexer->morphem.data.symbol == LSYM_WCONF_PRIMARY) { + } else { + G_Logger(LL_ERROR, "Expected 'primary' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column); + G_LogFuncEnd(); + return qfalse; + } + } + } break; default: G_LocLogger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);