File: theme2json.lua

package info (click to toggle)
highlight 4.10-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,556 kB
  • sloc: cpp: 27,579; makefile: 411; sh: 341; ansic: 264; php: 236; python: 217; ruby: 132; perl: 61; tcl: 1
file content (57 lines) | stat: -rw-r--r-- 1,670 bytes parent folder | download | duplicates (3)
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