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.py63
1 files changed, 51 insertions, 12 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index ceb6f14d..972c4004 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -5,7 +5,7 @@
Lexers for various shells.
- :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2019 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')
@@ -38,7 +38,7 @@ class BashLexer(RegexLexer):
'*.exheres-0', '*.exlib', '*.zsh',
'.bashrc', 'bashrc', '.bash_*', 'bash_*', 'zshrc', '.zshrc',
'PKGBUILD']
- mimetypes = ['application/x-sh', 'application/x-shellscript']
+ mimetypes = ['application/x-sh', 'application/x-shellscript', 'text/x-shellscript']
tokens = {
'root': [
@@ -76,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),
@@ -126,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.
@@ -518,7 +540,7 @@ class MSDOSSessionLexer(ShellSessionBaseLexer):
mimetypes = []
_innerLexerCls = BatchLexer
- _ps1rgx = r'^([^>]+>)(.*\n?)'
+ _ps1rgx = r'^([^>]*>)(.*\n?)'
_ps2 = 'More? '
@@ -638,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 '
@@ -672,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),