Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/q.py: 100%
13 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.q
3 ~~~~~~~~~~~~~~~~~
5 Lexer for the Q programming 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, words, include, bygroups, inherit
12from pygments.token import Comment, Name, Number, Operator, Punctuation, \
13 String, Whitespace, Literal, Generic
15__all__ = ["KLexer", "QLexer"]
18class KLexer(RegexLexer):
19 """
20 For `K <https://code.kx.com/>`_ source code.
22 .. versionadded:: 2.12
23 """
25 name = "K"
26 aliases = ["k"]
27 filenames = ["*.k"]
29 tokens = {
30 "whitespace": [
31 # hashbang script
32 (r"^#!.*", Comment.Hashbang),
33 # Comments
34 (r"^/\s*\n", Comment.Multiline, "comments"),
35 (r"(?<!\S)/.*", Comment.Single),
36 # Whitespace
37 (r"\s+", Whitespace),
38 # Strings
39 (r"\"", String.Double, "strings"),
40 ],
41 "root": [
42 include("whitespace"),
43 include("keywords"),
44 include("declarations"),
45 ],
46 "keywords": [
47 (words(("abs", "acos", "asin", "atan", "avg", "bin",
48 "binr", "by", "cor", "cos", "cov", "dev",
49 "delete", "div", "do", "enlist", "exec", "exit",
50 "exp", "from", "getenv", "hopen", "if", "in",
51 "insert", "last", "like", "log", "max", "min",
52 "prd", "select", "setenv", "sin", "sqrt", "ss",
53 "sum", "tan", "update", "var", "wavg", "while",
54 "within", "wsum", "xexp"),
55 suffix=r"\b"), Operator.Word),
56 ],
57 "declarations": [
58 # Timing
59 (r"^\\ts?", Comment.Preproc),
60 (r"^(\\\w\s+[^/\n]*?)(/.*)",
61 bygroups(Comment.Preproc, Comment.Single)),
62 # Generic System Commands
63 (r"^\\\w.*", Comment.Preproc),
64 # Prompt
65 (r"^[a-zA-Z]\)", Generic.Prompt),
66 # Function Names
67 (r"([.]?[a-zA-Z][\w.]*)(\s*)([-.~=!@#$%^&*_+|,<>?/\\:']?:)(\s*)(\{)",
68 bygroups(Name.Function, Whitespace, Operator, Whitespace, Punctuation),
69 "functions"),
70 # Variable Names
71 (r"([.]?[a-zA-Z][\w.]*)(\s*)([-.~=!@#$%^&*_+|,<>?/\\:']?:)",
72 bygroups(Name.Variable, Whitespace, Operator)),
73 # Functions
74 (r"\{", Punctuation, "functions"),
75 # Parentheses
76 (r"\(", Punctuation, "parentheses"),
77 # Brackets
78 (r"\[", Punctuation, "brackets"),
79 # Errors
80 (r"'`([a-zA-Z][\w.]*)?", Name.Exception),
81 # File Symbols
82 (r"`:([a-zA-Z/][\w./]*)?", String.Symbol),
83 # Symbols
84 (r"`([a-zA-Z][\w.]*)?", String.Symbol),
85 # Numbers
86 include("numbers"),
87 # Variable Names
88 (r"[a-zA-Z][\w.]*", Name),
89 # Operators
90 (r"[-=+*#$%@!~^&:.,<>'\\|/?_]", Operator),
91 # Punctuation
92 (r";", Punctuation),
93 ],
94 "functions": [
95 include("root"),
96 (r"\}", Punctuation, "#pop"),
97 ],
98 "parentheses": [
99 include("root"),
100 (r"\)", Punctuation, "#pop"),
101 ],
102 "brackets": [
103 include("root"),
104 (r"\]", Punctuation, "#pop"),
105 ],
106 "numbers": [
107 # Binary Values
108 (r"[01]+b", Number.Bin),
109 # Nulls/Infinities
110 (r"0[nNwW][cefghijmndzuvtp]?", Number),
111 # Timestamps
112 ((r"(?:[0-9]{4}[.][0-9]{2}[.][0-9]{2}|[0-9]+)"
113 "D(?:[0-9](?:[0-9](?::[0-9]{2}"
114 "(?::[0-9]{2}(?:[.][0-9]*)?)?)?)?)?"), Literal.Date),
115 # Datetimes
116 ((r"[0-9]{4}[.][0-9]{2}"
117 "(?:m|[.][0-9]{2}(?:T(?:[0-9]{2}:[0-9]{2}"
118 "(?::[0-9]{2}(?:[.][0-9]*)?)?)?)?)"), Literal.Date),
119 # Times
120 (r"[0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:[.][0-9]{1,3})?)?",
121 Literal.Date),
122 # GUIDs
123 (r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
124 Number.Hex),
125 # Byte Vectors
126 (r"0x[0-9a-fA-F]+", Number.Hex),
127 # Floats
128 (r"([0-9]*[.]?[0-9]+|[0-9]+[.]?[0-9]*)[eE][+-]?[0-9]+[ef]?",
129 Number.Float),
130 (r"([0-9]*[.][0-9]+|[0-9]+[.][0-9]*)[ef]?", Number.Float),
131 (r"[0-9]+[ef]", Number.Float),
132 # Characters
133 (r"[0-9]+c", Number),
134 # Integers
135 (r"[0-9]+[ihtuv]", Number.Integer),
136 # Long Integers
137 (r"[0-9]+[jnp]?", Number.Integer.Long),
138 ],
139 "comments": [
140 (r"[^\\]+", Comment.Multiline),
141 (r"^\\", Comment.Multiline, "#pop"),
142 (r"\\", Comment.Multiline),
143 ],
144 "strings": [
145 (r'[^"\\]+', String.Double),
146 (r"\\.", String.Escape),
147 (r'"', String.Double, "#pop"),
148 ],
149 }
152class QLexer(KLexer):
153 """
154 For `Q <https://code.kx.com/>`_ source code.
156 .. versionadded:: 2.12
157 """
159 name = "Q"
160 aliases = ["q"]
161 filenames = ["*.q"]
163 tokens = {
164 "root": [
165 (words(("aj", "aj0", "ajf", "ajf0", "all", "and", "any", "asc",
166 "asof", "attr", "avgs", "ceiling", "cols", "count", "cross",
167 "csv", "cut", "deltas", "desc", "differ", "distinct", "dsave",
168 "each", "ej", "ema", "eval", "except", "fby", "fills", "first",
169 "fkeys", "flip", "floor", "get", "group", "gtime", "hclose",
170 "hcount", "hdel", "hsym", "iasc", "idesc", "ij", "ijf",
171 "inter", "inv", "key", "keys", "lj", "ljf", "load", "lower",
172 "lsq", "ltime", "ltrim", "mavg", "maxs", "mcount", "md5",
173 "mdev", "med", "meta", "mins", "mmax", "mmin", "mmu", "mod",
174 "msum", "neg", "next", "not", "null", "or", "over", "parse",
175 "peach", "pj", "prds", "prior", "prev", "rand", "rank", "ratios",
176 "raze", "read0", "read1", "reciprocal", "reval", "reverse",
177 "rload", "rotate", "rsave", "rtrim", "save", "scan", "scov",
178 "sdev", "set", "show", "signum", "ssr", "string", "sublist",
179 "sums", "sv", "svar", "system", "tables", "til", "trim", "txf",
180 "type", "uj", "ujf", "ungroup", "union", "upper", "upsert",
181 "value", "view", "views", "vs", "where", "wj", "wj1", "ww",
182 "xasc", "xbar", "xcol", "xcols", "xdesc", "xgroup", "xkey",
183 "xlog", "xprev", "xrank"),
184 suffix=r"\b"), Name.Builtin,
185 ),
186 inherit,
187 ],
188 }