-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathhighlightlua.lua
More file actions
63 lines (56 loc) · 1.94 KB
/
highlightlua.lua
File metadata and controls
63 lines (56 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- highlightlua.lua
--
-- This Script provides a simple Method for Syntax Highlighting of Lua code
local Tokenizer = require("prometheus.tokenizer");
local colors = require("colors");
local TokenKind = Tokenizer.TokenKind;
local lookupify = require("prometheus.util").lookupify;
return function(code, luaVersion)
local out = "";
local tokenizer = Tokenizer:new({
LuaVersion = luaVersion,
});
tokenizer:append(code);
local tokens = tokenizer:scanAll();
local nonColorSymbols = lookupify{
",", ";", "(", ")", "{", "}", ".", ":", "[", "]"
}
local defaultGlobals = lookupify{
"string", "table", "bit32", "bit"
}
local currentPos = 1;
for _, token in ipairs(tokens) do
if token.startPos >= currentPos then
out = out .. string.sub(code, currentPos, token.startPos);
end
if token.kind == TokenKind.Ident then
if defaultGlobals[token.source] then
out = out .. colors(token.source, "red");
else
out = out .. token.source;
end
elseif token.kind == TokenKind.Keyword then
if token.source == "nil" then
out = out .. colors(token.source, "yellow");
else
out = out .. colors(token.source, "yellow");
end
elseif token.kind == TokenKind.Symbol then
if nonColorSymbols[token.source] then
out = out .. token.source;
else
out = out .. colors(token.source, "yellow");
end
elseif token.kind == TokenKind.String then
out = out .. colors(token.source, "green")
elseif token.kind == TokenKind.Number then
out = out .. colors(token.source, "red")
else
out = out .. token.source;
end
currentPos = token.endPos + 1;
end
return out;
end