aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_batch.lua
blob: 29de0febda0657eb7f24ba5328898733620196a9 (plain)
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
58
59
60
61
62
-- lite-xl 1.16
local syntax = require "core.syntax"

-- 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
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",
  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 = "%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 = "-?%.?%d+f?",                   type = "number"   },    -- integer numbers
    { pattern = { '"', '"', '\\' },             type = "string"   },    -- "strings"
    { pattern = "[%a_][%w_]*",                  type = "normal"   },
    { pattern = ":eof",                         type = "keyword"  },    -- not quite as intended, but ok for now
  },
  symbols = prepare_symbols(symtable),
}