Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/salty-houses-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@neo4j-cypher/language-support': patch
---

Updates grammar and semantic analysis to version 2025.06
16 changes: 16 additions & 0 deletions packages/language-support/src/antlr-grammar/Cypher25Lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ ACTIVE
: A C T I V E
;

ADD
: A D D
;

ADMIN
: A D M I N
;
Expand All @@ -131,6 +135,10 @@ ALL
: A L L
;

ALLREDUCE
: A L L R E D U C E
;

ALTER
: A L T E R
;
Expand Down Expand Up @@ -740,6 +748,10 @@ PERCENT
: '%'
;

IMPLIES
: I M P L I E S
;

INVALID_NEQ
: '!='
;
Expand Down Expand Up @@ -780,6 +792,10 @@ NEW
: N E W
;

NEXT
: N E X T
;

NODE
: N O D E
;
Expand Down
176 changes: 160 additions & 16 deletions packages/language-support/src/antlr-grammar/Cypher25Parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ statements
;

statement
: command | regularQuery
: command | nextStatement
;

nextStatement
: regularQuery (NEXT regularQuery)*
;

regularQuery
Expand All @@ -48,7 +52,7 @@ elseBranch

singleQuery
: clause+
| useClause? LCURLY regularQuery RCURLY
| useClause? LCURLY nextStatement RCURLY
;

clause
Expand Down Expand Up @@ -241,7 +245,7 @@ foreachClause
;

subqueryClause
: OPTIONAL? CALL subqueryScope? LCURLY regularQuery RCURLY subqueryInTransactionsParameters?
: OPTIONAL? CALL subqueryScope? LCURLY nextStatement RCURLY subqueryInTransactionsParameters?
;

subqueryScope
Expand Down Expand Up @@ -563,6 +567,7 @@ expression1
| listLiteral
| patternComprehension
| reduceExpression
| allReduceExpression
| listItemsPredicate
| normalizeFunction
| vectorFunction
Expand Down Expand Up @@ -632,6 +637,10 @@ reduceExpression
: REDUCE LPAREN variable EQ expression COMMA variable IN expression BAR expression RPAREN
;

allReduceExpression
: ALLREDUCE LPAREN variable EQ expression COMMA expression COMMA expression RPAREN
;

listItemsPredicate
: (
ALL
Expand Down Expand Up @@ -681,15 +690,15 @@ countStar
;

existsExpression
: EXISTS LCURLY (regularQuery | matchMode? patternList whereClause?) RCURLY
: EXISTS LCURLY (nextStatement | matchMode? patternList whereClause?) RCURLY
;

countExpression
: COUNT LCURLY (regularQuery | matchMode? patternList whereClause?) RCURLY
: COUNT LCURLY (nextStatement | matchMode? patternList whereClause?) RCURLY
;

collectExpression
: COLLECT LCURLY regularQuery RCURLY
: COLLECT LCURLY nextStatement RCURLY
;

numberLiteral
Expand Down Expand Up @@ -856,6 +865,17 @@ createCommand
)
;

alterCommand
: ALTER (
alterAlias
| alterCurrentUser
| alterCurrentGraphType
| alterDatabase
| alterUser
| alterServer
)
;

