|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.graph |
|
4 ~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for graph query languages. |
|
7 |
|
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include, bygroups, using, this |
|
15 from pygments.token import Keyword, Punctuation, Comment, Operator, Name,\ |
|
16 String, Number, Whitespace |
|
17 |
|
18 |
|
19 __all__ = ['CypherLexer'] |
|
20 |
|
21 |
|
22 class CypherLexer(RegexLexer): |
|
23 """ |
|
24 For `Cypher Query Language |
|
25 <http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html>`_ |
|
26 |
|
27 For the Cypher version in Neo4J 2.0 |
|
28 |
|
29 .. versionadded:: 2.0 |
|
30 """ |
|
31 name = 'Cypher' |
|
32 aliases = ['cypher'] |
|
33 filenames = ['*.cyp', '*.cypher'] |
|
34 |
|
35 flags = re.MULTILINE | re.IGNORECASE |
|
36 |
|
37 tokens = { |
|
38 'root': [ |
|
39 include('comment'), |
|
40 include('keywords'), |
|
41 include('clauses'), |
|
42 include('relations'), |
|
43 include('strings'), |
|
44 include('whitespace'), |
|
45 include('barewords'), |
|
46 ], |
|
47 'comment': [ |
|
48 (r'^.*//.*\n', Comment.Single), |
|
49 ], |
|
50 'keywords': [ |
|
51 (r'(create|order|match|limit|set|skip|start|return|with|where|' |
|
52 r'delete|foreach|not|by)\b', Keyword), |
|
53 ], |
|
54 'clauses': [ |
|
55 # TODO: many missing ones, see http://docs.neo4j.org/refcard/2.0/ |
|
56 (r'(all|any|as|asc|create|create\s+unique|delete|' |
|
57 r'desc|distinct|foreach|in|is\s+null|limit|match|none|' |
|
58 r'order\s+by|return|set|skip|single|start|union|where|with)\b', |
|
59 Keyword), |
|
60 ], |
|
61 'relations': [ |
|
62 (r'(-\[)(.*?)(\]->)', bygroups(Operator, using(this), Operator)), |
|
63 (r'(<-\[)(.*?)(\]-)', bygroups(Operator, using(this), Operator)), |
|
64 (r'-->|<--|\[|\]', Operator), |
|
65 (r'<|>|<>|=|<=|=>|\(|\)|\||:|,|;', Punctuation), |
|
66 (r'[.*{}]', Punctuation), |
|
67 ], |
|
68 'strings': [ |
|
69 (r'"(?:\\[tbnrf\'"\\]|[^\\"])*"', String), |
|
70 (r'`(?:``|[^`])+`', Name.Variable), |
|
71 ], |
|
72 'whitespace': [ |
|
73 (r'\s+', Whitespace), |
|
74 ], |
|
75 'barewords': [ |
|
76 (r'[a-z]\w*', Name), |
|
77 (r'\d+', Number), |
|
78 ], |
|
79 } |