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..787d035 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, @@ -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