pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.6k stars 519 forks source link

Custom spec error #1087

Closed LuaFan2 closed 3 years ago

LuaFan2 commented 3 years ago

Hello. I made custom interpreter for https://github.com/stevedonovan/LuaMacro (macro preprocessor for Lua) that create .lua file for files with .luam extension on save/run. But I found that syntax highlighting is gone. I tried to return it use copy of lua spec with changes in keywords:

local spec = {
  exts = {"luam"},
  lexer = wxstc.wxSTC_LEX_COFFEESCRIPT,
  apitype = "lua",
  linecomment = "--",
  sep = ".\\",

  -- borrow this logic from the Lua spec
  typeassigns = ide.specs.lua and ide.specs.lua.typeassigns,

  lexerstyleconvert = {
    text = {wxstc.wxSTC_COFFEESCRIPT_IDENTIFIER,},

    lexerdef = {wxstc.wxSTC_COFFEESCRIPT_DEFAULT,},
    comment = {wxstc.wxSTC_COFFEESCRIPT_COMMENT,
      wxstc.wxSTC_COFFEESCRIPT_COMMENTLINE,
      wxstc.wxSTC_COFFEESCRIPT_COMMENTDOC,},
    stringtxt = {wxstc.wxSTC_COFFEESCRIPT_STRING,
      wxstc.wxSTC_COFFEESCRIPT_CHARACTER,
      wxstc.wxSTC_COFFEESCRIPT_LITERALSTRING,},
    stringeol = {wxstc.wxSTC_COFFEESCRIPT_STRINGEOL,},
    preprocessor= {wxstc.wxSTC_COFFEESCRIPT_PREPROCESSOR,},
    operator = {wxstc.wxSTC_COFFEESCRIPT_OPERATOR,},
    number = {wxstc.wxSTC_COFFEESCRIPT_NUMBER,},

    keywords0 = {wxstc.wxSTC_COFFEESCRIPT_WORD,},
    keywords1 = {wxstc.wxSTC_COFFEESCRIPT_WORD2,},
    keywords2 = {wxstc.wxSTC_COFFEESCRIPT_GLOBALCLASS,},
  },

  keywords = {
    -- keywords
    [[and break do else elseif end for function goto if in local not or repeat return then until while]],

    -- constants/variables
    [[_G _VERSION _ENV false io.stderr io.stdin io.stdout nil math.huge math.pi self true package.cpath package.path]],

    -- core/global functions
    [[assert collectgarbage dofile error getfenv getmetatable ipairs load loadfile loadstring
      module next pairs pcall print rawequal rawget rawlen rawset require
      select setfenv setmetatable tonumber tostring type unpack xpcall]],

    -- library functions
    [[bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.bxor bit32.extract
      bit32.lrotate bit32.lshift bit32.replace bit32.rrotate bit32.rshift
      coroutine.create coroutine.resume coroutine.running coroutine.status coroutine.wrap coroutine.yield
      coroutine.isyieldable
      debug.debug debug.getfenv debug.gethook debug.getinfo debug.getlocal
      debug.getmetatable debug.getregistry debug.getupvalue debug.getuservalue debug.setfenv
      debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.setuservalue
      debug.traceback debug.upvalueid debug.upvaluejoin
      io.close io.flush io.input io.lines io.open io.output io.popen io.read io.tmpfile io.type io.write
      close flush lines read seek setvbuf write
      math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.cosh math.deg math.exp
      math.floor math.fmod math.frexp math.ldexp math.log math.log10 math.max math.min math.modf
      math.pow math.rad math.random math.randomseed math.sin math.sinh math.sqrt math.tan math.tanh
      math.type math.tointeger math.maxinteger math.mininteger math.ult
      os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname
      package.loadlib package.searchpath package.seeall package.config
      package.loaded package.loaders package.preload package.searchers
      string.byte string.char string.dump string.find string.format string.gmatch string.gsub string.len
      string.lower string.match string.rep string.reverse string.sub string.upper
      byte find format gmatch gsub len lower match rep reverse sub upper
      table.move, string.pack, string.unpack, string.packsize
      table.concat table.insert table.maxn table.pack table.remove table.sort table.unpack]],

      -- macroses

      [[def_ set_ do_ @include @def require_ _END_CLOSE_]]
  },
}

But with it on run I get Lua error related to macro syntax. I can't understand how to fix it and didn't find anything in the documentation that could help me

pkulchenko commented 3 years ago

@LuaFan2, where did you put this code? If you just want to enable Lua syntax highlighting for .luam files, then you can add the following to the config:

local luaspec = ide.specs.lua
luaspec.exts[#luaspec.exts+1] = "luaz"

See https://github.com/pkulchenko/ZeroBraneStudio/blob/master/cfg/user-sample.lua#L14. If you want to extend the macros, then see the next line.

For the documentation on adding/registering a spec, see this section: https://studio.zerobrane.com/doc-plugin#registering-a-specification. Let me know if this doesn't address your question.

moteus commented 3 years ago

You can checkout my custom interpreter https://github.com/moteus/zbs-package/blob/master/zbstudio/packages/ujit.lua It supports multiple lexers an run commands