summaryrefslogtreecommitdiff
path: root/pygments/lexers/shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/lexers/shell.py')
-rw-r--r--pygments/lexers/shell.py83
1 files changed, 63 insertions, 20 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index a5933afb..31bc7e94 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -5,7 +5,7 @@
Lexers for various shells.
- :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -19,7 +19,7 @@ from pygments.util import shebang_matches
__all__ = ['BashLexer', 'BashSessionLexer', 'TcshLexer', 'BatchLexer',
- 'MSDOSSessionLexer', 'PowerShellLexer',
+ 'SlurmBashLexer', 'MSDOSSessionLexer', 'PowerShellLexer',
'PowerShellSessionLexer', 'TcshSessionLexer', 'FishShellLexer']
line_re = re.compile('.*?\n')
@@ -27,17 +27,18 @@ line_re = re.compile('.*?\n')
class BashLexer(RegexLexer):
"""
- Lexer for (ba|k|)sh shell scripts.
+ Lexer for (ba|k|z|)sh shell scripts.
.. versionadded:: 0.6
"""
name = 'Bash'
- aliases = ['bash', 'sh', 'ksh', 'shell']
+ aliases = ['bash', 'sh', 'ksh', 'zsh', 'shell']
filenames = ['*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass',
- '*.exheres-0', '*.exlib',
- '.bashrc', 'bashrc', '.bash_*', 'bash_*', 'PKGBUILD']
- mimetypes = ['application/x-sh', 'application/x-shellscript']
+ '*.exheres-0', '*.exlib', '*.zsh',
+ '.bashrc', 'bashrc', '.bash_*', 'bash_*', 'zshrc', '.zshrc',
+ 'PKGBUILD']
+ mimetypes = ['application/x-sh', 'application/x-shellscript', 'text/x-shellscript']
tokens = {
'root': [
@@ -50,7 +51,7 @@ class BashLexer(RegexLexer):
(r'\$\(\(', Keyword, 'math'),
(r'\$\(', Keyword, 'paren'),
(r'\$\{#?', String.Interpol, 'curly'),
- (r'\$[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable), # user variable
+ (r'\$[a-zA-Z_]\w*', Name.Variable), # user variable
(r'\$(?:\d+|[#$?!_*@-])', Name.Variable), # builtin
(r'\$', Text),
],
@@ -75,7 +76,7 @@ class BashLexer(RegexLexer):
(r'&&|\|\|', Operator),
],
'data': [
- (r'(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"', String.Double),
+ (r'(?s)\$?"(\\.|[^"\\$])*"', String.Double),
(r'"', String.Double, 'string'),
(r"(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
(r"(?s)'.*?'", String.Single),
@@ -125,6 +126,28 @@ class BashLexer(RegexLexer):
return 0.2
+class SlurmBashLexer(BashLexer):
+ """
+ Lexer for (ba|k|z|)sh Slurm scripts.
+
+ .. versionadded:: 2.4
+ """
+
+ name = 'Slurm'
+ aliases = ['slurm', 'sbatch']
+ filenames = ['*.sl']
+ mimetypes = []
+ EXTRA_KEYWORDS = {'srun'}
+
+ def get_tokens_unprocessed(self, text):
+ for index, token, value in BashLexer.get_tokens_unprocessed(self, text):
+ if token is Text and value in self.EXTRA_KEYWORDS:
+ yield index, Name.Builtin, value
+ elif token is Comment.Single and 'SBATCH' in value:
+ yield index, Keyword.Pseudo, value
+ else:
+ yield index, token, value
+
class ShellSessionBaseLexer(Lexer):
"""
Base lexer for simplistic shell sessions.
@@ -478,13 +501,16 @@ class BatchLexer(RegexLexer):
using(this, state='variable')), '#pop'),
(r'(exist%s)(%s%s)' % (_token_terminator, _space, _stoken),
bygroups(Keyword, using(this, state='text')), '#pop'),
- (r'(%s%s?)(==)(%s?%s)' % (_stoken, _space, _space, _stoken),
- bygroups(using(this, state='text'), Operator,
- using(this, state='text')), '#pop'),
(r'(%s%s)(%s)(%s%s)' % (_number, _space, _opword, _space, _number),
bygroups(using(this, state='arithmetic'), Operator.Word,
using(this, state='arithmetic')), '#pop'),
- (r'(%s%s)(%s)(%s%s)' % (_stoken, _space, _opword, _space, _stoken),
+ (_stoken, using(this, state='text'), ('#pop', 'if2')),
+ ],
+ 'if2': [
+ (r'(%s?)(==)(%s?%s)' % (_space, _space, _stoken),
+ bygroups(using(this, state='text'), Operator,
+ using(this, state='text')), '#pop'),
+ (r'(%s)(%s)(%s%s)' % (_space, _opword, _space, _stoken),
bygroups(using(this, state='text'), Operator.Word,
using(this, state='text')), '#pop')
],
@@ -634,13 +660,29 @@ class PowerShellLexer(RegexLexer):
'wildcard').split()
verbs = (
- 'write where wait use update unregister undo trace test tee take '
- 'suspend stop start split sort skip show set send select scroll resume '
- 'restore restart resolve resize reset rename remove register receive '
- 'read push pop ping out new move measure limit join invoke import '
- 'group get format foreach export expand exit enter enable disconnect '
- 'disable debug cxnew copy convertto convertfrom convert connect '
- 'complete compare clear checkpoint aggregate add').split()
+ 'write where watch wait use update unregister unpublish unprotect '
+ 'unlock uninstall undo unblock trace test tee take sync switch '
+ 'suspend submit stop step start split sort skip show set send select '
+ 'search scroll save revoke resume restore restart resolve resize '
+ 'reset request repair rename remove register redo receive read push '
+ 'publish protect pop ping out optimize open new move mount merge '
+ 'measure lock limit join invoke install initialize import hide group '
+ 'grant get format foreach find export expand exit enter enable edit '
+ 'dismount disconnect disable deny debug cxnew copy convertto '
+ 'convertfrom convert connect confirm compress complete compare close '
+ 'clear checkpoint block backup assert approve aggregate add').split()
+
+ aliases_ = (
+ 'ac asnp cat cd cfs chdir clc clear clhy cli clp cls clv cnsn '
+ 'compare copy cp cpi cpp curl cvpa dbp del diff dir dnsn ebp echo epal '
+ 'epcsv epsn erase etsn exsn fc fhx fl foreach ft fw gal gbp gc gci gcm '
+ 'gcs gdr ghy gi gjb gl gm gmo gp gps gpv group gsn gsnp gsv gu gv gwmi '
+ 'h history icm iex ihy ii ipal ipcsv ipmo ipsn irm ise iwmi iwr kill lp '
+ 'ls man md measure mi mount move mp mv nal ndr ni nmo npssc nsn nv ogv '
+ 'oh popd ps pushd pwd r rbp rcjb rcsn rd rdr ren ri rjb rm rmdir rmo '
+ 'rni rnp rp rsn rsnp rujb rv rvpa rwmi sajb sal saps sasv sbp sc select '
+ 'set shcm si sl sleep sls sort sp spjb spps spsv start sujb sv swmi tee '
+ 'trcm type wget where wjb write').split()
commenthelp = (
'component description example externalhelp forwardhelpcategory '
@@ -668,6 +710,7 @@ class PowerShellLexer(RegexLexer):
(r'(%s)\b' % '|'.join(keywords), Keyword),
(r'-(%s)\b' % '|'.join(operators), Operator),
(r'(%s)-[a-z_]\w*\b' % '|'.join(verbs), Name.Builtin),
+ (r'(%s)\s' % '|'.join(aliases_), Name.Builtin),
(r'\[[a-z_\[][\w. `,\[\]]*\]', Name.Constant), # .net [type]s
(r'-[a-z_]\w*', Name),
(r'\w+', Name),