Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/gsql.py: 100%
11 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.gsql
3 ~~~~~~~~~~~~~~~~~~~~
5 Lexers for TigerGraph GSQL graph query language
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11import re
13from pygments.lexer import RegexLexer, include, bygroups, using, this, words
14from pygments.token import Keyword, Punctuation, Comment, Operator, Name, \
15 String, Number, Whitespace
17__all__ = ["GSQLLexer"]
20class GSQLLexer(RegexLexer):
22 """
23 For GSQL queries (version 3.x).
25 .. versionadded:: 2.10
26 """
28 name = 'GSQL'
29 url = 'https://docs.tigergraph.com/dev/gsql-ref'
30 aliases = ['gsql']
31 filenames = ['*.gsql']
33 flags = re.MULTILINE | re.IGNORECASE
35 tokens = {
36 'root': [
37 include('comment'),
38 include('keywords'),
39 include('clauses'),
40 include('accums'),
41 include('relations'),
42 include('strings'),
43 include('whitespace'),
44 include('barewords'),
45 include('operators'),
46 ],
47 'comment': [
48 (r'\#.*', Comment.Single),
49 (r'/\*(.|\n)*?\*/', Comment.Multiline),
50 ],
51 'keywords': [
52 (words((
53 'ACCUM', 'AND', 'ANY', 'API', 'AS', 'ASC', 'AVG', 'BAG', 'BATCH',
54 'BETWEEN', 'BOOL', 'BOTH', 'BREAK', 'BY', 'CASE', 'CATCH', 'COALESCE',
55 'COMPRESS', 'CONTINUE', 'COUNT', 'CREATE', 'DATETIME', 'DATETIME_ADD',
56 'DATETIME_SUB', 'DELETE', 'DESC', 'DISTRIBUTED', 'DO', 'DOUBLE',
57 'EDGE', 'ELSE', 'END', 'ESCAPE', 'EXCEPTION', 'FALSE', 'FILE',
58 'FILTER', 'FLOAT', 'FOREACH', 'FOR', 'FROM', 'GRAPH', 'GROUP',
59 'GSQL_INT_MAX', 'GSQL_INT_MIN', 'GSQL_UINT_MAX', 'HAVING', 'IF',
60 'IN', 'INSERT', 'INT', 'INTERPRET', 'INTERSECT', 'INTERVAL', 'INTO',
61 'IS', 'ISEMPTY', 'JSONARRAY', 'JSONOBJECT', 'LASTHOP', 'LEADING',
62 'LIKE', 'LIMIT', 'LIST', 'LOAD_ACCUM', 'LOG', 'MAP', 'MATCH', 'MAX',
63 'MIN', 'MINUS', 'NOT', 'NOW', 'NULL', 'OFFSET', 'OR', 'ORDER', 'PATH',
64 'PER', 'PINNED', 'POST_ACCUM', 'POST-ACCUM', 'PRIMARY_ID', 'PRINT',
65 'QUERY', 'RAISE', 'RANGE', 'REPLACE', 'RESET_COLLECTION_ACCUM',
66 'RETURN', 'RETURNS', 'RUN', 'SAMPLE', 'SELECT', 'SELECT_VERTEX',
67 'SET', 'SRC', 'STATIC', 'STRING', 'SUM', 'SYNTAX', 'TARGET',
68 'TAGSTGT', 'THEN', 'TO', 'TO_CSV', 'TO_DATETIME', 'TRAILING',
69 'TRIM', 'TRUE', 'TRY', 'TUPLE', 'TYPEDEF', 'UINT', 'UNION', 'UPDATE',
70 'VALUES', 'VERTEX', 'WHEN', 'WHERE', 'WHILE', 'WITH'),
71 prefix=r'(?<!\.)', suffix=r'\b'), Keyword),
72 ],
73 'clauses': [
74 (words(('accum', 'having', 'limit', 'order', 'postAccum', 'sample', 'where')),
75 Name.Builtin),
76 ],
77 'accums': [
78 (words(('andaccum', 'arrayaccum', 'avgaccum', 'bagaccum', 'bitwiseandaccum',
79 'bitwiseoraccum', 'groupbyaccum', 'heapaccum', 'listaccum',
80 'MapAccum', 'maxaccum', 'minaccum', 'oraccum', 'setaccum',
81 'sumaccum')), Name.Builtin),
82 ],
83 'relations': [
84 (r'(-\s?)(\(.*\:\w?\))(\s?-)', bygroups(Operator, using(this), Operator)),
85 (r'->|<-', Operator),
86 (r'[.*{}\[\]\<\>\_]', Punctuation),
87 ],
88 'strings': [
89 (r'"([^"\\]|\\.)*"', String),
90 (r'@{1,2}\w+', Name.Variable),
91 ],
92 'whitespace': [
93 (r'\s+', Whitespace),
94 ],
95 'barewords': [
96 (r'[a-z]\w*', Name),
97 (r'(\d+\.\d+|\d+)', Number),
98 ],
99 'operators': [
100 (r'\$|[^0-9|\/|\-](\-\=|\+\=|\*\=|\\\=|\=|\=\=|\=\=\=|'
101 r'\+|\-|\*|\\|\+\=|\>|\<)[^\>|\/]', Operator),
102 (r'(\||\(|\)|\,|\;|\=|\-|\+|\*|\/|\>|\<|\:)', Operator),
103 ],
104 }