diff options
author | Liqube <git@liqube.com> | 2020-05-18 17:47:45 +0200 |
---|---|---|
committer | Liqube <git@liqube.com> | 2020-05-18 17:47:45 +0200 |
commit | 705a030527c147cfc31bdd9351e0b7194dcd2b6f (patch) | |
tree | 9e3718c133414d04d4a388865587a57163deb73b /plugins/language_batch.lua | |
parent | 19d01aae13b1adbc4026817af97eb26a7f4a45d7 (diff) | |
download | lite-xl-plugins-705a030527c147cfc31bdd9351e0b7194dcd2b6f.tar.gz lite-xl-plugins-705a030527c147cfc31bdd9351e0b7194dcd2b6f.zip |
handle lower and upper symbols add symbols fix labels
Diffstat (limited to 'plugins/language_batch.lua')
-rw-r--r-- | plugins/language_batch.lua | 106 |
1 files changed, 43 insertions, 63 deletions
diff --git a/plugins/language_batch.lua b/plugins/language_batch.lua index fe1f28e..1cc511f 100644 --- a/plugins/language_batch.lua +++ b/plugins/language_batch.lua @@ -1,6 +1,44 @@ local syntax = require "core.syntax" --- liqube sat may 16, 2020 +-- batch syntax for lite <liqube> + +-- windows batch files use caseless matching for symbols +local symtable = { + ["keyword"] = { + "if", "else", "elsif", "not", "for", "do", "in", + "equ", "neq", "lss", "leq", "gtr", "geq", -- == != < <= > >= + "nul", "con", "prn", "prn", "lpt1", "com1", "com2", "com3", "com4", + "exist", "defined", + "errorlevel", "cmdextversion", + "goto", "call", "verify", + }, + ["function"] = { + "set", "setlocal", "endlocal", "enabledelayedexpansion", + "echo", "type", + "cd", "chdir", + "md", "mkdir", + "pause", "choice", "exit", + "del", "rd", "rmdir", + "copy", "xcopy", + "move", "ren", + "find", "findstr", + "sort", "shift", "attrib", + "cmd", "command", + "forfiles", + }, +} +-- prepare a mixed symbol list digestable by lite +local function prepare_symbols(symtable) + local symbols = { } + for symtype, symlist in pairs(symtable) do + for _, symname in ipairs(symlist) do + symbols[symname:lower()] = symtype + symbols[symname:upper()] = symtype + end + end + return symbols +end + syntax.add { files = { "%.bat$", "%.cmd$" }, comment = "rem", @@ -9,73 +47,15 @@ syntax.add { { pattern = "@echo on\n", type = "keyword" }, { pattern = "rem.-\n", type = "comment" }, -- rem comment line, rem, rem. { pattern = "REM.-\n", type = "comment" }, + { pattern = "%s*:[%w%-]+", type = "symbol" }, -- :labels { pattern = "%:%:.-\n", type = "comment" }, -- :: comment line { pattern = "%%%w+%%", type = "symbol" }, -- %variable% { pattern = "%%%%?~?[%w:]+", type = "symbol" }, -- %1, %~dpn1, %~1:2, %%i, %%~i - { pattern = "[!=()%>&%^/\\]", type = "operator" }, -- operators + { pattern = "[!=()%>&%^/\\@]", type = "operator" }, -- operators { pattern = "-?%.?%d+f?", type = "number" }, -- integer numbers { pattern = { '"', '"', '\\' }, type = "string" }, -- "strings" { pattern = "[%a_][%w_]*", type = "normal" }, - { pattern = ":eof", type = "keyword" }, -- todo: end processing here (lite cannot do that yet) - { pattern = "%s*:%w+", type = "symbol" }, -- :labels - }, - -- todo: caseless matching (lite cannot do that yet) - symbols = { - ["if"] = "keyword", - ["else"] = "keyword", - ["elsif"] = "keyword", - ["not"] = "keyword", - ["for"] = "keyword", - ["do"] = "keyword", - ["exist"] = "keyword", - ["in"] = "keyword", - ["equ"] = "keyword", -- == - ["neq"] = "keyword", -- != - ["lss"] = "keyword", -- < - ["leq"] = "keyword", -- <= - ["gtr"] = "keyword", -- > - ["geq"] = "keyword", -- >= - ["nul"] = "keyword", - ["con"] = "keyword", - ["prn"] = "keyword", - ["prn"] = "keyword", - ["lpt1"] = "keyword", - ["com1"] = "keyword", - ["com2"] = "keyword", - ["com3"] = "keyword", - ["com4"] = "keyword", - ["errorlevel"] = "keyword", - ["defined"] = "keyword", - ["cmdextversion"] = "keyword", - ["goto"] = "keyword", - ["call"] = "keyword", - ["verify"] = "keyword", - ["setlocal"] = "function", - ["endlocal"] = "function", - ["enabledelayedexpansion"] = "function", - ["set"] = "function", - ["echo"] = "function", - ["rd"] = "function", - ["xcopy"] = "function", - ["del"] = "function", - ["ren"] = "function", - ["rmdir"] = "function", - ["move"] = "function", - ["copy"] = "function", - ["find"] = "function", - ["exit"] = "function", - ["pause"] = "function", - ["choice"] = "function", - ["command"] = "function", - ["cmd"] = "function", - ["shift"] = "function", - ["attrib"] = "function", - ["type"] = "function", - ["sort"] = "function", - ["cd"] = "function", - ["chdir"] = "function", - ["md"] = "function", - ["mkdir"] = "function", - ["forfiles"] = "function", + { pattern = ":eof", type = "keyword" }, -- NOTE: end processing here once possible in lite }, + symbols = prepare_symbols(symtable), } |