codekingpro/portable-devtools
114k
1"""2 pygments.lexers.qlik3 ~~~~~~~~~~~~~~~~~~~~4 5 Lexer for the qlik scripting language6 7 :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8 :license: BSD, see LICENSE for details.9"""10 11import re12 13from pygments.lexer import RegexLexer, include, bygroups, words14from pygments.token import Comment, Keyword, Name, Number, Operator, \15 Punctuation, String, Text16from pygments.lexers._qlik_builtins import OPERATORS_LIST, STATEMENT_LIST, \17 SCRIPT_FUNCTIONS, CONSTANT_LIST18 19__all__ = ["QlikLexer"]20 21 22class QlikLexer(RegexLexer):23 """24 Lexer for qlik code, including .qvs files25 """26 27 name = "Qlik"28 aliases = ["qlik", "qlikview", "qliksense", "qlikscript"]29 filenames = ["*.qvs", "*.qvw"]30 url = "https://qlik.com"31 version_added = '2.12'32 33 flags = re.IGNORECASE34 35 tokens = {36 # Handle multi-line comments37 "comment": [38 (r"\*/", Comment.Multiline, "#pop"),39 (r"[^*]+", Comment.Multiline),40 ],41 # Handle numbers42 "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 things47 "interp": [48 (49 r"(\$\()(\w+)(\))",50 bygroups(String.Interpol, Name.Variable, String.Interpol),51 ),52 ],53 # Handle strings54 "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 comments80 (r"\s+", Text.Whitespace),81 (r"/\*", Comment.Multiline, "comment"),82 (r"//.*\n", Comment.Single),83 # variable assignment84 (r"(let|set)(\s+)", bygroups(Keyword.Declaration, Text.Whitespace),85 "assignment"),86 # Word operators87 (words(OPERATORS_LIST["words"], prefix=r"\b", suffix=r"\b"),88 Operator.Word),89 # Statements90 (words(STATEMENT_LIST, suffix=r"\b"), Keyword),91 # Table names92 (r"[a-z]\w*:", Keyword.Declaration),93 # Constants94 (words(CONSTANT_LIST, suffix=r"\b"), Keyword.Constant),95 # Functions96 (words(SCRIPT_FUNCTIONS, suffix=r"(?=\s*\()"), Name.Builtin,97 "function"),98 # interpolation - e.g. $(variableName)99 include("interp"),100 # Quotes denote a field/file name101 (r'"', String.Symbol, "field_name_quote"),102 # Square brackets denote a field/file name103 (r"\[", String.Symbol, "field_name_bracket"),104 # Strings105 (r"'", String, "string"),106 # Numbers107 include("numerics"),108 # Operator symbols109 (words(OPERATORS_LIST["symbols"]), Operator),110 # Strings denoted by single quotes111 (r"'.+?'", String),112 # Words as text113 (r"\b\w+\b", Text),114 # Basic punctuation115 (r"[,;.()\\/]", Punctuation),116 ],117 }118 