Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make syntax highlighting?

Hello! I'm making a programming language in lua, i searched for this so i can make my own syntax highlighting, but i didn't find anything. Is there any article or doc that talks about this? Since roblox studio does that and lua learning has that implemented too.

Help is appreciated!

5 comments

0

Syntax highlighting inside of Roblox TextLables or on a website?

0

TextLabels

0

Or text boxes, i know i can use multiple labels but it would cause lag

0

alright

1 answer

So, to make Lua Syntax is kinda easy. You need to use gsub and string patterns to make syntax.

Keywords:


local str = "script."
local Ingore =
      {
            ["="] = true,
            ["."] = true,
            [","] = true,
            ["("] = true,
            [")"] = true,
            ["["] = true,
            ["]"] = true,
            ["{"] = true,
            ["}"] = true,
            [":"] = true,
            ["*"] = true,
            ["/"] = true,
            ["+"] = true,
            ["-"] = true,
            ["%"] = true,
            [";"] = true,
            ["~"] = true
      }
local highlight = ""
str = string.gsub(str,'\46',function(c)
      if Ingore[c] then
            return " "
      else
            return c
      end
end)
highlight = string.gsub(str,'%\83+',function(c)
      if c == "script" then
            return "script"
      else
            return (' '):rep(#c)
      end
end)
print(highlight)

String:

local str = '"fisi"\n"s"'
local boolean = false
local highlight = ""
str:gsub('\46',function(c)
	if c == '"' and boolean == false then
		boolean = true
	elseif boolean == true and c == '"' then
		boolean = false
	end
	if boolean == true and  c ~= '"' then
	highlight = highlight .. c
	end
	if boolean == false and c == '"' then
	elseif c == "\n" and boolean == false then
		highlight = highlight .. "\n"
	elseif c == "\t" and boolean == false  then
		highlight = highlight .. "\t"
	elseif boolean == false  then
		highlight = highlight .. " "
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.