Skip to content

Commit eca4709

Browse files
committed
a working version
1 parent fae104f commit eca4709

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3748
-3598
lines changed

Cypher.g4

Lines changed: 50 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,80 @@
11
grammar Cypher;
22

3-
cypher : SP? statement ( SP? ';' )? SP? ;
3+
cypher : singleQuery ( ';' )? ;
44

5-
statement : singleQuery ;
6-
7-
singleQuery : clause ( SP? clause )* ;
5+
singleQuery : clause ( clause )* ;
86

97
clause : match
108
| return1
119
;
1210

13-
match : MATCH SP? pattern ( SP? where )? ;
14-
15-
return1 : RETURN SP returnBody ;
16-
17-
returnBody : returnItems ;
18-
19-
returnItems : ( ( SP? ',' SP? returnItem )* )
20-
| ( returnItem ( SP? ',' SP? returnItem )* )
21-
;
22-
23-
returnItem : expression
24-
;
11+
match : MATCH pattern ( WHERE expression )? ;
2512

26-
where : WHERE SP expression ;
13+
return1 : RETURN ( expression ( ',' expression )* ) ;
2714

28-
pattern : patternPart ( SP? ',' SP? patternPart )* ;
15+
pattern : patternPart ( ',' patternPart )* ;
2916

30-
patternPart : ( variable SP? '=' SP? anonymousPatternPart )
31-
| anonymousPatternPart
17+
patternPart : ( variable '=' patternElement )
18+
| patternElement
3219
;
3320

34-
anonymousPatternPart : patternElement ;
35-
36-
patternElement : ( nodePattern ( SP? patternElementChain )* )
21+
patternElement : ( nodePattern ( patternElementChain )* )
3722
| ( '(' patternElement ')' )
3823
;
3924

40-
nodePattern : '(' SP? ( variable SP? )? ( nodeLabels SP? )? ( properties SP? )? ')' ;
25+
patternElementChain : relationshipPattern nodePattern ;
4126

42-
patternElementChain : relationshipPattern SP? nodePattern ;
27+
nodePattern : '(' ( variable )? ( nodeLabels )? ( properties )? ')' ;
4328

44-
relationshipPattern : ( leftArrowHead SP? dash SP? relationshipDetail? SP? dash SP? rightArrowHead )
45-
| ( leftArrowHead SP? dash SP? relationshipDetail? SP? dash )
46-
| ( dash SP? relationshipDetail? SP? dash SP? rightArrowHead )
47-
| ( dash SP? relationshipDetail? SP? dash )
29+
relationshipPattern : ( leftArrowHead dash relationshipDetail? dash rightArrowHead )
30+
| ( leftArrowHead dash relationshipDetail? dash )
31+
| ( dash relationshipDetail? dash rightArrowHead )
32+
| ( dash relationshipDetail? dash )
4833
;
4934

50-
relationshipDetail : '[' SP? ( variable SP? )? ( relationshipTypes SP? )? rangeLiteral? ( properties SP? )? ']' ;
35+
relationshipDetail : '[' ( variable )? ( relationshipTypes )? rangeLiteral? ( properties )? ']' ;
5136

5237
properties : mapLiteral
53-
| parameter
5438
;
5539

56-
relationshipTypes : ':' SP? relTypeName ( SP? '|' ':'? SP? relTypeName )* ;
40+
relationshipTypes : ':' relTypeName ( '|' ':'? relTypeName )* ;
5741

58-
nodeLabels : nodeLabel ( SP? nodeLabel )* ;
42+
nodeLabels : (':' labelName) ( ':' labelName )* ;
5943

60-
nodeLabel : ':' SP? labelName ;
61-
62-
rangeLiteral : '*' SP? ( integerLiteral SP? )? ( '..' SP? ( integerLiteral SP? )? )? ;
44+
rangeLiteral : '*' ( integerLiteral )? ( '..' ( integerLiteral )? )? ;
6345

6446
labelName : symbolicName ;
6547

6648
relTypeName : symbolicName ;
6749

