"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/extras/json/theme2json.lua" (12 May 2020, 1670 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "theme2json.lua": 3.53_vs_3.54.

    1 #!/bin/lua
    2 
    3 -- This script converts a highlight theme to a JSON dataset
    4 
    5 function bool2str(b)
    6   if not b then return "false" end
    7   return "true"
    8 end
    9 
   10 function printAttributes(e, isLast)
   11     retVal =  [[{ "Colour": "]]..e.Colour..[[", "Bold": ]]..bool2str(e.Bold)..[[, "Italic": ]]..bool2str(e.Italic)..[[, "Underline": ]]..bool2str(e.Underline)
   12     if isLast then
   13         retVal = retVal .." }\n"
   14     else
   15         retVal = retVal .." },\n"
   16     end
   17     return retVal
   18 end
   19 
   20 function printKeywords()
   21     retVal="\n"
   22     for k, v in pairs(Keywords) do
   23         retVal = retVal.."        "..printAttributes(v, k==#Keywords)
   24     end
   25     return retVal
   26 end
   27 
   28 function theme2json()
   29     dofile (arg[1])
   30     print (
   31 [[{
   32     "Description"   : "]]..Description..[[",
   33     "Default"       : ]]..printAttributes(Default)..[[
   34     "Canvas"        : ]]..printAttributes(Canvas)..[[
   35     "Number"        : ]]..printAttributes(Number)..[[
   36     "Escape"        : ]]..printAttributes(Escape)..[[
   37     "String"        : ]]..printAttributes(String)..[[
   38     "StringPreProc" : ]]..printAttributes(StringPreProc)..[[
   39     "BlockComment"  : ]]..printAttributes(BlockComment)..[[
   40     "LineComment"   : ]]..printAttributes(LineComment)..[[
   41     "PreProcessor"  : ]]..printAttributes(PreProcessor)..[[
   42     "LineNum"       : ]]..printAttributes(LineNum)..[[
   43     "Operator"      : ]]..printAttributes(Operator)..[[
   44     "Interpolation" : ]]..printAttributes(Interpolation)..[[
   45     "Keywords": []]..printKeywords()..[[
   46     ]
   47 }]])
   48 end
   49 
   50 if #arg < 1 then
   51   print ("Invoke this script with a theme file as argument")
   52 else
   53     if not pcall(theme2json) then
   54         print ("Script not existing or invalid")
   55     end
   56 end
   57