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
|
#!/bin/lua
-- This script converts a highlight theme to a JSON dataset
function bool2str(b)
if not b then return "false" end
return "true"
end
function printAttributes(e, isLast)
retVal = [[{ "Colour": "]]..e.Colour..[[", "Bold": ]]..bool2str(e.Bold)..[[, "Italic": ]]..bool2str(e.Italic)..[[, "Underline": ]]..bool2str(e.Underline)
if isLast then
retVal = retVal .." }\n"
else
retVal = retVal .." },\n"
end
return retVal
end
function printKeywords()
retVal="\n"
for k, v in pairs(Keywords) do
retVal = retVal.." "..printAttributes(v, k==#Keywords)
end
return retVal
end
function theme2json()
dofile (arg[1])
print (
[[{
"Description" : "]]..Description..[[",
"Default" : ]]..printAttributes(Default)..[[
"Canvas" : ]]..printAttributes(Canvas)..[[
"Number" : ]]..printAttributes(Number)..[[
"Escape" : ]]..printAttributes(Escape)..[[
"String" : ]]..printAttributes(String)..[[
"StringPreProc" : ]]..printAttributes(StringPreProc)..[[
"BlockComment" : ]]..printAttributes(BlockComment)..[[
"LineComment" : ]]..printAttributes(LineComment)..[[
"PreProcessor" : ]]..printAttributes(PreProcessor)..[[
"LineNum" : ]]..printAttributes(LineNum)..[[
"Operator" : ]]..printAttributes(Operator)..[[
"Interpolation" : ]]..printAttributes(Interpolation)..[[
"Keywords": []]..printKeywords()..[[
]
}]])
end
if #arg < 1 then
print ("Invoke this script with a theme file as argument")
else
if not pcall(theme2json) then
print ("Script not existing or invalid")
end
end
|