Skip to content

Commit

Permalink
Swaps parser for Cypher 25
Browse files Browse the repository at this point in the history
  • Loading branch information
ncordon committed Nov 27, 2024
1 parent 0e662f8 commit e8380f5
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 138 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
parser grammar Cypher5Parser;
parser grammar Cypher25Parser;


options { tokenVocab = Cypher5Lexer; }
options { tokenVocab = Cypher25Lexer; }
statements
: statement (SEMICOLON statement)* SEMICOLON? EOF
;

statement
: periodicCommitQueryHintFailure? (command | regularQuery)
;

periodicCommitQueryHintFailure
: USING PERIODIC COMMIT UNSIGNED_DECIMAL_INTEGER?
: command | regularQuery
;

regularQuery
Expand Down Expand Up @@ -168,7 +164,6 @@ matchMode
hint
: USING (((
INDEX
| BTREE INDEX
| TEXT INDEX
| RANGE INDEX
| POINT INDEX
Expand Down Expand Up @@ -324,7 +319,7 @@ nodeLabelsIs
dynamicExpression
: DOLLAR LPAREN expression RPAREN
;

dynamicAnyAllExpression
: DOLLAR (ALL | ANY)? LPAREN expression RPAREN
;
Expand Down Expand Up @@ -694,7 +689,7 @@ parameter[String paramType]
;

parameterName[String paramType]
: (symbolicNameString | UNSIGNED_DECIMAL_INTEGER)
: (symbolicNameString | UNSIGNED_DECIMAL_INTEGER | UNSIGNED_OCTAL_INTEGER | EXTENDED_IDENTIFIER)
;

functionInvocation
Expand Down Expand Up @@ -890,71 +885,45 @@ composableShowCommandClauses
)
;

showBriefAndYield
: (BRIEF | VERBOSE) OUTPUT?
| yieldClause returnClause?
| whereClause
;

showIndexCommand
: (
FULLTEXT
| LOOKUP
| POINT
| RANGE
| TEXT
| VECTOR
) showIndexesNoBrief
| (ALL | BTREE)? showIndexesAllowBrief
: (showIndexType)? showIndexesEnd
;

showIndexesAllowBrief
: indexToken showBriefAndYield? composableCommandClauses?
;
showIndexType
: ALL
| FULLTEXT
| LOOKUP
| POINT
| RANGE
| TEXT
| VECTOR
;

showIndexesNoBrief
showIndexesEnd
: indexToken showCommandYield? composableCommandClauses?
;

showConstraintCommand
: (NODE | RELATIONSHIP | REL)? constraintAllowYieldType showConstraintsAllowYield # ShowConstraintMulti
| (NODE | RELATIONSHIP | REL) UNIQUE showConstraintsAllowYield # ShowConstraintUnique
| (RELATIONSHIP | REL)? KEY showConstraintsAllowYield # ShowConstraintKey
| REL EXIST showConstraintsAllowYield # ShowConstraintRelExist
| (NODE | RELATIONSHIP)? EXISTS showConstraintsAllowBrief # ShowConstraintOldExists
| constraintBriefAndYieldType? showConstraintsAllowBriefAndYield # ShowConstraintBriefAndYield
: ALL? showConstraintsEnd # ShowConstraintAll
| (showConstraintEntity)? constraintExistType showConstraintsEnd # ShowConstraintExist
| (showConstraintEntity)? KEY showConstraintsEnd # ShowConstraintKey
| (showConstraintEntity)? PROPERTY TYPE showConstraintsEnd # ShowConstraintPropType
| (showConstraintEntity)? (PROPERTY)? (UNIQUE | UNIQUENESS) showConstraintsEnd # ShowConstraintUnique
;

constraintAllowYieldType
: UNIQUENESS
| constraintExistType
| PROPERTY TYPE
;
showConstraintEntity
: NODE # nodeEntity
| (RELATIONSHIP | REL) # relEntity
;

constraintExistType
: EXISTENCE
| EXIST
| PROPERTY EXISTENCE
| PROPERTY EXIST
;

constraintBriefAndYieldType
: ALL
| UNIQUE
| EXIST
| NODE KEY
| NODE EXIST
| RELATIONSHIP EXIST
;

showConstraintsAllowBriefAndYield
: constraintToken showBriefAndYield? composableCommandClauses?
;

showConstraintsAllowBrief
: constraintToken ((BRIEF | VERBOSE) OUTPUT?)? composableCommandClauses?
;

showConstraintsAllowYield
showConstraintsEnd
: constraintToken showCommandYield? composableCommandClauses?
;

Expand Down Expand Up @@ -985,7 +954,7 @@ showTransactions
;

terminateTransactions
: transactionToken namesAndClauses
: transactionToken stringsOrExpression showCommandYield? composableCommandClauses?
;

showSettings
Expand Down Expand Up @@ -1016,34 +985,28 @@ commandRelPattern
;

createConstraint
: CONSTRAINT symbolicNameOrStringParameter? (IF NOT EXISTS)? (ON | FOR) (commandNodePattern | commandRelPattern) constraintType commandOptions?
: CONSTRAINT symbolicNameOrStringParameter? (IF NOT EXISTS)? FOR (commandNodePattern | commandRelPattern) constraintType commandOptions?
;

constraintType
: ASSERT EXISTS propertyList # ConstraintExists
| (REQUIRE | ASSERT) propertyList (COLONCOLON | IS (TYPED | COLONCOLON)) type # ConstraintTyped
| (REQUIRE | ASSERT) propertyList IS (NODE | RELATIONSHIP | REL)? UNIQUE # ConstraintIsUnique
| (REQUIRE | ASSERT) propertyList IS (NODE | RELATIONSHIP | REL)? KEY # ConstraintKey
| (REQUIRE | ASSERT) propertyList IS NOT NULL # ConstraintIsNotNull
: REQUIRE propertyList (COLONCOLON | IS (TYPED | COLONCOLON)) type # ConstraintTyped
| REQUIRE propertyList IS (NODE | RELATIONSHIP | REL)? UNIQUE # ConstraintIsUnique
| REQUIRE propertyList IS (NODE | RELATIONSHIP | REL)? KEY # ConstraintKey
| REQUIRE propertyList IS NOT NULL # ConstraintIsNotNull
;

dropConstraint
: CONSTRAINT (ON (commandNodePattern | commandRelPattern) ASSERT (EXISTS propertyList | propertyList IS (UNIQUE | NODE KEY | NOT NULL)) | symbolicNameOrStringParameter (IF EXISTS)?)
: CONSTRAINT symbolicNameOrStringParameter (IF EXISTS)?
;

createIndex
: BTREE INDEX createIndex_
| RANGE INDEX createIndex_
: RANGE INDEX createIndex_
| TEXT INDEX createIndex_
| POINT INDEX createIndex_
| VECTOR INDEX createIndex_
| LOOKUP INDEX createLookupIndex
| FULLTEXT INDEX createFulltextIndex
| INDEX (ON oldCreateIndex | createIndex_)
;

oldCreateIndex
: labelType LPAREN nonEmptyNameList RPAREN
| INDEX createIndex_
;

createIndex_
Expand Down Expand Up @@ -1075,7 +1038,7 @@ lookupIndexRelPattern
;

dropIndex
: INDEX (ON labelType LPAREN nonEmptyNameList RPAREN | symbolicNameOrStringParameter (IF EXISTS)?)
: INDEX symbolicNameOrStringParameter (IF EXISTS)?
;

propertyList
Expand Down Expand Up @@ -1170,7 +1133,7 @@ reallocateDatabases
// Role commands

createRole
: ROLE commandNameExpression (IF NOT EXISTS)? (AS COPY OF commandNameExpression)?
: IMMUTABLE? ROLE commandNameExpression (IF NOT EXISTS)? (AS COPY OF commandNameExpression)?
;

dropRole
Expand Down Expand Up @@ -1330,7 +1293,7 @@ allPrivilegeType
;

allPrivilegeTarget
: (DEFAULT | HOME) (DATABASE | GRAPH) # DefaultTarget
: HOME (DATABASE | GRAPH) # DefaultTarget
| (DATABASE | DATABASES) (TIMES | symbolicAliasNameList) # DatabaseVariableTarget
| (GRAPH | GRAPHS) (TIMES | symbolicAliasNameList) # GraphVariableTarget
| DBMS # DBMSTarget
Expand Down Expand Up @@ -1562,12 +1525,12 @@ nodeToken
;

databaseScope
: (DEFAULT | HOME) DATABASE
: HOME DATABASE
| (DATABASE | DATABASES) (TIMES | symbolicAliasNameList)
;

graphScope
: (DEFAULT | HOME) GRAPH
: HOME GRAPH
| (GRAPH | GRAPHS) (TIMES | symbolicAliasNameList)
;

Expand All @@ -1582,15 +1545,15 @@ createDatabase
;

primaryTopology
: UNSIGNED_DECIMAL_INTEGER primaryToken
: uIntOrIntParameter primaryToken
;

primaryToken
: PRIMARY | PRIMARIES
;

secondaryTopology
: UNSIGNED_DECIMAL_INTEGER secondaryToken
: uIntOrIntParameter secondaryToken
;

secondaryToken
Expand Down Expand Up @@ -1646,8 +1609,6 @@ showDatabase
| (DATABASE | DATABASES) symbolicAliasNameOrParameter? showCommandYield?
;

// Alias commands

aliasName
: symbolicAliasNameOrParameter
;
Expand All @@ -1656,6 +1617,8 @@ databaseName
: symbolicAliasNameOrParameter
;

// Alias commands

createAlias
: ALIAS aliasName (IF NOT EXISTS)? FOR DATABASE databaseName (AT stringOrParameter USER commandNameExpression PASSWORD passwordExpression (DRIVER mapOrParameter)?)? (PROPERTIES mapOrParameter)?
;
Expand Down Expand Up @@ -1754,6 +1717,13 @@ stringOrParameter
| parameter["STRING"]
;

// Should return an Either[Integer, Parameter]
// There is no unsigned integer Cypher Type so the parameter permits signed values.
uIntOrIntParameter
:UNSIGNED_DECIMAL_INTEGER
| parameter["INTEGER"]
;

mapOrParameter
: map
| parameter["MAP"]
Expand Down Expand Up @@ -1812,7 +1782,6 @@ unescapedLabelSymbolicNameString_
| AS
| ASC
| ASCENDING
| ASSERT
| ASSIGN
| AT
| AUTH
Expand All @@ -1822,8 +1791,6 @@ unescapedLabelSymbolicNameString_
| BOOSTED
| BOTH
| BREAK
| BRIEF
| BTREE
| BUILT
| BY
| CALL
Expand All @@ -1834,7 +1801,6 @@ unescapedLabelSymbolicNameString_
| COLLECT
| COMMAND
| COMMANDS
| COMMIT
| COMPOSITE
| CONCURRENT
| CONSTRAINT
Expand Down Expand Up @@ -1948,12 +1914,10 @@ unescapedLabelSymbolicNameString_
| OPTION
| OR
| ORDER
| OUTPUT
| PASSWORD
| PASSWORDS
| PATH
| PATHS
| PERIODIC
| PLAINTEXT
| POINT
| POPULATED
Expand Down Expand Up @@ -2042,7 +2006,6 @@ unescapedLabelSymbolicNameString_
| USING
| VALUE
| VECTOR
| VERBOSE
| VERTEX
| WAIT
| WHEN
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lexer grammar CypherPreLexer;

import Cypher5Lexer;
import Cypher25Lexer;

EXPLAIN:
E X P L A I N;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parser grammar CypherPreParser;

import Cypher5Parser;
import Cypher25Parser;

options { tokenVocab = CypherPreLexer; }

Expand Down
Loading

0 comments on commit e8380f5

Please sign in to comment.