So im trying to make syntax highlighting for my programming language (yes im making a programming language in roblox studio lol)
Ive been trying to figure out why this is happening for a while,
As you can see the syntax highlighting works correctly on words
But on every symbol ive tried it just does nothing at all, I know this is a gsub issue most likely, but does anyone know why this is happening?
Code:
local keywords = {
["declare"] = "135,206,250",
["yell"] = "135,206,250",
["+"] = "255,140,0",
["="] = "255,0,0",
["["] = "75,0,130",
["]"] = "75,0,130",
["("] = "238,130,238",
[")"] = "238,130,238",
[","] = "255,215,0",
["-"] = "255,140,0",
["*"] = "255,140,0",
["/"] = "255,140,0",
["Random"] = "0,255,255",
["true"] = "255,215,0",
["false"] = "255,215,0",
}
local function insertHighlights(txt)
txt = txt:gsub("<", "<"):gsub(">", ">")
txt = txt:gsub("</font>", ""):gsub("<font.->", "")
txt = " " .. txt .. " "
for i, v in pairs(keywords) do
-- Escape patterns and ensure only whole keywords are matched
local pattern = "%f[%w_]" .. i:gsub("%W", "%%%1") .. "%f[%W_]"
txt = txt:gsub(pattern, function(x)
return '<font color="rgb(' .. v .. ')">' .. x .. '</font>'
end)
end
txt = txt:gsub("%%SLASH%%", "/")
return txt:sub(2, #txt - 1)
end
(and yes theres more syntax in the language this is just what is being effected mainly)