summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--doc/languages.rst1
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/jslt.py94
-rw-r--r--tests/snippets/jslt/test_sample.txt83
5 files changed, 180 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 65a8ba9b..515b88ec 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -6,6 +6,7 @@ Major developers are Tim Hatch <tim@timhatch.com> and Armin Ronacher
Other contributors, listed alphabetically, are:
* Sam Aaron -- Ioke lexer
+* João Abecasis -- JSLT lexer
* Ali Afshar -- image formatter
* Thomas Aglassinger -- Easytrieve, JCL, Rexx, Transact-SQL and VBScript
lexers
diff --git a/doc/languages.rst b/doc/languages.rst
index 35aeb506..0132a847 100644
--- a/doc/languages.rst
+++ b/doc/languages.rst
@@ -93,6 +93,7 @@ Programming languages
* `Jasmin <http://jasmin.sourceforge.net/>`_
* `Jcl <https://en.wikipedia.org/wiki/Job_Control_Language>`_
* `Julia <https://julialang.org>`_
+* `JSLT <https://github.com/schibsted/jslt>`_
* `Kotlin <https://kotlinlang.org/>`_
* `Lasso <http://www.lassosoft.com/>`_ (incl. templating)
* `Limbo <http://www.vitanuova.com/inferno/limbo.html>`_
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index c7fa5452..c1cef93c 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -222,6 +222,7 @@ LEXERS = {
'IrcLogsLexer': ('pygments.lexers.textfmts', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)),
'IsabelleLexer': ('pygments.lexers.theorem', 'Isabelle', ('isabelle',), ('*.thy',), ('text/x-isabelle',)),
'JLexer': ('pygments.lexers.j', 'J', ('j',), ('*.ijs',), ('text/x-j',)),
+ 'JSLTLexer': ('pygments.lexers.jslt', 'JSLT', ('jslt',), ('*.jslt',), ('text/x-jslt',)),
'JagsLexer': ('pygments.lexers.modeling', 'JAGS', ('jags',), ('*.jag', '*.bug'), ()),
'JasminLexer': ('pygments.lexers.jvm', 'Jasmin', ('jasmin', 'jasminxt'), ('*.j',), ()),
'JavaLexer': ('pygments.lexers.jvm', 'Java', ('java',), ('*.java',), ('text/x-java',)),
diff --git a/pygments/lexers/jslt.py b/pygments/lexers/jslt.py
new file mode 100644
index 00000000..a27cb014
--- /dev/null
+++ b/pygments/lexers/jslt.py
@@ -0,0 +1,94 @@
+"""
+ pygments.lexers.jslt
+ ~~~~~~~~~~~~~~~~~~~~
+
+ Lexers for the JSLT language
+
+ :copyright: Copyright 2021 by the Pygments team, see AUTHORS
+ :license: BSD, see LICENSE for details
+"""
+
+from pygments.lexer import RegexLexer, combined, words
+from pygments.token import Comment, Keyword, Name, Number, Operator, \
+ Punctuation, String, Whitespace
+
+
+__all__ = ['JSLTLexer']
+
+
+_WORD_END = r'(?=[^0-9A-Z_a-z-])'
+
+
+class JSLTLexer(RegexLexer):
+ """
+ For `JSLT <https://github.com/schibsted/jslt>`_ source.
+
+ .. versionadded:: 2.10
+ """
+ name = 'JSLT'
+ filenames = ['*.jslt']
+ aliases = ['jslt']
+ mimetypes = ['text/x-jslt']
+
+ tokens = {
+ 'root': [
+ (r'[\t\n\f\r ]+', Whitespace),
+ (r'//.*(\n|\Z)', Comment.Single),
+ (r'-?(0|[1-9][0-9]*)', Number.Integer),
+ (r'-?(0|[1-9][0-9]*)(.[0-9]+a)?([Ee][+-]?[0-9]+)', Number.Float),
+ (r'"([^"\\]|\\.)*"', String.Double),
+ (r'[(),:\[\]{}]', Punctuation),
+ (r'(!=|[<=>]=?)', Operator),
+ (r'[*+/|-]', Operator),
+ (r'\.', Operator),
+ (words(('import',), suffix=_WORD_END), Keyword.Namespace, combined('import-path', 'whitespace')),
+ (words(('as',), suffix=_WORD_END), Keyword.Namespace, combined('import-alias', 'whitespace')),
+ (words(('let',), suffix=_WORD_END), Keyword.Declaration, combined('constant', 'whitespace')),
+ (words(('def',), suffix=_WORD_END), Keyword.Declaration, combined('function', 'whitespace')),
+ (words(('false', 'null', 'true'), suffix=_WORD_END), Keyword.Constant),
+ (words(('else', 'for', 'if'), suffix=_WORD_END), Keyword),
+ (words(('and', 'or'), suffix=_WORD_END), Operator.Word),
+ (words((
+ 'all', 'any', 'array', 'boolean', 'capture', 'ceiling',
+ 'contains', 'ends-with', 'error', 'flatten', 'floor',
+ 'format-time', 'from-json', 'get-key', 'hash-int', 'index-of',
+ 'is-array', 'is-boolean', 'is-decimal', 'is-integer',
+ 'is-number', 'is-object', 'is-string', 'join', 'lowercase',
+ 'max', 'min', 'mod', 'not', 'now', 'number', 'parse-time',
+ 'parse-url', 'random', 'replace', 'round', 'sha256-hex', 'size',
+ 'split', 'starts-with', 'string', 'sum', 'test', 'to-json',
+ 'trim', 'uppercase', 'zip', 'zip-with-index', 'fallback'), suffix=_WORD_END),
+ Name.Builtin),
+ (r'[A-Z_a-z][0-9A-Z_a-z-]*:[A-Z_a-z][0-9A-Z_a-z-]*', Name.Function),
+ (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name),
+ (r'\$[A-Z_a-z][0-9A-Z_a-z-]*', Name.Variable),
+ ],
+ 'constant': [
+ (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Variable, 'root'),
+ ],
+ 'function': [
+ (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Function, combined('function-parameter-list', 'whitespace')),
+ ],
+ 'function-parameter-list': [
+ (r'\(', Punctuation, combined('function-parameters', 'whitespace')),
+ ],
+ 'function-parameters': [
+ (r',', Punctuation),
+ (r'\)', Punctuation, 'root'),
+ (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Variable),
+ ],
+ 'import-path': [
+ (r'"([^"]|\\.)*"', String.Symbol, 'root'),
+ ],
+ 'import-alias': [
+ (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Namespace, 'root'),
+ ],
+ 'string': [
+ (r'"', String.Double, '#pop'),
+ (r'\\.', String.Escape),
+ ],
+ 'whitespace': [
+ (r'[\t\n\f\r ]+', Whitespace),
+ (r'//.*(\n|\Z)', Comment.Single),
+ ]
+ }
diff --git a/tests/snippets/jslt/test_sample.txt b/tests/snippets/jslt/test_sample.txt
new file mode 100644
index 00000000..73ad3fda
--- /dev/null
+++ b/tests/snippets/jslt/test_sample.txt
@@ -0,0 +1,83 @@
+---input---
+import "transforms/yellow.jslt" as yellow
+
+// Known valid types
+let valid-types = [ "SomeType" ]
+
+def foobar(arg) $arg.foobar
+
+{
+ "foobar": foobar(.),
+ "is-valid": contains(.type, $valid-types),
+ *: .
+}
+
+---tokens---
+'import' Keyword.Namespace
+' ' Text.Whitespace
+'"transforms/yellow.jslt"' Literal.String.Symbol
+' ' Text.Whitespace
+'as' Keyword.Namespace
+' ' Text.Whitespace
+'yellow' Name.Namespace
+'\n\n' Text.Whitespace
+
+'// Known valid types\n' Comment.Single
+
+'let' Keyword.Declaration
+' ' Text.Whitespace
+'valid-types' Name.Variable
+' ' Text.Whitespace
+'=' Operator
+' ' Text.Whitespace
+'[' Punctuation
+' ' Text.Whitespace
+'"SomeType"' Literal.String.Double
+' ' Text.Whitespace
+']' Punctuation
+'\n\n' Text.Whitespace
+
+'def' Keyword.Declaration
+' ' Text.Whitespace
+'foobar' Name.Function
+'(' Punctuation
+'arg' Name.Variable
+')' Punctuation
+' ' Text.Whitespace
+'$arg' Name.Variable
+'.' Operator
+'foobar' Name
+'\n\n' Text.Whitespace
+
+'{' Punctuation
+'\n ' Text.Whitespace
+'"foobar"' Literal.String.Double
+':' Punctuation
+' ' Text.Whitespace
+'foobar' Name
+'(' Punctuation
+'.' Operator
+')' Punctuation
+',' Punctuation
+'\n ' Text.Whitespace
+'"is-valid"' Literal.String.Double
+':' Punctuation
+' ' Text.Whitespace
+'contains' Name.Builtin
+'(' Punctuation
+'.' Operator
+'type' Name
+',' Punctuation
+' ' Text.Whitespace
+'$valid-types' Name.Variable
+')' Punctuation
+',' Punctuation
+'\n ' Text.Whitespace
+'*' Operator
+':' Punctuation
+' ' Text.Whitespace
+'.' Operator
+'\n' Text.Whitespace
+
+'}' Punctuation
+'\n' Text.Whitespace