summaryrefslogtreecommitdiff
path: root/.config/vis/lexers/execline.lua
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2024-12-27 17:25:54 -0500
committerSam Nystrom <sam@samnystrom.dev>2024-12-27 17:25:54 -0500
commitbacc2552699376770a8c87cd6d3bc71aeb1f9330 (patch)
treef1eff71196359519a3b40d87a41454cbf04b2e1d /.config/vis/lexers/execline.lua
parent390b2840178b89d84bedcbd8a392a0c567c3f457 (diff)
vis: add config
Diffstat (limited to '.config/vis/lexers/execline.lua')
-rw-r--r--.config/vis/lexers/execline.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/.config/vis/lexers/execline.lua b/.config/vis/lexers/execline.lua
new file mode 100644
index 0000000..cb79c8d
--- /dev/null
+++ b/.config/vis/lexers/execline.lua
@@ -0,0 +1,64 @@
+-- Copyright 2023 Sam Nystrom <sam@samnystrom.dev>
+-- Execline LPeg lexer.
+
+local l = require('lexer')
+local token, word_match = l.token, l.word_match
+local P, R, S = lpeg.P, lpeg.R, lpeg.S
+
+local M = {_NAME = 'execline'}
+
+-- Whitespace.
+local ws = token(l.WHITESPACE, l.space^1)
+
+-- Comments.
+local comment = token(l.COMMENT, l.starts_line(S('#')) * l.nonnewline^0)
+
+-- Strings.
+local sq_str = l.range("'")
+local dq_str = l.range('"')
+local string = token(l.STRING, sq_str + dq_str)
+
+-- Numbers.
+local dec = l.digit^1 * ('_' * l.digit^1)^0
+local oct_num = '0' * S('01234567_')^1
+local integer = S('+-')^-1 * (l.hex_num + oct_num + dec)
+local number = token(l.NUMBER, (l.float + integer))
+
+-- Keywords.
+local keyword = token(l.KEYWORD, word_match{
+ 'execlineb', 'execline-cd', 'posix-cd', 'execline-umask', 'posix-umask',
+ 'emptyenv', 'envfile', 'export', 'unexport', 'fdclose', 'fdblock', 'fdmove',
+ 'fdswap', 'fdreserve', 'redirfd', 'piperw', 'heredoc', 'wait', 'getcwd',
+ 'getpid', 'exec', 'tryexec', 'exit', 'trap', 'withstdinas',
+ 'foreground', 'background', 'case', 'if', 'ifelse', 'ifte', 'ifthenelse',
+ 'backtick', 'pipeline', 'runblock',
+ 'define', 'importas', 'elglob', 'elgetpositionals', 'multidefine',
+ 'multisubstitute',
+ 'forx', 'forstdin', 'forbacktickx', 'loopwhilex',
+ 'elgetopt', 'shift', 'dollarat',
+ 'eltest', 'homeof',
+ 'execline'
+})
+
+-- Identifiers.
+local identifier = token(l.IDENTIFIER, l.word)
+
+local variable = token(l.VARIABLE, '$' * (l.word + l.range('{}', true, true, true)))
+
+-- Operators.
+local operator = token(l.OPERATOR, S('{}'))
+
+M._rules = {
+ {'whitespace', ws},
+ {'keyword', keyword},
+ {'identifier', identifier},
+ {'string', string},
+ {'comment', comment},
+ {'number', number},
+ {'variable', variable},
+ {'operator', operator},
+}
+
+M._LEXBYLINE = true
+
+return M