Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/jmespath.py: 100%
9 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.jmespath
3 ~~~~~~~~~~~~~~~~~~~~~~~~
5 Lexers for the JMESPath 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, bygroups, include
12from pygments.token import String, Punctuation, Whitespace, Name, Operator, \
13 Number, Literal, Keyword
15__all__ = ['JMESPathLexer']
18class JMESPathLexer(RegexLexer):
19 """
20 For JMESPath queries.
21 """
22 name = 'JMESPath'
23 url = 'https://jmespath.org'
24 filenames = ['*.jp']
25 aliases = ['jmespath', 'jp']
27 tokens = {
28 'string': [
29 (r"'(\\(.|\n)|[^'\\])*'", String),
30 ],
31 'punctuation': [
32 (r'(\[\?|[\.\*\[\],:\(\)\{\}\|])', Punctuation),
33 ],
34 'ws': [
35 (r" |\t|\n|\r", Whitespace)
36 ],
37 "dq-identifier": [
38 (r'[^\\"]+', Name.Variable),
39 (r'\\"', Name.Variable),
40 (r'.', Punctuation, '#pop'),
41 ],
42 'identifier': [
43 (r'(&)?(")', bygroups(Name.Variable, Punctuation), 'dq-identifier'),
44 (r'(")?(&?[A-Za-z][A-Za-z0-9_-]*)(")?', bygroups(Punctuation, Name.Variable, Punctuation)),
45 ],
46 'root': [
47 include('ws'),
48 include('string'),
49 (r'(==|!=|<=|>=|<|>|&&|\|\||!)', Operator),
50 include('punctuation'),
51 (r'@', Name.Variable.Global),
52 (r'(&?[A-Za-z][A-Za-z0-9_]*)(\()', bygroups(Name.Function, Punctuation)),
53 (r'(&)(\()', bygroups(Name.Variable, Punctuation)),
54 include('identifier'),
55 (r'-?\d+', Number),
56 (r'`', Literal, 'literal'),
57 ],
58 'literal': [
59 include('ws'),
60 include('string'),
61 include('punctuation'),
62 (r'(false|true|null)\b', Keyword.Constant),
63 include('identifier'),
64 (r'-?\d+\.?\d*([eE][-+]\d+)?', Number),
65 (r'\\`', Literal),
66 (r'`', Literal, '#pop'),
67 ]
68 }