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