Skip to content

Conversation

@hvub
Copy link

@hvub hvub commented Dec 21, 2021

This modifies the visitor so that is correctly reproduces the groups of clauses in a Cypher query.

For the example

MATCH (a) WITH a MATCH (b) SET a.prop = 'match 2' WITH a, b MATCH (c) WITH a, b, c MATCH (d) RETURN *

the modified visitor outputs

MultiPart [
  Group [
    1: MATCH (a)
    2: WITH a
  ]
  Group [
    3: MATCH (b)
    4: SET a.prop = 'match 2'
    5: WITH a, b
  ]
  Group [
    6: MATCH (c)
    7: WITH a, b, c
  ]
  Group [
    8: MATCH (d)
    9: RETURN *
  ]
]

In essence, the grammar tells us a group is terminated by a WITH or a RETURN. Hence, we can simply collect clauses until a WITH or a RETURN appears. When we visit a WITH or a RETURN, we wrap the current group and start a new group.

Note that it is important to call the overridden implementation of the base visitor, e.g.

super.visitOC_MultiPartQuery(ctx);

or directly do what the base visitor does, i.e.

visitChildren(ctx);

so that the visitor continues further down the parse tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant