@@ -19,64 +19,6 @@ const (
19
19
PropertyExprType ExpressionType = iota
20
20
)
21
21
22
- // ExpressionVisitor a visitor of expression
23
- type ExpressionVisitor interface {
24
- OnEnterPropertyOrLabelsExpression (e query.QueryPropertyOrLabelsExpression ) error
25
- OnExitPropertyOrLabelsExpression (e query.QueryPropertyOrLabelsExpression ) error
26
-
27
- OnEnterStringListNullOperatorExpression (e query.QueryStringListNullOperatorExpression ) error
28
- OnExitStringListNullOperatorExpression (e query.QueryStringListNullOperatorExpression ) error
29
-
30
- OnVariable (name string ) error
31
- OnVariablePropertiesPath (propertiesPath []string ) error
32
-
33
- OnStringLiteral (value string ) error
34
- OnDoubleLiteral (value float64 ) error
35
- OnIntegerLiteral (value int64 ) error
36
- OnBooleanLiteral (value bool ) error
37
-
38
- OnEnterFunctionInvocation (name string , distinct bool ) error
39
- OnExitFunctionInvocation (name string , distinct bool ) error
40
-
41
- OnEnterParenthesizedExpression () error
42
- OnExitParenthesizedExpression () error
43
-
44
- OnStringOperator (operator query.StringOperator ) error
45
-
46
- OnEnterUnaryExpression () error
47
- OnExitUnaryExpression () error
48
-
49
- OnEnterPowerOfExpression () error
50
- OnExitPowerOfExpression () error
51
-
52
- OnEnterMultipleDivideModuloExpression () error
53
- OnExitMultipleDivideModuloExpression () error
54
- OnMultiplyDivideModuloOperator (operator query.MultiplyDivideModuloOperator ) error
55
-
56
- OnEnterAddOrSubtractExpression () error
57
- OnExitAddOrSubtractExpression () error
58
- OnAddOrSubtractOperator (operator query.AddOrSubtractOperator ) error
59
-
60
- OnEnterComparisonExpression () error
61
- OnExitComparisonExpression () error
62
- OnComparisonOperator (operator query.ComparisonOperator ) error
63
-
64
- OnEnterNotExpression (not bool ) error
65
- OnExitNotExpression (not bool ) error
66
-
67
- OnEnterAndExpression () error
68
- OnExitAndExpression () error
69
-
70
- OnEnterXorExpression () error
71
- OnExitXorExpression () error
72
-
73
- OnEnterOrExpression () error
74
- OnExitOrExpression () error
75
-
76
- OnEnterExpression () error
77
- OnExitExpression () error
78
- }
79
-
80
22
// ExpressionParser is a parser of expression
81
23
type ExpressionParser struct {
82
24
visitor ExpressionVisitor
@@ -168,13 +110,30 @@ func (ep *ExpressionParser) ParsePropertyOrLabelsExpression(q *query.QueryProper
168
110
}
169
111
} else if q .Atom .RelationshipsPattern != nil {
170
112
parser := NewPatternParser (ep .queryGraph )
113
+ // Parse the pattern to push the nodes and relations into the query graph
171
114
err := parser .ParseRelationshipsPattern (
172
115
q .Atom .RelationshipsPattern ,
173
116
Scope {Context : WhereContext , ID : ep .patternIDGenerator })
174
117
if err != nil {
175
118
return err
176
119
}
177
- ep .patternIDGenerator ++
120
+ defer func () { ep .patternIDGenerator ++ }()
121
+
122
+ err = ep .visitor .OnEnterRelationshipsPattern (* q .Atom .RelationshipsPattern , ep .patternIDGenerator )
123
+ if err != nil {
124
+ return err
125
+ }
126
+
127
+ err = ep .ParseRelationshipsPattern (q .Atom .RelationshipsPattern )
128
+ if err != nil {
129
+ return err
130
+ }
131
+
132
+ err = ep .visitor .OnExitRelationshipsPattern (* q .Atom .RelationshipsPattern , ep .patternIDGenerator )
133
+ if err != nil {
134
+ return err
135
+ }
136
+
178
137
} else {
179
138
return fmt .Errorf ("Unable to parse property or labels expression" )
180
139
}
@@ -187,6 +146,27 @@ func (ep *ExpressionParser) ParsePropertyOrLabelsExpression(q *query.QueryProper
187
146
return nil
188
147
}
189
148
149
+ // ParseRelationshipsPattern parse a query relationships pattern
150
+ func (ep * ExpressionParser ) ParseRelationshipsPattern (q * query.QueryRelationshipsPattern ) error {
151
+ err := ep .visitor .OnNodePattern (q .QueryNodePattern )
152
+ if err != nil {
153
+ return err
154
+ }
155
+
156
+ for _ , pc := range q .QueryPatternElementChains {
157
+ err = ep .visitor .OnRelationshipPattern (pc .RelationshipPattern )
158
+ if err != nil {
159
+ return err
160
+ }
161
+
162
+ err = ep .visitor .OnNodePattern (pc .NodePattern )
163
+ if err != nil {
164
+ return err
165
+ }
166
+ }
167
+ return nil
168
+ }
169
+
190
170
// ParseStringListNullOperatorExpression parse string list null operator expression
191
171
func (ep * ExpressionParser ) ParseStringListNullOperatorExpression (q * query.QueryStringListNullOperatorExpression ) error {
192
172
err := ep .visitor .OnEnterStringListNullOperatorExpression (* q )
0 commit comments