Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/jslt.py: 100%
11 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.jslt
3 ~~~~~~~~~~~~~~~~~~~~
5 Lexers for the JSLT language
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, combined, words
12from pygments.token import Comment, Keyword, Name, Number, Operator, \
13 Punctuation, String, Whitespace
16__all__ = ['JSLTLexer']
19_WORD_END = r'(?=[^0-9A-Z_a-z-])'
22class JSLTLexer(RegexLexer):
23 """
24 For JSLT source.
26 .. versionadded:: 2.10
27 """
28 name = 'JSLT'
29 url = 'https://github.com/schibsted/jslt'
30 filenames = ['*.jslt']
31 aliases = ['jslt']
32 mimetypes = ['text/x-jslt']
34 tokens = {
35 'root': [
36 (r'[\t\n\f\r ]+', Whitespace),
37 (r'//.*(\n|\Z)', Comment.Single),
38 (r'-?(0|[1-9][0-9]*)', Number.Integer),
39 (r'-?(0|[1-9][0-9]*)(.[0-9]+a)?([Ee][+-]?[0-9]+)', Number.Float),
40 (r'"([^"\\]|\\.)*"', String.Double),
41 (r'[(),:\[\]{}]', Punctuation),
42 (r'(!=|[<=>]=?)', Operator),
43 (r'[*+/|-]', Operator),
44 (r'\.', Operator),
45 (words(('import',), suffix=_WORD_END), Keyword.Namespace, combined('import-path', 'whitespace')),
46 (words(('as',), suffix=_WORD_END), Keyword.Namespace, combined('import-alias', 'whitespace')),
47 (words(('let',), suffix=_WORD_END), Keyword.Declaration, combined('constant', 'whitespace')),
48 (words(('def',), suffix=_WORD_END), Keyword.Declaration, combined('function', 'whitespace')),
49 (words(('false', 'null', 'true'), suffix=_WORD_END), Keyword.Constant),
50 (words(('else', 'for', 'if'), suffix=_WORD_END), Keyword),
51 (words(('and', 'or'), suffix=_WORD_END), Operator.Word),
52 (words((
53 'all', 'any', 'array', 'boolean', 'capture', 'ceiling',
54 'contains', 'ends-with', 'error', 'flatten', 'floor',
55 'format-time', 'from-json', 'get-key', 'hash-int', 'index-of',
56 'is-array', 'is-boolean', 'is-decimal', 'is-integer',
57 'is-number', 'is-object', 'is-string', 'join', 'lowercase',
58 'max', 'min', 'mod', 'not', 'now', 'number', 'parse-time',
59 'parse-url', 'random', 'replace', 'round', 'sha256-hex', 'size',
60 'split', 'starts-with', 'string', 'sum', 'test', 'to-json',
61 'trim', 'uppercase', 'zip', 'zip-with-index', 'fallback'), suffix=_WORD_END),
62 Name.Builtin),
63 (r'[A-Z_a-z][0-9A-Z_a-z-]*:[A-Z_a-z][0-9A-Z_a-z-]*', Name.Function),
64 (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name),
65 (r'\$[A-Z_a-z][0-9A-Z_a-z-]*', Name.Variable),
66 ],
67 'constant': [
68 (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Variable, 'root'),
69 ],
70 'function': [
71 (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Function, combined('function-parameter-list', 'whitespace')),
72 ],
73 'function-parameter-list': [
74 (r'\(', Punctuation, combined('function-parameters', 'whitespace')),
75 ],
76 'function-parameters': [
77 (r',', Punctuation),
78 (r'\)', Punctuation, 'root'),
79 (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Variable),
80 ],
81 'import-path': [
82 (r'"([^"]|\\.)*"', String.Symbol, 'root'),
83 ],
84 'import-alias': [
85 (r'[A-Z_a-z][0-9A-Z_a-z-]*', Name.Namespace, 'root'),
86 ],
87 'string': [
88 (r'"', String.Double, '#pop'),
89 (r'\\.', String.Escape),
90 ],
91 'whitespace': [
92 (r'[\t\n\f\r ]+', Whitespace),
93 (r'//.*(\n|\Z)', Comment.Single),
94 ]
95 }