From 00c198ac29038c32eb7bdfd04f1afeed9fcf5bc4 Mon Sep 17 00:00:00 2001 From: WallopingEwe <53689141+WallopingEwe@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:05:02 -0600 Subject: [PATCH 1/2] Add syntax highlighting to structs to be like other types. The code looks more unified and easier to look at instead of situations like below. void function(orange, orange, yellow, orange) or (orange) char = "string"; (yellow) struct; (orange) float = 5; --- lua/wire/client/hlzasm/hc_compiler.lua | 10 ++++++++++ lua/wire/client/hlzasm/hc_syntax.lua | 1 + lua/wire/client/text_editor/modes/zcpu.lua | 16 +++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lua/wire/client/hlzasm/hc_compiler.lua b/lua/wire/client/hlzasm/hc_compiler.lua index 8499140..ce457bb 100644 --- a/lua/wire/client/hlzasm/hc_compiler.lua +++ b/lua/wire/client/hlzasm/hc_compiler.lua @@ -196,6 +196,16 @@ function HCOMP:StartCompile(sourceCode,fileName,writeByteCallback,writeByteCalle self.WriteByteCallback = writeByteCallback self.WriteByteCaller = writeByteCaller + -- Refresh the keywords table. + local keywordsTable = WireTextEditor.Modes.ZCPU.keywordsTable + local keywordsTableOriginal = WireTextEditor.Modes.ZCPU.keywordsTableOriginal + + for k,v in pairs(keywordsTable) do + if keywordsTableOriginal[k] == nil then + keywordsTable[k] = nil + end + end + -- Set the working directory self.FileName = string.sub(fileName,string.find(fileName,"\\$") or 1) if string.GetPathFromFilename then diff --git a/lua/wire/client/hlzasm/hc_syntax.lua b/lua/wire/client/hlzasm/hc_syntax.lua index 7bac93a..e558609 100644 --- a/lua/wire/client/hlzasm/hc_syntax.lua +++ b/lua/wire/client/hlzasm/hc_syntax.lua @@ -461,6 +461,7 @@ function HCOMP:DefineVariable(isFunctionParam,isForwardDecl,isRegisterDecl,isStr varType = self.TokenData varSize = 0 -- Depends on pointer level isStruct = true + WireTextEditor.Modes.ZCPU.keywordsTable[string.upper(varType)] = true -- Add the new struct to the keywords table. else -- Define variable self:ExpectToken(TOKEN.TYPE) varType = self.TokenData diff --git a/lua/wire/client/text_editor/modes/zcpu.lua b/lua/wire/client/text_editor/modes/zcpu.lua index 168e54f..ee67f9e 100644 --- a/lua/wire/client/text_editor/modes/zcpu.lua +++ b/lua/wire/client/text_editor/modes/zcpu.lua @@ -91,11 +91,16 @@ local keywordsList = { "INT","FLOAT","CHAR","VOID","PRESERVE","ZAP","STRUCT","VECTOR" } -local keywordsTable = {} +EDITOR.keywordsTable = {} +local keywordsTable = EDITOR.keywordsTable + for k,v in pairs(keywordsList) do keywordsTable[v] = true end +-- For checking the keywords to remove structs in the editor. +EDITOR.keywordsTableOriginal = table.Copy(keywordsTable) + -- Build lookup table for registers local registersTable = { EAX = true,EBX = true,ECX = true,EDX = true,ESI = true,EDI = true, @@ -194,7 +199,7 @@ function EDITOR:SyntaxColorLine(row) if self:NextPattern(".-%*/") then self.blockcomment = nil else - self:NextPattern(".*") + self:NextPattern(".*") end cols[#cols + 1] = {self.tokendata, colors["comment"]} @@ -202,6 +207,9 @@ function EDITOR:SyntaxColorLine(row) local isGpu = self:GetParent().EditorType == "GPU" + -- Remember the last token to prevent structs from being highlighted. + local previousToken = "" + while self.character do local tokenname = "" self.tokendata = "" @@ -217,13 +225,15 @@ function EDITOR:SyntaxColorLine(row) tokenname = "opcode" elseif registersTable[sstr] then tokenname = "register" - elseif keywordsTable[sstr] then + elseif keywordsTable[sstr] and (previousToken ~= "STRUCT") then -- Default to number/normal if it's declaring a struct. tokenname = "keyword" elseif tonumber(self.tokendata) then tokenname = "number" else tokenname = "normal" end + + previousToken = sstr elseif (self.character == "'") or (self.character == "\"") then tokenname = "string" local delimiter = self.character From 91057088f802ec4ce9aa1b3aa712e20b43d9ca44 Mon Sep 17 00:00:00 2001 From: WallopingEwe <53689141+WallopingEwe@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:34:33 -0600 Subject: [PATCH 2/2] Removed space I added on accident. --- lua/wire/client/text_editor/modes/zcpu.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wire/client/text_editor/modes/zcpu.lua b/lua/wire/client/text_editor/modes/zcpu.lua index ee67f9e..787d035 100644 --- a/lua/wire/client/text_editor/modes/zcpu.lua +++ b/lua/wire/client/text_editor/modes/zcpu.lua @@ -199,7 +199,7 @@ function EDITOR:SyntaxColorLine(row) if self:NextPattern(".-%*/") then self.blockcomment = nil else - self:NextPattern(".*") + self:NextPattern(".*") end cols[#cols + 1] = {self.tokendata, colors["comment"]}