Skip to content

Commit

Permalink
Update openCypher grammar description
Browse files Browse the repository at this point in the history
- Including links to these from the CIP
- Also update examples for the parser tests
  • Loading branch information
Mats-SX committed Jul 2, 2021
1 parent 03bca92 commit 26f22bb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
10 changes: 10 additions & 0 deletions cip/1.accepted/CIP2016-12-14-Constraint-syntax.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ References to existing grammar parts:
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=Expression[<Expression>]
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=PropertyExpression[<PropertyExpression>]

References to new grammar parts:

* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=Command[<ConstraintCommand>]
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=CreateConstraint[<CreateConstraint>]
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=DropConstraint[<DropConstraint>]
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=ConstraintPredicate[<ConstraintPredicate>]
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=Unique[<Unique>]
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=NodeKey[<NodeKey>]
* https://raw.githack.com/openCypher/openCypher/master/tools/grammar-production-links/grammarLink.html?p=GroupedPropertyExpression[<GroupedPropertyExpression>]

The `REQUIRE` clause works exactly like the `WHERE` clause in a standard Cypher query, with the addition of also supporting the special constraint operators `IS UNIQUE`, `IS NODE KEY`, and the new `<GroupedExpression>` expression.
This allows for complex concrete constraint definitions (using custom predicates) within the specified syntax.

Expand Down
7 changes: 4 additions & 3 deletions grammar/basic-grammar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
</alt>
</production>

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

Expand Down Expand Up @@ -714,6 +714,9 @@
OF
ADD
DROP
NODE
KEY
UNIQUE
</alt>
</production>

Expand All @@ -728,8 +731,6 @@
ANY
NONE
SINGLE
NODE
KEY
</alt>
</production>

Expand Down
44 changes: 22 additions & 22 deletions grammar/commands.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,41 @@

<!-- / 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"/>
DROP &SP; CONSTRAINT &SP; <non-terminal ref="SymbolicName"/>
</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 name="CreateConstraint">
CREATE &SP; CONSTRAINT &SP; <non-terminal ref="SymbolicName"/> &SP;
FOR &SP; <non-terminal ref="Pattern"/> &SP;
REQUIRE &SP; <non-terminal ref="ConstraintPredicate"/>
</production>

<production name="ConstraintExpression">
<production name="ConstraintPredicate">
<alt>
<non-terminal ref="Uniqueness"/>
<non-terminal ref="NodeKey"/>
<non-terminal ref="Expression"/>
<non-terminal ref="Unique"/>
<non-terminal ref="NodeKey"/>
</alt>
</production>

<production name="Uniqueness">
UNIQUE &SP; <non-terminal ref="PropertyExpression"/>
<production name="Unique">
<non-terminal ref="GroupedPropertyExpression"/> &SP; IS &SP; UNIQUE
</production>

<production name="NodeKey">
NODE &SP; KEY &SP; <non-terminal ref="PropertyExpression"/> <repeat>&WS; , &WS; <non-terminal ref="PropertyExpression"/></repeat>
<non-terminal ref="GroupedPropertyExpression"/> &SP; IS &SP; NODE &SP; KEY
</production>

<production name="GroupedPropertyExpression">
<alt>
<non-terminal ref="PropertyExpression"/>
<seq>
( &WS; <non-terminal ref="PropertyExpression"/>
<repeat>&WS; , &WS; <non-terminal ref="PropertyExpression"/></repeat>
&WS; )
</seq>
</alt>
</production>

<!-- / LEGACY COMMANDS \ -->
Expand Down
21 changes: 15 additions & 6 deletions tools/grammar/src/test/resources/cypher.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,30 @@ RETURN count(label) AS numLabels§
CALL db.labels() YIELD x WHERE label CONTAINS 'User' AND foo + bar = foo RETURN count(label) AS numLabels§
CREATE CONSTRAINT foo
FOR (p:Person)
REQUIRE UNIQUE p.name§
REQUIRE p.name IS UNIQUE§
CREATE CONSTRAINT foo
FOR (p:Person)
REQUIRE (p.name) IS UNIQUE§
CREATE CONSTRAINT foo
FOR (p:Person)
REQUIRE (p.name, p.email) IS UNIQUE§
CREATE CONSTRAINT baz
FOR (p:Person)
REQUIRE exists(p.name)§
REQUIRE p.name IS NOT NULL§
CREATE CONSTRAINT cru
FOR ()-[r:REL]-()
REQUIRE exists(r.property)§
REQUIRE r.property > 5§
DROP CONSTRAINT foo_bar_baz§
CREATE CONSTRAINT nodeKey
FOR (n:Node)
REQUIRE NODE KEY n.prop§
REQUIRE n.prop IS NODE KEY§
CREATE CONSTRAINT nodeKey
FOR (n:Node)
REQUIRE (n.prop) IS NODE KEY§
CREATE CONSTRAINT nodeKey
FOR (n:Node)
REQUIRE NODE KEY n.p1, n.p2, n.p3§
REQUIRE (n.p1, n.p2, n.p3) IS NODE KEY§
CREATE CONSTRAINT nodeKey
FOR (n:Node)
REQUIRE NODE KEY n.p1 ,n.p2, n.p3§
REQUIRE ( n.p1 ,n.p2, n.p3 ) IS NODE KEY§
DROP CONSTRAINT foo§

0 comments on commit 26f22bb

Please sign in to comment.