summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryton Hall <email@bryton.io>2019-01-03 18:39:56 -0500
committerGeorg Brandl <georg@python.org>2019-11-27 07:08:09 +0100
commitac037db8115485ee9f17a848e496c98bcc58cf0e (patch)
tree658cc22d6faafd9d081ca7d86d5ab2f1c5843c51
parentb45777fd2713bc3c6b80680168563afa5c96b46d (diff)
downloadpygments-git-793/brytonhall/singularity.tar.gz
add Singularity lexer793/brytonhall/singularity
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/configs.py37
-rw-r--r--tests/examplefiles/Singularity45
3 files changed, 81 insertions, 2 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index acb71ad9..b5a7938b 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -396,6 +396,7 @@ LEXERS = {
'ShExCLexer': ('pygments.lexers.rdf', 'ShExC', ('shexc', 'shex'), ('*.shex',), ('text/shex',)),
'ShenLexer': ('pygments.lexers.lisp', 'Shen', ('shen',), ('*.shen',), ('text/x-shen', 'application/x-shen')),
'SilverLexer': ('pygments.lexers.verification', 'Silver', ('silver',), ('*.sil', '*.vpr'), ()),
+ 'SingularityLexer': ('pygments.lexers.configs', 'Singularity', ('singularity',), ('*.def', 'Singularity'), ()),
'SlashLexer': ('pygments.lexers.slash', 'Slash', ('slash',), ('*.sl',), ()),
'SlimLexer': ('pygments.lexers.webmisc', 'Slim', ('slim',), ('*.slim',), ('text/x-slim',)),
'SlurmBashLexer': ('pygments.lexers.shell', 'Slurm', ('slurm', 'sbatch'), ('*.sl',), ()),
diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py
index a18285af..b719e30a 100644
--- a/pygments/lexers/configs.py
+++ b/pygments/lexers/configs.py
@@ -13,7 +13,7 @@ import re
from pygments.lexer import RegexLexer, default, words, bygroups, include, using
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
- Number, Punctuation, Whitespace, Literal
+ Number, Punctuation, Whitespace, Literal, Generic
from pygments.lexers.shell import BashLexer
from pygments.lexers.data import JsonLexer
@@ -21,7 +21,8 @@ __all__ = ['IniLexer', 'RegeditLexer', 'PropertiesLexer', 'KconfigLexer',
'Cfengine3Lexer', 'ApacheConfLexer', 'SquidConfLexer',
'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer',
'TerraformLexer', 'TermcapLexer', 'TerminfoLexer',
- 'PkgConfigLexer', 'PacmanConfLexer', 'AugeasLexer', 'TOMLLexer']
+ 'PkgConfigLexer', 'PacmanConfLexer', 'AugeasLexer', 'TOMLLexer',
+ 'SingularityLexer']
class IniLexer(RegexLexer):
@@ -934,3 +935,35 @@ class TOMLLexer(RegexLexer):
]
}
+
+
+class SingularityLexer(RegexLexer):
+ """
+ Lexer for `Singularity definition files
+ <https://www.sylabs.io/guides/3.0/user-guide/definition_files.html>`_.
+
+ .. versionadded:: 2.6
+ """
+
+ name = 'Singularity'
+ aliases = ['singularity']
+ filenames = ['*.def', 'Singularity']
+ flags = re.IGNORECASE | re.MULTILINE | re.DOTALL
+
+ _headers = r'^(\s)*(bootstrap|from|osversion|mirrorurl|include|registry|namespace|includecmd)(:)'
+ _section = r'^%(?:pre|post|setup|environment|help|labels|test|runscript|files|startscript)\b'
+ _appsect = r'^%app(?:install|help|run|labels|env|test|files)\b'
+
+ tokens = {
+ 'root': [
+ (_section, Generic.Heading, 'script'),
+ (_appsect, Generic.Heading, 'script'),
+ (_headers, bygroups(Text, Keyword, Text)),
+ (r'\s*#.*?\n', Comment),
+ (r'\b(([0-9]+\.?[0-9]*)|(\.[0-9]+))\b', Number),
+ (r'(?!^\s*%).', Text),
+ ],
+ 'script': [
+ (r'(.+?(?=^\s*%))|(.*)', using(BashLexer), '#pop'),
+ ],
+ }
diff --git a/tests/examplefiles/Singularity b/tests/examplefiles/Singularity
new file mode 100644
index 00000000..0056e008
--- /dev/null
+++ b/tests/examplefiles/Singularity
@@ -0,0 +1,45 @@
+BoOtStRaP: library # pass: headers are case-insensitive
+# pass: do not highlight '%'
+MirrorURL: http://mirror.centos.org/centos-%{OSVERSION}/%{OSVERSION}/os/$basearch/
+ From: ubuntu:18.04 # pass: leading whitespace allowed
+
+%setup
+ touch /file1
+touch ${SINGULARITY_ROOTFS}/file2 # pass: leading whitespace optional
+
+%files
+ /file1
+ /file1 /opt
+
+%environment
+ export LISTEN_PORT=12345
+ export LC_ALL=C
+
+%runscript
+ echo "Container was created $NOW"
+ echo "Arguments received: $*"
+ exec echo "$@"
+
+%startscript
+ nc -lp $LISTEN_PORT
+
+%test
+ grep -q NAME=\"Ubuntu\" /etc/os-release
+ if [ $? -eq 0 ]; then
+ echo "Container base is Ubuntu as expected."
+ else
+ echo "Container base is not Ubuntu."
+ fi
+
+%labels
+ Author d@sylabs.io
+ Version v0.0.1
+
+%help
+ This is a demo container used to illustrate a def file that uses all
+ supported sections.
+
+%post
+ apt-get update && apt-get install -y netcat
+ NOW=$((date % 1)) # pass: don't highlight '%'
+ echo "export NOW=\"${NOW}\"" >> $SINGULARITY_ENVIRONMENT