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

11 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2 pygments.lexers.qlik 

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

4 

5 Lexer for the qlik scripting language 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import RegexLexer, include, bygroups, words 

14from pygments.token import Comment, Keyword, Name, Number, Operator, \ 

15 Punctuation, String, Text 

16from pygments.lexers._qlik_builtins import OPERATORS_LIST, STATEMENT_LIST, \ 

17 SCRIPT_FUNCTIONS, CONSTANT_LIST 

18 

19__all__ = ["QlikLexer"] 

20 

21 

22class QlikLexer(RegexLexer): 

23 """ 

24 Lexer for qlik code, including .qvs files 

25 

26 .. versionadded:: 2.12 

27 """ 

28 

29 name = "Qlik" 

30 aliases = ["qlik", "qlikview", "qliksense", "qlikscript"] 

31 filenames = ["*.qvs", "*.qvw"] 

32 

33 flags = re.IGNORECASE 

34 

35 tokens = { 

36 # Handle multi-line comments 

37 "comment": [ 

38 (r"\*/", Comment.Multiline, "#pop"), 

39 (r"[^*]+", Comment.Multiline), 

40 ], 

41 # Handle numbers 

42 "numerics": [ 

43 (r"\b\d+\.\d+(e\d+)?[fd]?\b", Number.Float), 

44 (r"\b\d+\b", Number.Integer), 

45 ], 

46 # Handle variable names in things 

47 "interp": [ 

48 ( 

49 r"(\$\()(\w+)(\))", 

50 bygroups(String.Interpol, Name.Variable, String.Interpol), 

51 ), 

52 ], 

53 # Handle strings 

54 "string": [ 

55 (r"'", String, "#pop"), 

56 include("interp"), 

57 (r"[^'$]+", String), 

58 (r"\$", String), 

59 ], 

60 # 

61 "assignment": [ 

62 (r";", Punctuation, "#pop"), 

63 include("root"), 

64 ], 

65 "field_name_quote": [ 

66 (r'"', String.Symbol, "#pop"), 

67 include("interp"), 

68 (r"[^\"$]+", String.Symbol), 

69 (r"\$", String.Symbol), 

70 ], 

71 "field_name_bracket": [ 

72 (r"\]", String.Symbol, "#pop"), 

73 include("interp"), 

74 (r"[^\]$]+", String.Symbol), 

75 (r"\$", String.Symbol), 

76 ], 

77 "function": [(r"\)", Punctuation, "#pop"), include("root")], 

78 "root": [ 

79 # Whitespace and comments 

80 (r"\s+", Text.Whitespace), 

81 (r"/\*", Comment.Multiline, "comment"), 

82 (r"//.*\n", Comment.Single), 

83 # variable assignment 

84 (r"(let|set)(\s+)", bygroups(Keyword.Declaration, Text.Whitespace), 

85 "assignment"), 

86 # Word operators 

87 (words(OPERATORS_LIST["words"], prefix=r"\b", suffix=r"\b"), 

88 Operator.Word), 

89 # Statements 

90 (words(STATEMENT_LIST, suffix=r"\b"), Keyword), 

91 # Table names 

92 (r"[a-z]\w*:", Keyword.Declaration), 

93 # Constants 

94 (words(CONSTANT_LIST, suffix=r"\b"), Keyword.Constant), 

95 # Functions 

96 (words(SCRIPT_FUNCTIONS, suffix=r"(?=\s*\()"), Name.Builtin, 

97 "function"), 

98 # interpolation - e.g. $(variableName) 

99 include("interp"), 

100 # Quotes denote a field/file name 

101 (r'"', String.Symbol, "field_name_quote"), 

102 # Square brackets denote a field/file name 

103 (r"\[", String.Symbol, "field_name_bracket"), 

104 # Strings 

105 (r"'", String, "string"), 

106 # Numbers 

107 include("numerics"), 

108 # Operator symbols 

109 (words(OPERATORS_LIST["symbols"]), Operator), 

110 # Strings denoted by single quotes 

111 (r"'.+?'", String), 

112 # Words as text 

113 (r"\b\w+\b", Text), 

114 # Basic punctuation 

115 (r"[,;.()\\/]", Punctuation), 

116 ], 

117 }