Skip to content

Commit 81b7aa5

Browse files
authored
Add syntax highlighting to structs to be like other types. (#70)
* 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; * Removed space I added on accident.
1 parent 13da808 commit 81b7aa5

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lua/wire/client/hlzasm/hc_compiler.lua

+10
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ function HCOMP:StartCompile(sourceCode,fileName,writeByteCallback,writeByteCalle
196196
self.WriteByteCallback = writeByteCallback
197197
self.WriteByteCaller = writeByteCaller
198198

199+
-- Refresh the keywords table.
200+
local keywordsTable = WireTextEditor.Modes.ZCPU.keywordsTable
201+
local keywordsTableOriginal = WireTextEditor.Modes.ZCPU.keywordsTableOriginal
202+
203+
for k,v in pairs(keywordsTable) do
204+
if keywordsTableOriginal[k] == nil then
205+
keywordsTable[k] = nil
206+
end
207+
end
208+
199209
-- Set the working directory
200210
self.FileName = string.sub(fileName,string.find(fileName,"\\$") or 1)
201211
if string.GetPathFromFilename then

lua/wire/client/hlzasm/hc_syntax.lua

+1
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ function HCOMP:DefineVariable(isFunctionParam,isForwardDecl,isRegisterDecl,isStr
461461
varType = self.TokenData
462462
varSize = 0 -- Depends on pointer level
463463
isStruct = true
464+
WireTextEditor.Modes.ZCPU.keywordsTable[string.upper(varType)] = true -- Add the new struct to the keywords table.
464465
else -- Define variable
465466
self:ExpectToken(TOKEN.TYPE)
466467
varType = self.TokenData

lua/wire/client/text_editor/modes/zcpu.lua

+12-2
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,16 @@ local keywordsList = {
9191
"INT","FLOAT","CHAR","VOID","PRESERVE","ZAP","STRUCT","VECTOR"
9292
}
9393

94-
local keywordsTable = {}
94+
EDITOR.keywordsTable = {}
95+
local keywordsTable = EDITOR.keywordsTable
96+
9597
for k,v in pairs(keywordsList) do
9698
keywordsTable[v] = true
9799
end
98100

101+
-- For checking the keywords to remove structs in the editor.
102+
EDITOR.keywordsTableOriginal = table.Copy(keywordsTable)
103+
99104
-- Build lookup table for registers
100105
local registersTable = {
101106
EAX = true,EBX = true,ECX = true,EDX = true,ESI = true,EDI = true,
@@ -202,6 +207,9 @@ function EDITOR:SyntaxColorLine(row)
202207

203208
local isGpu = self:GetParent().EditorType == "GPU"
204209

210+
-- Remember the last token to prevent structs from being highlighted.
211+
local previousToken = ""
212+
205213
while self.character do
206214
local tokenname = ""
207215
self.tokendata = ""
@@ -217,13 +225,15 @@ function EDITOR:SyntaxColorLine(row)
217225
tokenname = "opcode"
218226
elseif registersTable[sstr] then
219227
tokenname = "register"
220-
elseif keywordsTable[sstr] then
228+
elseif keywordsTable[sstr] and (previousToken ~= "STRUCT") then -- Default to number/normal if it's declaring a struct.
221229
tokenname = "keyword"
222230
elseif tonumber(self.tokendata) then
223231
tokenname = "number"
224232
else
225233
tokenname = "normal"
226234
end
235+
236+
previousToken = sstr
227237
elseif (self.character == "'") or (self.character == "\"") then
228238
tokenname = "string"
229239
local delimiter = self.character

0 commit comments

Comments
 (0)