68-
expression : expression10 ;
50+
expression : exp_not ( AND exp_not )* ;
51+
52+
53+
//exp_not : ( NOT )* exp_arithmatic ;
54+
exp_not : ( NOT )? exp_arithmatic ;
55+
6956

70-
expression10 : exp_not ( SP AND SP exp_not )* ;
57+
//exp_arithmatic : exp_binary ( partialComparisonExpression )* ;
58+
exp_arithmatic : exp_binary ( partialComparisonExpression )? ;
7159

72-
exp_not : ( NOT SP? )* exp_arithmatic ;
60+
exp_binary : exp_muldiv ( ( '+' exp_muldiv ) | ( '-' exp_muldiv ) )* ;
7361

74-
exp_arithmatic : exp_binary ( SP? partialComparisonExpression )* ;
62+
exp_muldiv : exp_xor ( ( '*' exp_xor ) | ( '/' exp_xor ) | ( '%' exp_xor ) )* ;
7563

76-
exp_binary : exp_addsub ( ( SP? '+' SP? exp_addsub ) | ( SP? '-' SP? exp_addsub ) )* ;
64+
exp_xor : exp_unary ( '^' exp_unary )* ;
7765

78-
exp_addsub : exp_muldivmod ( ( SP? '*' SP? exp_muldivmod ) | ( SP? '/' SP? exp_muldivmod ) | ( SP? '%' SP? exp_muldivmod ) )* ;
66+
exp_unary : ( ( '+' | '-' ) )* exp_basic ;
7967

80-
exp_muldivmod : exp_xor ( SP? '^' SP? exp_xor )* ;
8168

82-
exp_xor : ( ( '+' | '-' ) SP? )* exp_unary ;
69+
// Remove nested array visit. Only support list visiting for constants.
70+
//exp_basic : expression2 ( ( '[' expression ']' ) | ( '[' expression? '..' expression? ']' ) )*;
71+
exp_basic : expression2 ( ( '[' expression ']' ) | ( '[' expression? '..' expression? ']' ) )?;
8372

84-
exp_unary : expression2 ( ( SP? '[' expression ']' ) | ( SP? '[' expression? '..' expression? ']' ) );
8573

86-
expression2 : atom ( SP? ( propertyLookup | nodeLabels ) )* ;
74+
expression2 : atom ( nodeLabels | propertyLookup )? ;
8775

8876
atom : literal
89-
| parameter
90-
| ( COUNT SP? '(' SP? '*' SP? ')' )
77+
| ( COUNT '(' '*' ')' )
9178
| relationshipsPattern
9279
| parenthesizedExpression
9380
| variable
@@ -112,26 +99,24 @@ booleanLiteral : TRUE
11299
| FALSE
113100
;
114101

115-
listLiteral : '[' SP? ( expression SP? ( ',' SP? expression SP? )* )? ']' ;
102+
listLiteral : '[' ( expression ( ',' expression )* )? ']' ;
116103

117-
mapLiteral : '{' SP? ( propertyKeyName SP? ':' SP? expression SP? ( ',' SP? propertyKeyName SP? ':' SP? expression SP? )* )? '}' ;
104+
mapLiteral : '{' ( propertyKeyName ':' expression ( ',' propertyKeyName ':' expression )* )? '}' ;
118105

119-
partialComparisonExpression : ( '=' SP? exp_binary )
120-
| ( '<>' SP? exp_binary )
121-
| ( '!=' SP? exp_binary )
122-
| ( '<' SP? exp_binary )
123-
| ( '>' SP? exp_binary )
124-
| ( '<=' SP? exp_binary )
125-
| ( '>=' SP? exp_binary )
106+
partialComparisonExpression : ( '=' exp_binary )
107+
| ( '<>' exp_binary )
108+
| ( '!=' exp_binary )
109+
| ( '<' exp_binary )
110+
| ( '>' exp_binary )
111+
| ( '<=' exp_binary )
112+
| ( '>=' exp_binary )
126113
;
127114

128-
parenthesizedExpression : '(' SP? expression SP? ')' ;
115+
parenthesizedExpression : '(' expression ')' ;
129116

