summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-04-24 10:43:05 -0400
committerTim Hatch <tim@timhatch.com>2014-04-24 10:43:05 -0400
commit9b2efddd8f4d31545dd410688fa227bf79dbd919 (patch)
treeb46796018d38b0454ab84639ed6dac04bd4133a2
parent4e5d0a59b65ac8eb9f0050c5a818b3444eb52092 (diff)
downloadpygments-9b2efddd8f4d31545dd410688fa227bf79dbd919.tar.gz
Fix cypher lexer to match example file
-rw-r--r--pygments/lexers/graph.py26
-rw-r--r--tests/examplefiles/test.cyp6
2 files changed, 25 insertions, 7 deletions
diff --git a/pygments/lexers/graph.py b/pygments/lexers/graph.py
index f9e8f3a7..186af92f 100644
--- a/pygments/lexers/graph.py
+++ b/pygments/lexers/graph.py
@@ -11,9 +11,9 @@
import re
-from pygments.lexer import RegexLexer, include, bygroups
+from pygments.lexer import RegexLexer, include, bygroups, using, this
from pygments.token import Keyword, Punctuation, Text, Comment, Operator, Name,\
-String, Number, Generic
+ String, Number, Generic, Whitespace
__all__ = ['CypherLexer']
@@ -31,6 +31,7 @@ class CypherLexer(RegexLexer):
name = 'Cypher'
aliases = ['cypher']
filenames = ['*.cyp','*.cypher']
+
flags = re.MULTILINE | re.IGNORECASE
tokens = {
@@ -39,7 +40,9 @@ class CypherLexer(RegexLexer):
include('keywords'),
include('clauses'),
include('relations'),
- include('strings')
+ include('strings'),
+ include('whitespace'),
+ include('barewords'),
],
'comment': [
(r'^.*//.*\n', Comment.Single),
@@ -55,12 +58,23 @@ class CypherLexer(RegexLexer):
Keyword),
],
'relations': [
- (r'-->|-\[.*\]->|<-\[.*\]-|<--|\[|\]', Operator),
+ (r'(-\[)(.*?)(\]->)', bygroups(Operator, using(this), Operator)),
+ (r'(<-\[)(.*?)(\]-)', bygroups(Operator, using(this), Operator)),
+ (r'-->|<--|\[|\]', Operator),
(r'<|>|<>|=|<=|=>|\(|\)|\||:|,|;', Punctuation),
+ (r'[.*{}]', Punctuation),
],
'strings': [
- (r'\".*\"', String),
- ]
+ (r'"(?:\\[tbnrf\'\"\\]|[^\\"])*"', String),
+ (r'`(?:``|[^`])+`', Name.Variable),
+ ],
+ 'whitespace': [
+ (r'\s+', Whitespace),
+ ],
+ 'barewords': [
+ (r'[a-z][a-zA-Z0-9_]*', Name),
+ (r'\d+', Number),
+ ],
}
diff --git a/tests/examplefiles/test.cyp b/tests/examplefiles/test.cyp
index 7ac6f85c..37465a4d 100644
--- a/tests/examplefiles/test.cyp
+++ b/tests/examplefiles/test.cyp
@@ -66,7 +66,6 @@ MATCH (a)-[:ACTED_IN]->(m)
WITH a,count(m) as Movies
RETURN a.name as Actor, Movies ORDER BY Movies;
---does not work
START keanu=node:node_auto_index(name="Keanu Reeves"),actor
MATCH past=(keanu)-[:ACTED_IN]->()<-[:ACTED_IN]-(),
actors=(actor)-[:ACTED_IN]->()
@@ -117,3 +116,8 @@ MATCH p=shortestPath((charlize)-[:KNOWS*]->(bacon))
RETURN extract(n in nodes(p) | n.name)[1];
START actors=node:
+
+MATCH (alice)-[:`REALLY LIKES`]->(bob)
+MATCH (alice)-[:`REALLY ``LIKES```]->(bob)
+myFancyIdentifier.`(weird property name)`
+"string\t\n\b\f\\\''\""