From 7068070c0da0c4f28bf7b480477dca79e7ab8e94 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 4 Nov 2016 09:56:03 +0100 Subject: [PATCH] - fixed: The identifier fallback which existed for all other basic types was missing for 'state'. - added the option to put code right into the ZSCRIPT lump for smaller definitions where a file list would be too cumbersome. --- src/scripting/zscript/zcc-parse.lemon | 2 +- src/scripting/zscript/zcc_parser.cpp | 64 ++++++++++++++++++--------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/scripting/zscript/zcc-parse.lemon b/src/scripting/zscript/zcc-parse.lemon index b1065281c..9d22765fc 100644 --- a/src/scripting/zscript/zcc-parse.lemon +++ b/src/scripting/zscript/zcc-parse.lemon @@ -690,7 +690,7 @@ type_name(X) ::= DOT dottable_id(A). /* Type names can also be used as identifiers in contexts where type names * are not normally allowed. */ %fallback IDENTIFIER - SBYTE BYTE SHORT USHORT INT UINT BOOL FLOAT DOUBLE STRING VECTOR2 VECTOR3 NAME MAP ARRAY VOID. + SBYTE BYTE SHORT USHORT INT UINT BOOL FLOAT DOUBLE STRING VECTOR2 VECTOR3 NAME MAP ARRAY VOID STATE. /* Aggregate types */ %type aggregate_type {ZCC_Type *} diff --git a/src/scripting/zscript/zcc_parser.cpp b/src/scripting/zscript/zcc_parser.cpp index 84bebff40..fe6341bb3 100644 --- a/src/scripting/zscript/zcc_parser.cpp +++ b/src/scripting/zscript/zcc_parser.cpp @@ -179,9 +179,9 @@ static void InitTokenMap() TOKENDEF (TK_Loop, ZCC_LOOP); TOKENDEF (TK_Goto, ZCC_GOTO); TOKENDEF (TK_States, ZCC_STATES); - TOKENDEF (TK_State, ZCC_STATE); - TOKENDEF (TK_Color, ZCC_COLOR); - TOKENDEF (TK_Sound, ZCC_SOUND); + TOKENDEF2(TK_State, ZCC_STATE, NAME_State); + TOKENDEF2(TK_Color, ZCC_COLOR, NAME_Color); + TOKENDEF2(TK_Sound, ZCC_SOUND, NAME_Sound); TOKENDEF (TK_Identifier, ZCC_IDENTIFIER); TOKENDEF (TK_StringConst, ZCC_STRCONST); @@ -206,24 +206,27 @@ static void InitTokenMap() #undef TOKENDEF #undef TOKENDEF2 -static void ParseSingleFile(const char *filename, void *parser, ZCCParseState &state) +static void ParseSingleFile(const char *filename, int lump, void *parser, ZCCParseState &state) { int tokentype; - int lump; //bool failed; ZCCToken value; FScanner sc; - lump = Wads.CheckNumForFullName(filename, true); - if (lump >= 0) + if (filename != nullptr) { - sc.OpenLumpNum(lump); - } - else - { - Printf("Could not find script lump '%s'\n", filename); - return; + lump = Wads.CheckNumForFullName(filename, true); + if (lump >= 0) + { + sc.OpenLumpNum(lump); + } + else + { + Printf("Could not find script lump '%s'\n", filename); + return; + } } + else sc.OpenLumpNum(lump); state.sc = ≻ while (sc.GetToken()) @@ -309,20 +312,39 @@ static void DoParse(int lumpnum) #endif sc.OpenLumpNum(lumpnum); - // parse all files from this list in one go. - while (sc.GetString()) + auto saved = sc.SavePos(); + bool parsed = false; + if (sc.GetToken()) { - if (Wads.GetLumpFile(sc.LumpNum) == 0) + if (sc.TokenType == TK_Class || sc.TokenType == TK_Enum || sc.TokenType == TK_Struct || sc.TokenType == TK_Const || sc.TokenType == TK_Native) { - int includefile = Wads.GetLumpFile(Wads.CheckNumForFullName(sc.String, true)); - if (includefile != 0) + if (sc.CheckToken(TK_Identifier)) { - I_FatalError("File %s is overriding core lump %s.", - Wads.GetWadFullName(includefile), sc.String); + // This looks like an actual definition file and not a file list. + ParseSingleFile(nullptr, lumpnum, parser, state); + parsed = true; } } + } + if (!parsed) + { + sc.RestorePos(saved); + // parse all files from this list in one go. + while (sc.GetString()) + { + FixPathSeperator(sc.String); + if (Wads.GetLumpFile(sc.LumpNum) == 0) + { + int includefile = Wads.GetLumpFile(Wads.CheckNumForFullName(sc.String, true)); + if (includefile != 0) + { + I_FatalError("File %s is overriding core lump %s.", + Wads.GetWadFullName(includefile), sc.String); + } + } - ParseSingleFile(sc.String, parser, state); + ParseSingleFile(sc.String, 0, parser, state); + } } value.Int = -1;