From 7f2f51d48d4fab81de01e2de4db3f264993dcaff Mon Sep 17 00:00:00 2001 From: ZZYZX <zzyzx@virtual> Date: Thu, 9 Feb 2017 02:26:25 +0200 Subject: [PATCH] Added: primitive support for ZScript in the script editor (all classes in the current file are listed) --- Build/Scripting/ZDoom_ZSCRIPT.cfg | 25 ++++++++++ Source/Core/Builder.csproj | 2 + Source/Core/Config/ScriptConfiguration.cs | 6 +-- Source/Core/Properties/AssemblyInfo.cs | 4 +- .../Core/ZDoom/Scripting/DecorateParserSE.cs | 6 +-- .../ZDoom/Scripting/ScriptTypeParserSE.cs | 49 ++++++++++++++++++- .../BuilderModes/Properties/AssemblyInfo.cs | 2 +- 7 files changed, 83 insertions(+), 11 deletions(-) create mode 100755 Build/Scripting/ZDoom_ZSCRIPT.cfg diff --git a/Build/Scripting/ZDoom_ZSCRIPT.cfg b/Build/Scripting/ZDoom_ZSCRIPT.cfg new file mode 100755 index 000000000..d7dd85890 --- /dev/null +++ b/Build/Scripting/ZDoom_ZSCRIPT.cfg @@ -0,0 +1,25 @@ +/*******************************************************************\ + GZDoom Builder Script highlighting definitions for ZSCRIPT +\*******************************************************************/ + +// Editor settings +description = "ZDoom ZSCRIPT"; +codepage = 0; +extensions = "txt"; +casesensitive = false; +terminator = ";"; +insertcase = 1; // 0=Normal, 1=Lowercase, 2=Uppercase +lexer = 35; // CPP-style, case-insensitive +keywordhelp = "http://zdoom.org/wiki/ZScript"; +scripttype = "ZSCRIPT"; + +// todo +keywords +{ + +} + +constants +{ + +} \ No newline at end of file diff --git a/Source/Core/Builder.csproj b/Source/Core/Builder.csproj index 113306368..9ad4c5a8f 100644 --- a/Source/Core/Builder.csproj +++ b/Source/Core/Builder.csproj @@ -141,6 +141,7 @@ <Compile Include="Data\FileImage.cs" /> <Compile Include="Data\FlatImage.cs" /> <Compile Include="Data\ImageLoadState.cs" /> + <Compile Include="Data\Scripting\ZScriptScriptHandler.cs" /> <Compile Include="Data\UnknownImage.cs" /> <Compile Include="Data\PatchNames.cs" /> <Compile Include="Data\PK3Reader.cs" /> @@ -523,6 +524,7 @@ <Compile Include="ZDoom\DecorateActorStructure.cs" /> <Compile Include="ZDoom\DecorateStateGoto.cs" /> <Compile Include="ZDoom\DecorateStateStructure.cs" /> + <Compile Include="ZDoom\Scripting\ZScriptParserSE.cs" /> <Compile Include="ZDoom\ZScriptActorStructure.cs" /> <Compile Include="ZDoom\ZScriptParser.cs" /> <Compile Include="ZDoom\ZScriptStateGoto.cs" /> diff --git a/Source/Core/Config/ScriptConfiguration.cs b/Source/Core/Config/ScriptConfiguration.cs index abdd56592..765413752 100755 --- a/Source/Core/Config/ScriptConfiguration.cs +++ b/Source/Core/Config/ScriptConfiguration.cs @@ -212,7 +212,7 @@ namespace CodeImp.DoomBuilder.Config terminator = cfg.ReadSetting("terminator", ""); extrawordchars = cfg.ReadSetting("extrawordchars", ""); //mxd - //mxd. Get script type... + //mxd. Get script type... string scripttypestr = cfg.ReadSetting("scripttype", string.Empty); if(!string.IsNullOrEmpty(scripttypestr)) { @@ -233,8 +233,8 @@ namespace CodeImp.DoomBuilder.Config scripttype = ScriptType.UNKNOWN; } - //mxd. Make braces array - if(!string.IsNullOrEmpty(functionopen)) braces.Add(functionopen[0]); + //mxd. Make braces array + if (!string.IsNullOrEmpty(functionopen)) braces.Add(functionopen[0]); if(!string.IsNullOrEmpty(functionclose)) braces.Add(functionclose[0]); if(!string.IsNullOrEmpty(codeblockopen)) braces.Add(codeblockopen[0]); if(!string.IsNullOrEmpty(codeblockclose)) braces.Add(codeblockclose[0]); diff --git a/Source/Core/Properties/AssemblyInfo.cs b/Source/Core/Properties/AssemblyInfo.cs index e60d5c0e9..92ffe2092 100755 --- a/Source/Core/Properties/AssemblyInfo.cs +++ b/Source/Core/Properties/AssemblyInfo.cs @@ -30,6 +30,6 @@ using CodeImp.DoomBuilder; // Build Number // Revision // -[assembly: AssemblyVersion("2.3.0.2872")] +[assembly: AssemblyVersion("2.3.0.2873")] [assembly: NeutralResourcesLanguageAttribute("en")] -[assembly: AssemblyHash("0d43a7b")] +[assembly: AssemblyHash("1382d14")] diff --git a/Source/Core/ZDoom/Scripting/DecorateParserSE.cs b/Source/Core/ZDoom/Scripting/DecorateParserSE.cs index 7d4df6aa9..c075b2def 100755 --- a/Source/Core/ZDoom/Scripting/DecorateParserSE.cs +++ b/Source/Core/ZDoom/Scripting/DecorateParserSE.cs @@ -34,13 +34,13 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting // Continue until at the end of the stream while(SkipWhitespace(true)) { - string token = ReadToken(); + int startpos = (int)datastream.Position; + string token = ReadToken(); if(string.IsNullOrEmpty(token) || token.ToUpperInvariant() != "ACTOR") continue; SkipWhitespace(true); - int startpos = (int)datastream.Position; - List<string> definition = new List<string>(); + definition.Add(token); // actor ... ..., not just class name do { diff --git a/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs b/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs index 48d7299b9..a84cf3572 100755 --- a/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs +++ b/Source/Core/ZDoom/Scripting/ScriptTypeParserSE.cs @@ -35,6 +35,7 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting while(SkipWhitespace(true)) { string token = ReadToken(); + long cpos = datastream.Position; if(!string.IsNullOrEmpty(token)) { @@ -70,7 +71,7 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting } } - else if(token == "ACTOR") + else if(token == "ACTOR") // [ZZ] note: by the looks of it, this doesn't handle the case when we write actor with DoomEdNum. { SkipWhitespace(true); ReadToken(); //should be actor name @@ -78,7 +79,8 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting SkipWhitespace(true); token = ReadToken(); - if(token == ":" || token == "{" || token == "REPLACES") + // [ZZ] note: original code compared token to REPLACES without doing ToUpper + if(token == ":" || token == "{" || (token != null && token.ToUpperInvariant() == "REPLACES")) { scripttype = ScriptType.DECORATE; return true; @@ -87,13 +89,56 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting SkipWhitespace(true); token = ReadToken(); //should be actor name + // [ZZ] + if (token != "{") // actor bla : bla2 10666 { + { + SkipWhitespace(true); + token = ReadToken(); + } + if(token == "{") { scripttype = ScriptType.DECORATE; return true; } } + else if(token == "CLASS" || token == "STRUCT" || token == "ENUM" || token == "EXTEND") + { + if (token == "EXTEND") + { + SkipWhitespace(true); + token = ReadToken(); + if (!string.IsNullOrEmpty(token)) + token = token.ToUpperInvariant(); + } + + string otoken = token; // original token + + SkipWhitespace(true); + ReadToken(); //should be actor name + + SkipWhitespace(true); + token = ReadToken(); + + if ((otoken != "ENUM" && token == ":") || token == "{" || (otoken == "CLASS" && (token != null && token.ToUpperInvariant() == "REPLACES"))) + { + scripttype = ScriptType.ZSCRIPT; + return true; + } + + SkipWhitespace(true); + token = ReadToken(); //should be actor name + + if (token == "{") + { + scripttype = ScriptType.ZSCRIPT; + return true; + } + return true; + } } + + datastream.Position = cpos; // [ZZ] read next token, not whatever is left after possibly unsuccessful parsing. } return false; diff --git a/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs b/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs index eb701cab3..024f00a33 100755 --- a/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs +++ b/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Resources; // Build Number // Revision // -[assembly: AssemblyVersion("2.3.0.2872")] +[assembly: AssemblyVersion("2.3.0.2873")] [assembly: NeutralResourcesLanguageAttribute("en")] -- GitLab