From 2a4f16cf824eabb7ee3119abc32cfc88fbf622a3 Mon Sep 17 00:00:00 2001 From: Liqube Date: Sun, 17 May 2020 22:45:25 +0200 Subject: added language syntax for windows batch files --- README.md | 1 + plugins/language_batch.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 plugins/language_batch.lua diff --git a/README.md b/README.md index f5f095f..637990e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Plugin | Description [`inanimate`](plugins/inanimate.lua?raw=1) | Disables all transition animations [`indentguide`](plugins/indentguide.lua?raw=1) | Adds indent guides *([screenshot](https://user-images.githubusercontent.com/3920290/79640716-f9860000-818a-11ea-9c3b-26d10dd0e0c0.png))* [`language_angelscript`](plugins/language_angelscript.lua?raw=1) | Syntax for the [Angelscript](https://www.angelcode.com/angelscript/) programming language +[`language_batch`](plugins/language_batch.lua?raw=1) | Syntax for Windows [Batch Files](https://en.wikipedia.org/wiki/Batch_file) [`language_cpp`](plugins/language_cpp.lua?raw=1) | Syntax for the [C++](https://isocpp.org/) programming language [`language_csharp`](plugins/language_csharp.lua?raw=1) | Syntax for the [C#](http://csharp.net) programming language [`language_fe`](plugins/language_fe.lua?raw=1) | Syntax for the [fe](https://github.com/rxi/fe) programming language diff --git a/plugins/language_batch.lua b/plugins/language_batch.lua new file mode 100644 index 0000000..958f576 --- /dev/null +++ b/plugins/language_batch.lua @@ -0,0 +1,81 @@ +local syntax = require "core.syntax" + +-- liqube sat may 16, 2020 +syntax.add { + files = { "%.bat$", "%.cmd$" }, + comment = "rem", + patterns = { + { pattern = "@echo off\n", type = "keyword" }, + { pattern = "@echo on\n", type = "keyword" }, + { pattern = "rem.-\n", type = "comment" }, -- rem comment line, rem, rem. + { pattern = "REM.-\n", type = "comment" }, + { 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 = "-?%.?%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", + }, +} -- cgit v1.2.3 From 19d01aae13b1adbc4026817af97eb26a7f4a45d7 Mon Sep 17 00:00:00 2001 From: Liqube Date: Sun, 17 May 2020 22:49:31 +0200 Subject: fixed indentation --- plugins/language_batch.lua | 138 ++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/plugins/language_batch.lua b/plugins/language_batch.lua index 958f576..fe1f28e 100644 --- a/plugins/language_batch.lua +++ b/plugins/language_batch.lua @@ -5,77 +5,77 @@ syntax.add { files = { "%.bat$", "%.cmd$" }, comment = "rem", patterns = { - { pattern = "@echo off\n", type = "keyword" }, - { pattern = "@echo on\n", type = "keyword" }, - { pattern = "rem.-\n", type = "comment" }, -- rem comment line, rem, rem. - { pattern = "REM.-\n", type = "comment" }, - { 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 = "-?%.?%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 + { pattern = "@echo off\n", type = "keyword" }, + { pattern = "@echo on\n", type = "keyword" }, + { pattern = "rem.-\n", type = "comment" }, -- rem comment line, rem, rem. + { pattern = "REM.-\n", type = "comment" }, + { 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 = "-?%.?%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", + ["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", }, } -- cgit v1.2.3 From 705a030527c147cfc31bdd9351e0b7194dcd2b6f Mon Sep 17 00:00:00 2001 From: Liqube Date: Mon, 18 May 2020 17:47:45 +0200 Subject: handle lower and upper symbols add symbols fix labels --- plugins/language_batch.lua | 106 ++++++++++++++++++--------------------------- 1 file 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 + +-- 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), } -- cgit v1.2.3 From 641f10a90122cba4397cc2e7a99cb684bde2ef24 Mon Sep 17 00:00:00 2001 From: Liqube Date: Mon, 18 May 2020 17:48:16 +0200 Subject: cleanup indentation --- plugins/language_batch.lua | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/language_batch.lua b/plugins/language_batch.lua index 1cc511f..ca063f7 100644 --- a/plugins/language_batch.lua +++ b/plugins/language_batch.lua @@ -5,26 +5,26 @@ local syntax = require "core.syntax" -- 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", + "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", + "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 @@ -33,7 +33,7 @@ local function prepare_symbols(symtable) for symtype, symlist in pairs(symtable) do for _, symname in ipairs(symlist) do symbols[symname:lower()] = symtype - symbols[symname:upper()] = symtype + symbols[symname:upper()] = symtype end end return symbols -- cgit v1.2.3 From 5affdc231f7cf34ffa1246eff502ebe6e9e1e449 Mon Sep 17 00:00:00 2001 From: Liqube Date: Mon, 18 May 2020 17:56:22 +0200 Subject: minor --- plugins/language_batch.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/language_batch.lua b/plugins/language_batch.lua index ca063f7..8caad59 100644 --- a/plugins/language_batch.lua +++ b/plugins/language_batch.lua @@ -27,7 +27,7 @@ local symtable = { "forfiles", }, } --- prepare a mixed symbol list digestable by lite +-- prepare a mixed symbol list local function prepare_symbols(symtable) local symbols = { } for symtype, symlist in pairs(symtable) do @@ -55,7 +55,7 @@ syntax.add { { pattern = "-?%.?%d+f?", type = "number" }, -- integer numbers { pattern = { '"', '"', '\\' }, type = "string" }, -- "strings" { pattern = "[%a_][%w_]*", type = "normal" }, - { pattern = ":eof", type = "keyword" }, -- NOTE: end processing here once possible in lite + { pattern = ":eof", type = "keyword" }, -- not quite as intended, but ok for now }, symbols = prepare_symbols(symtable), } -- cgit v1.2.3 From 8b1cff83b29b7448985ea75957b1320c20635762 Mon Sep 17 00:00:00 2001 From: Liqube Date: Mon, 18 May 2020 18:11:01 +0200 Subject: csv basic syntax --- plugins/language_csv.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 plugins/language_csv.lua diff --git a/plugins/language_csv.lua b/plugins/language_csv.lua new file mode 100644 index 0000000..1ffb832 --- /dev/null +++ b/plugins/language_csv.lua @@ -0,0 +1,13 @@ +local syntax = require "core.syntax" + +-- csv basic syntax for lite +syntax.add { + files = { "%.csv$" }, + patterns = { + { pattern = "-?%.?%d+f?", type = "number" }, -- numbers + { pattern = "[,;|]", type = "operator" }, -- operators + { pattern = { '"', '"', '\\' }, type = "string" }, -- strings + { pattern = { "'", "'", '\\' }, type = "string" }, -- strings + }, + symbols = { }, +} -- cgit v1.2.3 From d18469455b3969cb74a41b541745e6184cc61f15 Mon Sep 17 00:00:00 2001 From: Liqube Date: Mon, 18 May 2020 18:17:48 +0200 Subject: whoops --- plugins/language_csv.lua | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 plugins/language_csv.lua diff --git a/plugins/language_csv.lua b/plugins/language_csv.lua deleted file mode 100644 index 1ffb832..0000000 --- a/plugins/language_csv.lua +++ /dev/null @@ -1,13 +0,0 @@ -local syntax = require "core.syntax" - --- csv basic syntax for lite -syntax.add { - files = { "%.csv$" }, - patterns = { - { pattern = "-?%.?%d+f?", type = "number" }, -- numbers - { pattern = "[,;|]", type = "operator" }, -- operators - { pattern = { '"', '"', '\\' }, type = "string" }, -- strings - { pattern = { "'", "'", '\\' }, type = "string" }, -- strings - }, - symbols = { }, -} -- cgit v1.2.3