Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/jmespath.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

1""" 

2 pygments.lexers.jmespath 

3 ~~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for the JMESPath language 

6 

7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, bygroups, include 

12from pygments.token import String, Punctuation, Whitespace, Name, Operator, \ 

13 Number, Literal, Keyword 

14 

15__all__ = ['JMESPathLexer'] 

16 

17 

18class JMESPathLexer(RegexLexer): 

19 """ 

20 For JMESPath queries. 

21 """ 

22 name = 'JMESPath' 

23 url = 'https://jmespath.org' 

24 filenames = ['*.jp'] 

25 aliases = ['jmespath', 'jp'] 

26 version_added = '' 

27 

28 tokens = { 

29 'string': [ 

30 (r"'(\\(.|\n)|[^'\\])*'", String), 

31 ], 

32 'punctuation': [ 

33 (r'(\[\?|[\.\*\[\],:\(\)\{\}\|])', Punctuation), 

34 ], 

35 'ws': [ 

36 (r" |\t|\n|\r", Whitespace) 

37 ], 

38 "dq-identifier": [ 

39 (r'[^\\"]+', Name.Variable), 

40 (r'\\"', Name.Variable), 

41 (r'.', Punctuation, '#pop'), 

42 ], 

43 'identifier': [ 

44 (r'(&)?(")', bygroups(Name.Variable, Punctuation), 'dq-identifier'), 

45 (r'(")?(&?[A-Za-z][A-Za-z0-9_-]*)(")?', bygroups(Punctuation, Name.Variable, Punctuation)), 

46 ], 

47 'root': [ 

48 include('ws'), 

49 include('string'), 

50 (r'(==|!=|<=|>=|<|>|&&|\|\||!)', Operator), 

51 include('punctuation'), 

52 (r'@', Name.Variable.Global), 

53 (r'(&?[A-Za-z][A-Za-z0-9_]*)(\()', bygroups(Name.Function, Punctuation)), 

54 (r'(&)(\()', bygroups(Name.Variable, Punctuation)), 

55 include('identifier'), 

56 (r'-?\d+', Number), 

57 (r'`', Literal, 'literal'), 

58 ], 

59 'literal': [ 

60 include('ws'), 

61 include('string'), 

62 include('punctuation'), 

63 (r'(false|true|null)\b', Keyword.Constant), 

64 include('identifier'), 

65 (r'-?\d+\.?\d*([eE][-+]\d+)?', Number), 

66 (r'\\`', Literal), 

67 (r'`', Literal, '#pop'), 

68 ] 

69 }