130-
parameter : '$' ( symbolicName | DecimalInteger ) ;
117+
relationshipsPattern : nodePattern ( patternElementChain )+ ;
131118

132-
relationshipsPattern : nodePattern ( SP? patternElementChain )+ ;
133-
134-
propertyLookup : '.' SP? ( propertyKeyName ) ;
119+
propertyLookup : '.' ( propertyKeyName ) ;
135120

136121
propertyKeyName : symbolicName ;
137122

@@ -178,7 +163,6 @@ symbolicName : UnescapedSymbolicName
178163
| MATCH
179164
| RETURN
180165
| WHERE
181-
| OR
182166
| AND
183167
| NOT
184168
| TRUE
@@ -188,8 +172,6 @@ COUNT : ( 'C' | 'c' ) ( 'O' | 'o' ) ( 'U' | 'u' ) ( 'N' | 'n' ) ( 'T' | 't' ) ;
188172

189173
NULL : ( 'N' | 'n' ) ( 'U' | 'u' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ;
190174

191-
OR : ( 'O' | 'o' ) ( 'R' | 'r' ) ;
192-
193175
MATCH : ( 'M' | 'm' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'C' | 'c' ) ( 'H' | 'h' ) ;
194176

195177
RETURN : ( 'R' | 'r' ) ( 'E' | 'e' ) ( 'T' | 't' ) ( 'U' | 'u' ) ( 'R' | 'r' ) ( 'N' | 'n' ) ;
@@ -235,7 +217,7 @@ IdentifierPart : ID_Continue
235217
/**
236218
* Any character except "`", enclosed within `backticks`. Backticks are escaped with double backticks. */
237219

238-
SP : ( WHITESPACE )+ ;
220+
SP : ( WHITESPACE )+ -> skip;
239221

240222
WHITESPACE : SPACE
241223
| TAB
@@ -273,6 +255,8 @@ Comment : ( '/*' ( Comment_1 | ( '*' Comment_2 ) )* '*/' )
273255
| ( '//' ( Comment_3 )* CR? ( LF | EOF ) )
274256
;
275257

258+
259+
276260
leftArrowHead : '<'
277261
;
278262

Cypher.tokens

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,29 @@ T__21=22
2323
T__22=23
2424
T__23=24
2525
T__24=25
26-
T__25=26
27-
StringLiteral=27
28-
DecimalInteger=28
29-
Digit=29
30-
NonZeroDigit=30
31-
NonZeroOctDigit=31
32-
OctDigit=32
33-
ZeroDigit=33
34-
RegularDecimalReal=34
35-
COUNT=35
36-
NULL=36
37-
OR=37
38-
MATCH=38
39-
RETURN=39
40-
WHERE=40
41-
AND=41
42-
NOT=42
43-
TRUE=43
44-
FALSE=44
45-
UnescapedSymbolicName=45
46-
IdentifierStart=46
47-
IdentifierPart=47
48-
SP=48
49-
WHITESPACE=49
50-
Comment=50
26+
StringLiteral=26
27+
DecimalInteger=27
28+
Digit=28
29+
NonZeroDigit=29
30+
NonZeroOctDigit=30
31+
OctDigit=31
32+
ZeroDigit=32
33+
RegularDecimalReal=33
34+
COUNT=34
35+
NULL=35
36+
MATCH=36
37+
RETURN=37
38+
WHERE=38
39+
AND=39
40+
NOT=40
41+
TRUE=41
42+
FALSE=42
43+
UnescapedSymbolicName=43
44+
IdentifierStart=44
45+
IdentifierPart=45
46+
SP=46
47+
WHITESPACE=47
48+
Comment=48
5149
';'=1
5250
','=2
5351
'='=3
@@ -72,6 +70,5 @@ Comment=50
7270
'>'=22
7371
'<='=23
7472
'>='=24
75-
'$'=25
76-
'.'=26
77-
'0'=33
73+
'.'=25
74+
'0'=32

0 commit comments

Comments
 (0)