Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/codeql.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

14 statements  

1""" 

2 pygments.lexers.codeql 

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

4 

5 Lexer for CodeQL query language. 

6 

7 The grammar is originating from: 

8 https://github.com/github/vscode-codeql/blob/main/syntaxes/README.md 

9 

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

11 :license: BSD, see LICENSE for details. 

12""" 

13 

14__all__ = ['CodeQLLexer'] 

15 

16import re 

17 

18from pygments.lexer import RegexLexer, words 

19from pygments.token import Comment, Operator, Keyword, Name, String, \ 

20 Number, Punctuation, Whitespace 

21 

22class CodeQLLexer(RegexLexer): 

23 name = 'CodeQL' 

24 aliases = ['codeql', 'ql'] 

25 filenames = ['*.ql', '*.qll'] 

26 mimetypes = [] 

27 url = 'https://github.com/github/codeql' 

28 version_added = '2.19' 

29 

30 flags = re.MULTILINE | re.UNICODE 

31 

32 tokens = { 

33 'root': [ 

34 # Whitespace and comments 

35 (r'\s+', Whitespace), 

36 (r'//.*?\n', Comment.Single), 

37 (r'/\*', Comment.Multiline, 'multiline-comments'), 

38 

39 # Keywords 

40 (words(( 

41 'module', 'import', 'class', 'extends', 'implements', 

42 'predicate', 'select', 'where', 'from', 'as', 'and', 'or', 'not', 

43 'in', 'if', 'then', 'else', 'exists', 'forall', 'instanceof', 

44 'private', 'predicate', 'abstract', 'cached', 'external', 

45 'final', 'library', 'override', 'query' 

46 ), suffix=r'\b'), Keyword.Builtin), 

47 

48 # Special Keywords 

49 (words(('this'), # class related keywords 

50 prefix=r'\b', suffix=r'\b\??:?'), Name.Builtin.Pseudo), 

51 

52 # Types 

53 (words(( 

54 'boolean', 'date', 'float', 'int', 'string' 

55 ), suffix=r'\b'), Keyword.Type), 

56 

57 # Literals 

58 (r'"(\\\\|\\[^\\]|[^"\\])*"', String), 

59 (r'[0-9]+\.[0-9]+', Number.Float), 

60 (r'[0-9]+', Number.Integer), 

61 

62 # Operators 

63 (r'<=|>=|<|>|=|!=|\+|-|\*|/', Operator), 

64 

65 # Punctuation 

66 (r'[.,;:\[\]{}()]+', Punctuation), 

67 

68 # Identifiers 

69 (r'@[a-zA-Z_]\w*', Name.Variable), # Variables with @ prefix 

70 (r'[A-Z][a-zA-Z0-9_]*', Name.Class), # Types and classes 

71 (r'[a-z][a-zA-Z0-9_]*', Name.Variable), # Variables and predicates 

72 ], 

73 'multiline-comments': [ 

74 (r'[^*/]+', Comment.Multiline), 

75 (r'/\*', Comment.Multiline, '#push'), 

76 (r'\*/', Comment.Multiline, '#pop'), 

77 (r'[*/]', Comment.Multiline), 

78 ], 

79 

80 }