dropCommand
: DROP (
dropAlias
Expand Down Expand Up @@ -1100,18 +1120,138 @@ enclosedPropertyList
: variable property (COMMA variable property)*
;

// Admin commands
// Graph Type Specification

alterCommand
: ALTER (
alterAlias
| alterCurrentUser
| alterDatabase
| alterUser
| alterServer
)
alterCurrentGraphType
: CURRENT GRAPH TYPE ( (SET | ADD | ALTER) graphTypeSpecification | DROP graphTypeDropSpecification )
;

graphTypeSpecification
: LCURLY graphTypeSpecificationBody? RCURLY
;

graphTypeDropSpecification
: LCURLY graphTypeDropSpecificationBody? RCURLY
;

graphTypeSpecificationBody
: graphTypeElement (COMMA graphTypeElement)*
;

graphTypeDropSpecificationBody
: graphTypeDropElement (COMMA graphTypeDropElement)*
;

graphTypeElement
: edgeTypeSpecification
| nodeTypeSpecification
| constraintSpecification
;

graphTypeDropElement
: edgeTypeSpecification
| nodeTypeSpecification
| CONSTRAINT symbolicNameString
;

nodeTypeInlineConstraintList
: (constraintType commandOptions?)+
;

edgeTypeInlineConstraintList
: (constraintType commandOptions?)+
;

implies
: EQ rightArrow
| IMPLIES
;

// Node type specification

nodeTypeSpecification
: LPAREN variable? identifyingLabel impliedLabelSet? propertyTypeList? RPAREN nodeTypeInlineConstraintList?
;

impliedLabelSet
: labelType ( AMPERSAND symbolicNameString )*
;

identifyingLabel
: labelType implies
;

// Node type reference

nodeTypeReference
: nodeTypeAliasReference
| nodeTypeInSituReference
;

nodeTypeAliasReference
: LPAREN variable RPAREN
;

nodeTypeInSituReference
: LPAREN ( variable? labelType implies? )? RPAREN
;

// Edge type specifcation

edgeTypeSpecification
: nodeTypeReference arcTypePointingRight nodeTypeReference edgeTypeInlineConstraintList?
;

arcTypePointingRight
: arrowLine LBRACKET variable? identifyingRelationship propertyTypeList? RBRACKET arrowLine rightArrow
;

identifyingRelationship
: relType implies
;

// Edge type reference

edgeTypeReference
: edgeTypeAliasReference
| edgeTypeInSituReference
;

edgeTypeAliasReference
: LPAREN RPAREN arrowLine LBRACKET variable RBRACKET arrowLine rightArrow LPAREN RPAREN
;

edgeTypeInSituReference
: LPAREN RPAREN arrowLine LBRACKET variable? relType implies? RBRACKET arrowLine rightArrow LPAREN RPAREN
;

// Property Types

propertyTypeList
: LCURLY (propertyType ( COMMA propertyType )* )? RCURLY
;

propertyType
: propertyKeyName typed? type propertyTypeInlineConstraint?
;

propertyTypeInlineConstraint
: IS ( NODE | RELATIONSHIP | REL )? (KEY | UNIQUE)
;

typed
: COLONCOLON
| TYPED
;

// Graph Type constraint specification

constraintSpecification
: CONSTRAINT symbolicNameString? FOR (nodeTypeReference | edgeTypeReference) constraintType commandOptions?
;

// Admin commands

renameCommand
: RENAME (renameRole | renameServer | renameUser)
;
Expand Down Expand Up @@ -1598,7 +1738,7 @@ shards
;

graphShard
: GRAPH SHARD LCURLY (SET? topology)? RCURLY
: GRAPH SHARD LCURLY (topology)? RCURLY
;

propertyShard
Expand Down Expand Up @@ -1839,12 +1979,14 @@ unescapedSymbolicNameString_
: IDENTIFIER
| ACCESS
| ACTIVE
| ADD
| ADMIN
| ADMINISTRATOR
| ALIAS
| ALIASES
| ALL_SHORTEST_PATHS
| ALL
| ALLREDUCE
| ALTER
| AND
| ANY
Expand Down Expand Up @@ -1945,6 +2087,7 @@ unescapedSymbolicNameString_
| IF
| IMMUTABLE
| IMPERSONATE
| IMPLIES
| IN
| INDEX
| INDEXES
Expand Down Expand Up @@ -1982,6 +2125,7 @@ unescapedSymbolicNameString_
| NAMES
| NAN
| NEW
| NEXT
| NFC
| NFD
| NFKC
Expand Down
12 changes: 6 additions & 6 deletions packages/language-support/src/formatting/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1784,10 +1784,10 @@ export class TreePrintVisitor extends CypherCmdParserVisitor<void> {
this._visit(ctx.EXISTS());
this.avoidBreakBetween();
this._visit(ctx.LCURLY());
if (ctx.regularQuery()) {
if (ctx.nextStatement()) {
this.breakLine();
const queryIndent = this.addIndentation();
this._visit(ctx.regularQuery());
this._visit(ctx.nextStatement());
this.removeIndentation(queryIndent);
this.mustBreakBetween();
this._visit(ctx.RCURLY());
Expand All @@ -1814,7 +1814,7 @@ export class TreePrintVisitor extends CypherCmdParserVisitor<void> {
this.avoidBreakBetween();
this._visit(ctx.LCURLY());
const queryIndent = this.addIndentation();
this._visit(ctx.regularQuery());
this._visit(ctx.nextStatement());
this.removeIndentation(queryIndent);
this.breakLine();
this._visit(ctx.RCURLY());
Expand All @@ -1825,9 +1825,9 @@ export class TreePrintVisitor extends CypherCmdParserVisitor<void> {
this.avoidBreakBetween();
this._visit(ctx.LCURLY());

if (ctx.regularQuery()) {
if (ctx.nextStatement()) {
const queryIndent = this.addIndentation();
this._visit(ctx.regularQuery());
this._visit(ctx.nextStatement());
this.removeIndentation(queryIndent);
this.breakLine();
this.mustBreakBetween();
Expand Down Expand Up @@ -1943,7 +1943,7 @@ export class TreePrintVisitor extends CypherCmdParserVisitor<void> {
this._visit(ctx.LCURLY());
const queryIndent = this.addIndentation();
this.breakLine();
this._visit(ctx.regularQuery());
this._visit(ctx.nextStatement());
this.removeIndentation(queryIndent);
this.breakLine();
this._visit(ctx.RCURLY());
Expand Down
4 changes: 4 additions & 0 deletions packages/language-support/src/lexerSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ export const lexerComment = [
export const lexerKeywords = [
CypherLexer.ACCESS,
CypherLexer.ACTIVE,
CypherLexer.ADD,
CypherLexer.ADMIN,
CypherLexer.ADMINISTRATOR,
CypherLexer.ALIAS,
CypherLexer.ALIASES,
CypherLexer.ALL,
CypherLexer.ALLREDUCE,
CypherLexer.ALL_SHORTEST_PATHS,
CypherLexer.ALTER,
CypherLexer.AND,
Expand Down Expand Up @@ -208,6 +210,7 @@ export const lexerKeywords = [
CypherLexer.IF,
CypherLexer.IMMUTABLE,
CypherLexer.IMPERSONATE,
CypherLexer.IMPLIES,
CypherLexer.IN,
CypherLexer.INDEX,
CypherLexer.INDEXES,
Expand Down Expand Up @@ -245,6 +248,7 @@ export const lexerKeywords = [
CypherLexer.NAMES,
CypherLexer.NAN,
CypherLexer.NEW,
CypherLexer.NEXT,
CypherLexer.NFC,
CypherLexer.NFD,
CypherLexer.NFKC,
Expand Down
Loading