Skip to content

Commit

Permalink
Add grammar rules for new constraint syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Mats-SX committed Dec 15, 2016
1 parent a4a5203 commit 6a73206
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion grammar/basic-grammar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
</alt>
</production>

<production name="RelType" rr:inline="true" oc:legacy="true">
<production name="RelType" rr:inline="true">
:<non-terminal ref="RelTypeName"/>
</production>

Expand Down
45 changes: 43 additions & 2 deletions grammar/commands.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
xmlns:rr="http://opencypher.org/railroad"
xmlns:oc="http://opencypher.org/opencypher">

<production name="Command" rr:inline="true" oc:legacy="true">
<production name="Command" rr:inline="true">
<alt>
<non-terminal ref="CreateIndex"/>
<non-terminal ref="DropIndex"/>
Expand All @@ -44,10 +44,51 @@

<non-terminal ref="CreateRelationshipPropertyExistenceConstraint"/>
<non-terminal ref="DropRelationshipPropertyExistenceConstraint"/>

<non-terminal ref="CreateConstraint"/>
<non-terminal ref="DropConstraint"/>
</alt>
</production>

<!-- / NEW CONSTRAINT SYNTAX \ -->

<production name="CreateConstraint">
CREATE &SP; CONSTRAINT &SP; <non-terminal ref="ConstraintName"/> &SP;
FOR &SP; <non-terminal ref="ConstraintPattern"/> &SP;
REQUIRE &SP; <non-terminal ref="ConstraintExpression"/>
</production>

<production name="DropConstraint">
DROP &SP; CONSTRAINT &SP; <non-terminal ref="ConstraintName"/>
</production>

<production name="ConstraintName">
<non-terminal ref="SymbolicName"/>
</production>

<production name="ConstraintPattern">
<alt>
<seq>( &var; &label; ) </seq>
<seq>( ) - [ &var; <non-terminal ref='RelType'/> ] - ( ) </seq>
</alt>
</production>

<production name="ConstraintExpression">
<alt>
<non-terminal ref="NodePropertyUniquenessConstraint"/>
<non-terminal ref="PropertyExistenceConstraint"/>
</alt>
</production>

<!-- / COMMANDS \ -->
<production name="NodePropertyUniquenessConstraint">
UNIQUE &SP; <non-terminal ref="PropertyExpression"/> <repeat>&WS; , &WS; <non-terminal ref="PropertyExpression"/></repeat>
</production>

<production name="PropertyExistenceConstraint">
exists ( <non-terminal ref="PropertyExpression"/> )
</production>

<!-- / LEGACY COMMANDS \ -->

<production name="CreateUniqueConstraint" rr:inline="true" oc:legacy="true">
CREATE &SP; <non-terminal ref="UniqueConstraint"/>
Expand Down
13 changes: 13 additions & 0 deletions tools/grammar/src/test/resources/cypher.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,16 @@ MATCH (other:Person) WHERE ( NOT other.age > 25) RETURN other.name§
MATCH (other:Person) WHERE ( NOT other.age > 25) RETURN other.name§
MATCH (other:Person) WHERE ( NOT other.age > 25 ) RETURN other.name§
MATCH (other:Person) WHERE NOT ( other.age > 25) RETURN other.name§
CREATE CONSTRAINT foo
FOR (p:Person)
REQUIRE UNIQUE p.name§
CREATE CONSTRAINT bar
FOR (p:Person)
REQUIRE UNIQUE p.name, p.email§
CREATE CONSTRAINT baz
FOR (p:Person)
REQUIRE exists(p.name)§
CREATE CONSTRAINT cru
FOR ()-[r:REL]-()
REQUIRE exists(r.property)§
DROP CONSTRAINT foo_bar_baz§

0 comments on commit 6a73206

Please sign in to comment.