Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/graph.py: 100%
11 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.graph
3 ~~~~~~~~~~~~~~~~~~~~~
5 Lexers for graph query languages.
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
18__all__ = ['CypherLexer']
21class CypherLexer(RegexLexer):
22 """
23 For Cypher Query Language
25 For the Cypher version in Neo4j 3.3
27 .. versionadded:: 2.0
28 """
29 name = 'Cypher'
30 url = 'https://neo4j.com/docs/developer-manual/3.3/cypher/'
31 aliases = ['cypher']
32 filenames = ['*.cyp', '*.cypher']
34 flags = re.MULTILINE | re.IGNORECASE
36 tokens = {
37 'root': [
38 include('comment'),
39 include('clauses'),
40 include('keywords'),
41 include('relations'),
42 include('strings'),
43 include('whitespace'),
44 include('barewords'),
45 ],
46 'comment': [
47 (r'^.*//.*$', Comment.Single),
48 ],
49 'keywords': [
50 (r'(create|order|match|limit|set|skip|start|return|with|where|'
51 r'delete|foreach|not|by|true|false)\b', Keyword),
52 ],
53 'clauses': [
54 # based on https://neo4j.com/docs/cypher-refcard/3.3/
55 (r'(create)(\s+)(index|unique)\b',
56 bygroups(Keyword, Whitespace, Keyword)),
57 (r'(drop)(\s+)(contraint|index)(\s+)(on)\b',
58 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
59 (r'(ends)(\s+)(with)\b',
60 bygroups(Keyword, Whitespace, Keyword)),
61 (r'(is)(\s+)(node)(\s+)(key)\b',
62 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
63 (r'(is)(\s+)(null|unique)\b',
64 bygroups(Keyword, Whitespace, Keyword)),
65 (r'(load)(\s+)(csv)(\s+)(from)\b',
66 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
67 (r'(on)(\s+)(match|create)\b',
68 bygroups(Keyword, Whitespace, Keyword)),
69 (r'(optional)(\s+)(match)\b',
70 bygroups(Keyword, Whitespace, Keyword)),
71 (r'(order)(\s+)(by)\b',
72 bygroups(Keyword, Whitespace, Keyword)),
73 (r'(starts)(\s+)(with)\b',
74 bygroups(Keyword, Whitespace, Keyword)),
75 (r'(union)(\s+)(all)\b',
76 bygroups(Keyword, Whitespace, Keyword)),
77 (r'(using)(\s+)(periodic)(\s+)(commit)\b',
78 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
79 (words((
80 'all', 'any', 'as', 'asc', 'ascending', 'assert', 'call', 'case', 'create',
81 'delete', 'desc', 'descending', 'distinct', 'end', 'fieldterminator',
82 'foreach', 'in', 'limit', 'match', 'merge', 'none', 'not', 'null',
83 'remove', 'return', 'set', 'skip', 'single', 'start', 'then', 'union',
84 'unwind', 'yield', 'where', 'when', 'with'), suffix=r'\b'), Keyword),
85 ],
86 'relations': [
87 (r'(-\[)(.*?)(\]->)', bygroups(Operator, using(this), Operator)),
88 (r'(<-\[)(.*?)(\]-)', bygroups(Operator, using(this), Operator)),
89 (r'(-\[)(.*?)(\]-)', bygroups(Operator, using(this), Operator)),
90 (r'-->|<--|\[|\]', Operator),
91 (r'<|>|<>|=|<=|=>|\(|\)|\||:|,|;', Punctuation),
92 (r'[.*{}]', Punctuation),
93 ],
94 'strings': [
95 (r'"(?:\\[tbnrf\'"\\]|[^\\"])*"', String),
96 (r'`(?:``|[^`])+`', Name.Variable),
97 ],
98 'whitespace': [
99 (r'\s+', Whitespace),
100 ],
101 'barewords': [
102 (r'[a-z]\w*', Name),
103 (r'\d+', Number),
104 ],
105 }