@@ -7,11 +7,15 @@ import (
7
7
"github.com/clems4ever/go-graphkb/internal/query"
8
8
)
9
9
10
+ // ExpressionType expression type
10
11
type ExpressionType int
11
12
12
13
const (
13
- NodeExprType ExpressionType = iota
14
- EdgeExprType ExpressionType = iota
14
+ // NodeExprType node expression type
15
+ NodeExprType ExpressionType = iota
16
+ // EdgeExprType edge expression type
17
+ EdgeExprType ExpressionType = iota
18
+ // PropertyExprType property expression type
15
19
PropertyExprType ExpressionType = iota
16
20
)
17
21
@@ -77,16 +81,21 @@ type ExpressionVisitor interface {
77
81
type ExpressionParser struct {
78
82
visitor ExpressionVisitor
79
83
queryGraph * QueryGraph
84
+
85
+ // This ID is incremented for every pattern found in the expression
86
+ patternIDGenerator int
80
87
}
81
88
82
89
// NewExpressionParser create a new instance of expression parser.
83
90
func NewExpressionParser (visitor ExpressionVisitor , queryGraph * QueryGraph ) * ExpressionParser {
84
91
return & ExpressionParser {
85
- visitor : visitor ,
86
- queryGraph : queryGraph ,
92
+ visitor : visitor ,
93
+ queryGraph : queryGraph ,
94
+ patternIDGenerator : 0 ,
87
95
}
88
96
}
89
97
98
+ // ParsePropertyOrLabelsExpression parse property or labels expression
90
99
func (ep * ExpressionParser ) ParsePropertyOrLabelsExpression (q * query.QueryPropertyOrLabelsExpression ) error {
91
100
err := ep .visitor .OnEnterPropertyOrLabelsExpression (* q )
92
101
if err != nil {
@@ -159,10 +168,13 @@ func (ep *ExpressionParser) ParsePropertyOrLabelsExpression(q *query.QueryProper
159
168
}
160
169
} else if q .Atom .RelationshipsPattern != nil {
161
170
parser := NewPatternParser (ep .queryGraph )
162
- err := parser .ParseRelationshipsPattern (q .Atom .RelationshipsPattern )
171
+ err := parser .ParseRelationshipsPattern (
172
+ q .Atom .RelationshipsPattern ,
173
+ Scope {Context : WhereContext , ID : ep .patternIDGenerator })
163
174
if err != nil {
164
175
return err
165
176
}
177
+ ep .patternIDGenerator ++
166
178
} else {
167
179
return fmt .Errorf ("Unable to parse property or labels expression" )
168
180
}
@@ -175,6 +187,7 @@ func (ep *ExpressionParser) ParsePropertyOrLabelsExpression(q *query.QueryProper
175
187
return nil
176
188
}
177
189
190
+ // ParseStringListNullOperatorExpression parse string list null operator expression
178
191
func (ep * ExpressionParser ) ParseStringListNullOperatorExpression (q * query.QueryStringListNullOperatorExpression ) error {
179
192
err := ep .visitor .OnEnterStringListNullOperatorExpression (* q )
180
193
if err != nil {
@@ -216,6 +229,7 @@ func (ep *ExpressionParser) ParseStringListNullOperatorExpression(q *query.Query
216
229
return nil
217
230
}
218
231
232
+ // ParseUnaryAddOrSubtractExpression parse unary add or subtract expression
219
233
func (ep * ExpressionParser ) ParseUnaryAddOrSubtractExpression (q * query.QueryUnaryAddOrSubtractExpression ) error {
220
234
err := ep .ParseStringListNullOperatorExpression (& q .StringListNullOperatorExpression )
221
235
if err != nil {
@@ -224,6 +238,7 @@ func (ep *ExpressionParser) ParseUnaryAddOrSubtractExpression(q *query.QueryUnar
224
238
return nil
225
239
}
226
240
241
+ // ParsePowerOfExpression parse power of expression
227
242
func (ep * ExpressionParser ) ParsePowerOfExpression (q * query.QueryPowerOfExpression ) error {
228
243
err := ep .visitor .OnEnterPowerOfExpression ()
229
244
if err != nil {
@@ -244,6 +259,7 @@ func (ep *ExpressionParser) ParsePowerOfExpression(q *query.QueryPowerOfExpressi
244
259
return nil
245
260
}
246
261
262
+ // ParseMultipleDivideModuloExpression parse multiple divide modulo expression
247
263
func (ep * ExpressionParser ) ParseMultipleDivideModuloExpression (q * query.QueryMultipleDivideModuloExpression ) error {
248
264
err := ep .visitor .OnEnterMultipleDivideModuloExpression ()
249
265
if err != nil {
@@ -273,6 +289,7 @@ func (ep *ExpressionParser) ParseMultipleDivideModuloExpression(q *query.QueryMu
273
289
return nil
274
290
}
275
291
292
+ // ParseAddOrSubtractExpression parse add or subtract expression
276
293
func (ep * ExpressionParser ) ParseAddOrSubtractExpression (q * query.QueryAddOrSubtractExpression ) error {
277
294
err := ep .visitor .OnEnterAddOrSubtractExpression ()
278
295
if err != nil {
@@ -301,6 +318,7 @@ func (ep *ExpressionParser) ParseAddOrSubtractExpression(q *query.QueryAddOrSubt
301
318
return nil
302
319
}
303
320
321
+ // ParseComparisonExpression parse comparison expression
304
322
func (ep * ExpressionParser ) ParseComparisonExpression (q * query.QueryComparisonExpression ) error {
305
323
err := ep .visitor .OnEnterComparisonExpression ()
306
324
if err != nil {
@@ -331,6 +349,7 @@ func (ep *ExpressionParser) ParseComparisonExpression(q *query.QueryComparisonEx
331
349
return nil
332
350
}
333
351
352
+ // ParseNotExpression parse not expression
334
353
func (ep * ExpressionParser ) ParseNotExpression (q * query.QueryNotExpression ) error {
335
354
err := ep .visitor .OnEnterNotExpression (q .Not )
336
355
if err != nil {
@@ -349,6 +368,7 @@ func (ep *ExpressionParser) ParseNotExpression(q *query.QueryNotExpression) erro
349
368
return err
350
369
}
351
370
371
+ // ParseXorExpression parse xor expression
352
372
func (ep * ExpressionParser ) ParseXorExpression (q * query.QueryXorExpression ) error {
353
373
err := ep .visitor .OnEnterXorExpression ()
354
374
if err != nil {
@@ -380,6 +400,7 @@ func (ep *ExpressionParser) ParseXorExpression(q *query.QueryXorExpression) erro
380
400
return nil
381
401
}
382
402
403
+ // ParseOrExpression parse or expression
383
404
func (ep * ExpressionParser ) ParseOrExpression (q * query.QueryOrExpression ) error {
384
405
var err error
385
406
err = ep .visitor .OnEnterOrExpression ()
@@ -401,6 +422,7 @@ func (ep *ExpressionParser) ParseOrExpression(q *query.QueryOrExpression) error
401
422
return nil
402
423
}
403
424
425
+ // ParseExpression parse expression
404
426
func (ep * ExpressionParser ) ParseExpression (q * query.QueryExpression ) error {
405
427
err := ep .visitor .OnEnterExpression ()
406
428
if err != nil {
@@ -416,75 +438,3 @@ func (ep *ExpressionParser) ParseExpression(q *query.QueryExpression) error {
416
438
}
417
439
return nil
418
440
}
419
-
420
- type ExpressionVisitorBase struct {}
421
-
422
- func (evb * ExpressionVisitorBase ) OnEnterRelationshipsPattern () error {
423
- return nil
424
- }
425
- func (evb * ExpressionVisitorBase ) OnExitRelationshipsPattern () error {
426
- return nil
427
- }
428
-
429
- func (evb * ExpressionVisitorBase ) OnEnterNodePattern () error {
430
- return nil
431
- }
432
- func (evb * ExpressionVisitorBase ) OnExitNodePattern () error {
433
- return nil
434
- }
435
- func (evb * ExpressionVisitorBase ) OnEnterPropertyOrLabelsExpression (e query.QueryPropertyOrLabelsExpression ) error {
436
- return nil
437
- }
438
- func (evb * ExpressionVisitorBase ) OnExitPropertyOrLabelsExpression (e query.QueryPropertyOrLabelsExpression ) error {
439
- return nil
440
- }
441
- func (evb * ExpressionVisitorBase ) OnEnterStringListNullOperatorExpression (e query.QueryStringListNullOperatorExpression ) error {
442
- return nil
443
- }
444
- func (evb * ExpressionVisitorBase ) OnExitStringListNullOperatorExpression (e query.QueryStringListNullOperatorExpression ) error {
445
- return nil
446
- }
447
- func (evb * ExpressionVisitorBase ) OnVariable (name string ) error { return nil }
448
- func (evb * ExpressionVisitorBase ) OnVariablePropertiesPath (propertiesPath []string ) error { return nil }
449
- func (evb * ExpressionVisitorBase ) OnStringLiteral (value string ) error { return nil }
450
- func (evb * ExpressionVisitorBase ) OnDoubleLiteral (value float64 ) error { return nil }
451
- func (evb * ExpressionVisitorBase ) OnIntegerLiteral (value int64 ) error { return nil }
452
- func (evb * ExpressionVisitorBase ) OnBooleanLiteral (value bool ) error { return nil }
453
- func (evb * ExpressionVisitorBase ) OnEnterFunctionInvocation (name string , distinct bool ) error {
454
- return nil
455
- }
456
- func (evb * ExpressionVisitorBase ) OnExitFunctionInvocation (name string , distinct bool ) error {
457
- return nil
458
- }
459
- func (evb * ExpressionVisitorBase ) OnEnterParenthesizedExpression () error { return nil }
460
- func (evb * ExpressionVisitorBase ) OnExitParenthesizedExpression () error { return nil }
461
- func (evb * ExpressionVisitorBase ) OnStringOperator (operator query.StringOperator ) error { return nil }
462
- func (evb * ExpressionVisitorBase ) OnEnterUnaryExpression () error { return nil }
463
- func (evb * ExpressionVisitorBase ) OnExitUnaryExpression () error { return nil }
464
- func (evb * ExpressionVisitorBase ) OnEnterPowerOfExpression () error { return nil }
465
- func (evb * ExpressionVisitorBase ) OnExitPowerOfExpression () error { return nil }
466
- func (evb * ExpressionVisitorBase ) OnEnterMultipleDivideModuloExpression () error { return nil }
467
- func (evb * ExpressionVisitorBase ) OnExitMultipleDivideModuloExpression () error { return nil }
468
- func (evb * ExpressionVisitorBase ) OnMultiplyDivideModuloOperator (operator query.MultiplyDivideModuloOperator ) error {
469
- return nil
470
- }
471
- func (evb * ExpressionVisitorBase ) OnEnterAddOrSubtractExpression () error { return nil }
472
- func (evb * ExpressionVisitorBase ) OnExitAddOrSubtractExpression () error { return nil }
473
- func (evb * ExpressionVisitorBase ) OnAddOrSubtractOperator (operator query.AddOrSubtractOperator ) error {
474
- return nil
475
- }
476
- func (evb * ExpressionVisitorBase ) OnEnterComparisonExpression () error { return nil }
477
- func (evb * ExpressionVisitorBase ) OnExitComparisonExpression () error { return nil }
478
- func (evb * ExpressionVisitorBase ) OnComparisonOperator (operator query.ComparisonOperator ) error {
479
- return nil
480
- }
481
- func (evb * ExpressionVisitorBase ) OnEnterNotExpression (not bool ) error { return nil }
482
- func (evb * ExpressionVisitorBase ) OnExitNotExpression (not bool ) error { return nil }
483
- func (evb * ExpressionVisitorBase ) OnEnterAndExpression () error { return nil }
484
- func (evb * ExpressionVisitorBase ) OnExitAndExpression () error { return nil }
485
- func (evb * ExpressionVisitorBase ) OnEnterXorExpression () error { return nil }
486
- func (evb * ExpressionVisitorBase ) OnExitXorExpression () error { return nil }
487
- func (evb * ExpressionVisitorBase ) OnEnterOrExpression () error { return nil }
488
- func (evb * ExpressionVisitorBase ) OnExitOrExpression () error { return nil }
489
- func (evb * ExpressionVisitorBase ) OnEnterExpression () error { return nil }
490
- func (evb * ExpressionVisitorBase ) OnExitExpression () error { return nil }
0 commit comments