diff options
| author | orbitalquark <70453897+orbitalquark@users.noreply.github.com> | 2024-09-18 14:30:49 -0400 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2025-01-04 12:29:07 -0700 |
| commit | c1f4d3f68787fa2ae964c468d28a84df37319b28 (patch) | |
| tree | dcd62bd74f8f9fd786cba6a0c248fb388d5244a8 /lua/lexers/bash.lua | |
| parent | cc18cea14d1f836abcebb84a96f5029431474255 (diff) | |
| download | vis-c1f4d3f68787fa2ae964c468d28a84df37319b28.tar.gz vis-c1f4d3f68787fa2ae964c468d28a84df37319b28.tar.xz | |
lexers: switch to tabs for indentation
Diffstat (limited to 'lua/lexers/bash.lua')
| -rw-r--r-- | lua/lexers/bash.lua | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/lua/lexers/bash.lua b/lua/lexers/bash.lua index 2212ea6..e7da54b 100644 --- a/lua/lexers/bash.lua +++ b/lua/lexers/bash.lua @@ -11,7 +11,7 @@ lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD))) -- Builtins. lex:add_rule('builtin', - lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN)) * -P('=')) + lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN)) * -P('=')) -- Variable assignment. local assign = lex:tag(lexer.VARIABLE, lexer.word) * lex:tag(lexer.OPERATOR, '=') @@ -24,17 +24,17 @@ lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word)) local sq_str = -B('\\') * lexer.range("'", false, false) local dq_str = -B('\\') * lexer.range('"') local heredoc = '<<' * P(function(input, index) - local _, e, minus, _, delimiter = input:find('^(%-?)%s*(["\']?)([%w_]+)%2[^\n]*[\n\r\f;]+', index) - if not delimiter then return nil end - -- If the starting delimiter of a here-doc begins with "-", then spaces are allowed to come - -- before the closing delimiter. - _, e = - input:find((minus == '' and '[\n\r\f]+' or '[\n\r\f]+[ \t]*') .. delimiter .. '%f[^%w_]', e) - return e and e + 1 or #input + 1 + local _, e, minus, _, delimiter = input:find('^(%-?)%s*(["\']?)([%w_]+)%2[^\n]*[\n\r\f;]+', index) + if not delimiter then return nil end + -- If the starting delimiter of a here-doc begins with "-", then spaces are allowed to come + -- before the closing delimiter. + _, e = + input:find((minus == '' and '[\n\r\f]+' or '[\n\r\f]+[ \t]*') .. delimiter .. '%f[^%w_]', e) + return e and e + 1 or #input + 1 end) local ex_str = -B('\\') * '`' lex:add_rule('string', - lex:tag(lexer.STRING, sq_str + dq_str + heredoc) + lex:tag(lexer.EMBEDDED, ex_str)) + lex:tag(lexer.STRING, sq_str + dq_str + heredoc) + lex:tag(lexer.EMBEDDED, ex_str)) -- Comments. lex:add_rule('comment', lex:tag(lexer.COMMENT, -B('\\') * lexer.to_eol('#'))) @@ -44,9 +44,9 @@ lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number)) -- Variables. local builtin_var = lex:tag(lexer.OPERATOR, '$' * P('{')^-1) * lex:tag(lexer.VARIABLE_BUILTIN, - lex:word_match(lexer.VARIABLE_BUILTIN) + S('!#?*@$-') * -lexer.alnum + lexer.digit^1) + lex:word_match(lexer.VARIABLE_BUILTIN) + S('!#?*@$-') * -lexer.alnum + lexer.digit^1) local var_ref = lex:tag(lexer.OPERATOR, '$' * ('{' * S('!#')^-1)^-1) * - lex:tag(lexer.VARIABLE, lexer.word) + lex:tag(lexer.VARIABLE, lexer.word) local patt_expansion = lex:tag(lexer.DEFAULT, '/#' + '#' * P('#')^-1) lex:add_rule('variable', builtin_var + var_ref * patt_expansion^-1) @@ -54,17 +54,17 @@ lex:add_rule('variable', builtin_var + var_ref * patt_expansion^-1) local op = S('!<>&|;$()[]{}') + lpeg.B(lexer.space) * S('.:') * #lexer.space local function in_expr(constructs) - return P(function(input, index) - local line = input:sub(1, index):match('[^\r\n]*$') - for k, v in pairs(constructs) do - local s = line:find(k, 1, true) - if not s then goto continue end - local e = line:find(v, 1, true) - if not e or e < s then return true end - ::continue:: - end - return nil - end) + return P(function(input, index) + local line = input:sub(1, index):match('[^\r\n]*$') + for k, v in pairs(constructs) do + local s = line:find(k, 1, true) + if not s then goto continue end + local e = line:find(v, 1, true) + if not e or e < s then return true end + ::continue:: + end + return nil + end) end local file_op = '-' * (S('abcdefghkprstuwxGLNOS') + 'ef' + 'nt' + 'ot') @@ -74,7 +74,7 @@ local string_op = '-' * S('zn') + S('!=')^-1 * '=' + S('<>') local num_op = '-' * lexer.word_match('eq ne lt le gt ge') local in_cond_expr = in_expr{['[[ '] = ' ]]', ['[ '] = ' ]'} local conditional_op = (num_op + file_op + shell_op + var_op + string_op) * #lexer.space * - in_cond_expr + in_cond_expr local in_arith_expr = in_expr{['(('] = '))'} local arith_op = (S('+!~*/%<>=&^|?:,') + '--' + '-' * #S(' \t')) * in_arith_expr @@ -94,43 +94,43 @@ lex:add_fold_point(lexer.OPERATOR, '{', '}') -- Word lists. lex:set_word_list(lexer.KEYWORD, { - 'if', 'then', 'elif', 'else', 'fi', 'time', 'for', 'in', 'until', 'while', 'do', 'done', 'case', - 'esac', 'coproc', 'select', 'function' + 'if', 'then', 'elif', 'else', 'fi', 'time', 'for', 'in', 'until', 'while', 'do', 'done', 'case', + 'esac', 'coproc', 'select', 'function' }) lex:set_word_list(lexer.FUNCTION_BUILTIN, { - -- Shell built-ins. - 'break', 'cd', 'continue', 'eval', 'exec', 'exit', 'export', 'getopts', 'hash', 'pwd', 'readonly', - 'return', 'shift', 'test', 'times', 'trap', 'umask', 'unset', - -- Bash built-ins. - 'alias', 'bind', 'builtin', 'caller', 'command', 'declare', 'echo', 'enable', 'help', 'let', - 'local', 'logout', 'mapfile', 'printf', 'read', 'readarray', 'source', 'type', 'typeset', - 'ulimit', 'unalias', -- - 'set', 'shopt', -- shell behavior - 'dirs', 'popd', 'pushd', -- directory stack - 'bg', 'fg', 'jobs', 'kill', 'wait', 'disown', 'suspend', -- job control - 'fc', 'history' -- history + -- Shell built-ins. + 'break', 'cd', 'continue', 'eval', 'exec', 'exit', 'export', 'getopts', 'hash', 'pwd', 'readonly', + 'return', 'shift', 'test', 'times', 'trap', 'umask', 'unset', + -- Bash built-ins. + 'alias', 'bind', 'builtin', 'caller', 'command', 'declare', 'echo', 'enable', 'help', 'let', + 'local', 'logout', 'mapfile', 'printf', 'read', 'readarray', 'source', 'type', 'typeset', + 'ulimit', 'unalias', -- + 'set', 'shopt', -- shell behavior + 'dirs', 'popd', 'pushd', -- directory stack + 'bg', 'fg', 'jobs', 'kill', 'wait', 'disown', 'suspend', -- job control + 'fc', 'history' -- history }) lex:set_word_list(lexer.VARIABLE_BUILTIN, { - -- Shell built-ins. - 'CDPATH', 'HOME', 'IFS', 'MAIL', 'MAILPATH', 'OPTARG', 'OPTIND', 'PATH', 'PS1', 'PS2', - -- Bash built-ins. - 'BASH', 'BASHOPTS', 'BASHPID', 'BASH_ALIASES', 'BASH_ARGC', 'BASH_ARGV', 'BASH_ARGV0', - 'BASH_CMDS', 'BASH_COMMAND', 'BASH_COMPAT', 'BASH_ENV', 'BASH_EXECUTION_STRING', 'BASH_LINENO', - 'BASH_LOADABLES_PATH', 'BASH_REMATCH', 'BASH_SOURCE', 'BASH_SUBSHELL', 'BASH_VERSINFO', - 'BASH_VERSION', 'BASH_XTRACEFD', 'CHILD_MAX', 'COLUMNS', 'COMP_CWORD', 'COMP_LINE', 'COMP_POINT', - 'COMP_TYPE', 'COMP_KEY', 'COMP_WORDBREAKS', 'COMP_WORDS', 'COMP_REPLY', 'COPROC', 'DIRSTACK', - 'EMACS', 'ENV', 'EPOCHREALTIME', 'EPOCHSECONDS', 'EUID', 'EXECIGNORE', 'FCEDIT', 'FIGNORE', - 'FUNCNAME', 'FUNCNEST', 'GLOBIGNORE', 'GROUPS', 'histchars', 'HISTCMD', 'HISTCONTROL', 'HISTFILE', - 'HISTFILESIZE', 'HISTIGNORE', 'HISTSIZE', 'HISTTIMEFORMAT', 'HOSTFILE', 'HOSTNAME', 'HOSTTYPE', - 'IGNOREEOF', 'INPUTRC', 'INSIDE_EMACS', 'LANG', 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MESSAGES', - 'LC_NUMERIC', 'LC_TIME', 'LINENO', 'LINES', 'MACHTYPE', 'MAILCHECK', 'MAPFILE', 'OLDPWD', - 'OPTERR', 'OSTYPE', 'PIPESTATUS', 'POSIXLY_CORRECT', 'PPID', 'PROMPT_COMMAND', 'PROMPT_DIRTRIM', - 'PSO', 'PS3', 'PS4', 'PWD', 'RANDOM', 'READLINE_LINE', 'READLINE_MARK', 'READLINE_POINT', 'REPLY', - 'SECONDS', 'SHELL', 'SHELLOPTS', 'SHLVL', 'SRANDOM', 'TIMEFORMAT', 'TMOUT', 'TMPDIR', 'UID', - -- Job control. - 'auto_resume' + -- Shell built-ins. + 'CDPATH', 'HOME', 'IFS', 'MAIL', 'MAILPATH', 'OPTARG', 'OPTIND', 'PATH', 'PS1', 'PS2', + -- Bash built-ins. + 'BASH', 'BASHOPTS', 'BASHPID', 'BASH_ALIASES', 'BASH_ARGC', 'BASH_ARGV', 'BASH_ARGV0', + 'BASH_CMDS', 'BASH_COMMAND', 'BASH_COMPAT', 'BASH_ENV', 'BASH_EXECUTION_STRING', 'BASH_LINENO', + 'BASH_LOADABLES_PATH', 'BASH_REMATCH', 'BASH_SOURCE', 'BASH_SUBSHELL', 'BASH_VERSINFO', + 'BASH_VERSION', 'BASH_XTRACEFD', 'CHILD_MAX', 'COLUMNS', 'COMP_CWORD', 'COMP_LINE', 'COMP_POINT', + 'COMP_TYPE', 'COMP_KEY', 'COMP_WORDBREAKS', 'COMP_WORDS', 'COMP_REPLY', 'COPROC', 'DIRSTACK', + 'EMACS', 'ENV', 'EPOCHREALTIME', 'EPOCHSECONDS', 'EUID', 'EXECIGNORE', 'FCEDIT', 'FIGNORE', + 'FUNCNAME', 'FUNCNEST', 'GLOBIGNORE', 'GROUPS', 'histchars', 'HISTCMD', 'HISTCONTROL', 'HISTFILE', + 'HISTFILESIZE', 'HISTIGNORE', 'HISTSIZE', 'HISTTIMEFORMAT', 'HOSTFILE', 'HOSTNAME', 'HOSTTYPE', + 'IGNOREEOF', 'INPUTRC', 'INSIDE_EMACS', 'LANG', 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MESSAGES', + 'LC_NUMERIC', 'LC_TIME', 'LINENO', 'LINES', 'MACHTYPE', 'MAILCHECK', 'MAPFILE', 'OLDPWD', + 'OPTERR', 'OSTYPE', 'PIPESTATUS', 'POSIXLY_CORRECT', 'PPID', 'PROMPT_COMMAND', 'PROMPT_DIRTRIM', + 'PSO', 'PS3', 'PS4', 'PWD', 'RANDOM', 'READLINE_LINE', 'READLINE_MARK', 'READLINE_POINT', 'REPLY', + 'SECONDS', 'SHELL', 'SHELLOPTS', 'SHLVL', 'SRANDOM', 'TIMEFORMAT', 'TMOUT', 'TMPDIR', 'UID', + -- Job control. + 'auto_resume' }) lexer.property['scintillua.comment'] = '#' |
