From: Thomas Walker Lynch Date: Wed, 31 Jul 2024 16:34:12 +0000 (+0000) Subject: makes grammar X-Git-Url: https://git.reasoningtechnology.com/style/static/git-favicon.png?a=commitdiff_plain;h=4f13bcb34cfed9b09c32a6a6521e96919e87f808;p=GQL-to-Cypher makes grammar --- diff --git a/developer/ANTLR/GQL_2024.g4 b/developer/ANTLR/GQL_2024.g4 deleted file mode 100644 index 4a2f4e6..0000000 --- a/developer/ANTLR/GQL_2024.g4 +++ /dev/null @@ -1,3778 +0,0 @@ -grammar GQL_2024; - -options { caseInsensitive = true; } - -// 6 - -gqlProgram - : programActivity sessionCloseCommand? EOF - | sessionCloseCommand EOF - ; - -programActivity - : sessionActivity - | transactionActivity - ; - -sessionActivity - : sessionResetCommand+ - | sessionSetCommand+ sessionResetCommand* - ; - -transactionActivity - : startTransactionCommand (procedureSpecification endTransactionCommand?)? - | procedureSpecification endTransactionCommand? - | endTransactionCommand - ; - -endTransactionCommand - : rollbackCommand - | commitCommand - ; - -// 7.1 - -sessionSetCommand - : SESSION SET (sessionSetSchemaClause | sessionSetGraphClause | sessionSetTimeZoneClause | sessionSetParameterClause) - ; - -sessionSetSchemaClause - : SCHEMA schemaReference - ; - -sessionSetGraphClause - : PROPERTY? GRAPH graphExpression - ; - -sessionSetTimeZoneClause - : TIME ZONE setTimeZoneValue - ; - -setTimeZoneValue - : timeZoneString - ; - -sessionSetParameterClause - : sessionSetGraphParameterClause - | sessionSetBindingTableParameterClause - | sessionSetValueParameterClause - ; - -sessionSetGraphParameterClause - : PROPERTY? GRAPH sessionSetParameterName optTypedGraphInitializer - ; - -sessionSetBindingTableParameterClause - : BINDING? TABLE sessionSetParameterName optTypedBindingTableInitializer - ; - -sessionSetValueParameterClause - : VALUE sessionSetParameterName optTypedValueInitializer - ; - -sessionSetParameterName - : (IF NOT EXISTS)? sessionParameterSpecification - ; - -// 7.2 - -sessionResetCommand - : SESSION RESET sessionResetArguments? - ; - -sessionResetArguments - : ALL? (PARAMETERS | CHARACTERISTICS) - | SCHEMA - | PROPERTY? GRAPH - | TIME ZONE - | PARAMETER? sessionParameterSpecification - ; - -// 7.3 - -sessionCloseCommand - : SESSION CLOSE - ; - -// 7.4 - -sessionParameterSpecification - : GENERAL_PARAMETER_REFERENCE - ; - -// 8.1 - -startTransactionCommand - : START TRANSACTION transactionCharacteristics? - ; - -// 8.2 - -transactionCharacteristics - : transactionMode (COMMA transactionMode)* - ; - -transactionMode - : transactionAccessMode - ; - -transactionAccessMode - : READ ONLY - | READ WRITE - ; - -// 8.3 - -rollbackCommand - : ROLLBACK - ; - -// 8.4 - -commitCommand - : COMMIT - ; - -// 9.1 - -nestedProcedureSpecification - : LEFT_BRACE procedureSpecification RIGHT_BRACE - ; - -// , and are -// identical productions. The specification distinguishes them in the BNF, but in the implementation, the distinction -// has to be made sematically, in code, based on the kind of statements contained in the . -procedureSpecification - : procedureBody -// : catalogModifyingProcedureSpecification -// | dataModifyingProcedureSpecification -// | querySpecification - ; - -//catalogModifyingProcedureSpecification -// : procedureBody -// ; - -nestedDataModifyingProcedureSpecification - : LEFT_BRACE procedureBody RIGHT_BRACE - ; - -//dataModifyingProcedureSpecification -// : procedureBody -// ; - -nestedQuerySpecification - : LEFT_BRACE procedureBody RIGHT_BRACE - ; - -//querySpecification -// : procedureBody -// ; - -// 9.2 - -procedureBody - : atSchemaClause? bindingVariableDefinitionBlock? statementBlock - ; - -bindingVariableDefinitionBlock - : bindingVariableDefinition+ - ; - -bindingVariableDefinition - : graphVariableDefinition - | bindingTableVariableDefinition - | valueVariableDefinition - ; - -statementBlock - : statement nextStatement* - ; - -statement - : linearCatalogModifyingStatement - | linearDataModifyingStatement - | compositeQueryStatement - ; - -nextStatement - : NEXT yieldClause? statement - ; - -// 10.1 - -graphVariableDefinition - : PROPERTY? GRAPH bindingVariable optTypedGraphInitializer - ; - -optTypedGraphInitializer - : (typed? graphReferenceValueType)? graphInitializer - ; - -graphInitializer - : EQUALS_OPERATOR graphExpression - ; - -// 10.2 - -bindingTableVariableDefinition - : BINDING? TABLE bindingVariable optTypedBindingTableInitializer - ; - -optTypedBindingTableInitializer - : (typed? bindingTableReferenceValueType)? bindingTableInitializer - ; - -bindingTableInitializer - : EQUALS_OPERATOR bindingTableExpression - ; - -// 10.3 - -valueVariableDefinition - : VALUE bindingVariable optTypedValueInitializer - ; - -optTypedValueInitializer - : (typed? valueType)? valueInitializer - ; - -valueInitializer - : EQUALS_OPERATOR valueExpression - ; - -// 11.1 - -graphExpression - : objectExpressionPrimary - | graphReference - | objectNameOrBindingVariable - | currentGraph - ; - -currentGraph - : CURRENT_PROPERTY_GRAPH - | CURRENT_GRAPH - ; - -// 11.2 - -bindingTableExpression - : nestedBindingTableQuerySpecification - | objectExpressionPrimary - | bindingTableReference - | objectNameOrBindingVariable - ; - -nestedBindingTableQuerySpecification - : nestedQuerySpecification - ; - -// 11.3 - -objectExpressionPrimary - : VARIABLE valueExpressionPrimary - | parenthesizedValueExpression - | nonParenthesizedValueExpressionPrimarySpecialCase - ; - -// 12.1 - -linearCatalogModifyingStatement - : simpleCatalogModifyingStatement+ - ; - -simpleCatalogModifyingStatement - : primitiveCatalogModifyingStatement - | callCatalogModifyingProcedureStatement - ; - -primitiveCatalogModifyingStatement - : createSchemaStatement - | dropSchemaStatement - | createGraphStatement - | dropGraphStatement - | createGraphTypeStatement - | dropGraphTypeStatement - ; - -// 12.2 - -createSchemaStatement - : CREATE SCHEMA (IF NOT EXISTS)? catalogSchemaParentAndName - ; - -// 12.3 - -dropSchemaStatement - : DROP SCHEMA (IF EXISTS)? catalogSchemaParentAndName - ; - -// 12.4 - -createGraphStatement - : CREATE (PROPERTY? GRAPH (IF NOT EXISTS)? | OR REPLACE PROPERTY? GRAPH) catalogGraphParentAndName (openGraphType | ofGraphType) graphSource? - ; - -openGraphType - : typed? ANY (PROPERTY? GRAPH)? - ; - -ofGraphType - : graphTypeLikeGraph - | typed? graphTypeReference - | typed? (PROPERTY? GRAPH)? nestedGraphTypeSpecification - ; - -graphTypeLikeGraph - : LIKE graphExpression - ; - -graphSource - : AS COPY OF graphExpression - ; - -// 12.5 - -dropGraphStatement - : DROP PROPERTY? GRAPH (IF EXISTS)? catalogGraphParentAndName - ; - -// 12.6 - -createGraphTypeStatement - : CREATE (PROPERTY? GRAPH TYPE (IF NOT EXISTS)? | OR REPLACE PROPERTY? GRAPH TYPE) catalogGraphTypeParentAndName graphTypeSource - ; - -graphTypeSource - : AS? copyOfGraphType - | graphTypeLikeGraph - | AS? nestedGraphTypeSpecification - ; - -copyOfGraphType - : COPY OF graphTypeReference - ; - -// 12.7 - -dropGraphTypeStatement - : DROP PROPERTY? GRAPH TYPE (IF EXISTS)? catalogGraphTypeParentAndName - ; - -// 12.8 - -callCatalogModifyingProcedureStatement - : callProcedureStatement - ; - -// 13.1 - -linearDataModifyingStatement - : focusedLinearDataModifyingStatement - | ambientLinearDataModifyingStatement - ; - -focusedLinearDataModifyingStatement - : focusedLinearDataModifyingStatementBody - | focusedNestedDataModifyingProcedureSpecification - ; - -focusedLinearDataModifyingStatementBody - : useGraphClause simpleLinearDataAccessingStatement primitiveResultStatement? - ; - -focusedNestedDataModifyingProcedureSpecification - : useGraphClause nestedDataModifyingProcedureSpecification - ; - -ambientLinearDataModifyingStatement - : ambientLinearDataModifyingStatementBody - | nestedDataModifyingProcedureSpecification - ; - -ambientLinearDataModifyingStatementBody - : simpleLinearDataAccessingStatement primitiveResultStatement? - ; - -simpleLinearDataAccessingStatement - : simpleQueryStatement* simpleDataModifyingStatement+ - ; - -// Subsumed by previous rule to enforce 13.1 SR 5 -//simpleDataAccessingStatement -// : simpleQueryStatement -// | simpleDataModifyingStatement -// ; - -simpleDataModifyingStatement - : primitiveDataModifyingStatement - | callDataModifyingProcedureStatement - ; - -primitiveDataModifyingStatement - : insertStatement - | setStatement - | removeStatement - | deleteStatement - ; - -// 13.2 - -insertStatement - : INSERT insertGraphPattern - ; - -// 13.3 - -setStatement - : SET setItemList - ; - -setItemList - : setItem (COMMA setItem)* - ; - -setItem - : setPropertyItem - | setAllPropertiesItem - | setLabelItem - ; - -setPropertyItem - : bindingVariableReference PERIOD propertyName EQUALS_OPERATOR valueExpression - ; - -setAllPropertiesItem - : bindingVariableReference EQUALS_OPERATOR LEFT_BRACE propertyKeyValuePairList? RIGHT_BRACE - ; - -setLabelItem - : bindingVariableReference isOrColon labelName - ; - -// 13.4 - -removeStatement - : REMOVE removeItemList - ; - -removeItemList - : removeItem (COMMA removeItem)* - ; - -removeItem - : removePropertyItem - | removeLabelItem - ; - -removePropertyItem - : bindingVariableReference PERIOD propertyName - ; - -removeLabelItem - : bindingVariableReference isOrColon labelName - ; - -// 13.5 - -deleteStatement - : (DETACH | NODETACH)? DELETE deleteItemList - ; - -deleteItemList - : deleteItem (COMMA deleteItem)* - ; - -deleteItem - : valueExpression - ; - -// 13.6 - -callDataModifyingProcedureStatement - : callProcedureStatement - ; - -// 14.1 - -compositeQueryStatement - : compositeQueryExpression - ; - -// 14.2 - -compositeQueryExpression - : compositeQueryExpression queryConjunction compositeQueryPrimary - | compositeQueryPrimary - ; - -queryConjunction - : setOperator - | OTHERWISE - ; - -setOperator - : UNION setQuantifier? - | EXCEPT setQuantifier? - | INTERSECT setQuantifier? - ; - -compositeQueryPrimary - : linearQueryStatement - ; - -// 14.3 and - -linearQueryStatement - : focusedLinearQueryStatement - | ambientLinearQueryStatement - ; - -focusedLinearQueryStatement - : focusedLinearQueryStatementPart* focusedLinearQueryAndPrimitiveResultStatementPart - | focusedPrimitiveResultStatement - | focusedNestedQuerySpecification - | selectStatement - ; - -focusedLinearQueryStatementPart - : useGraphClause simpleLinearQueryStatement - ; - -focusedLinearQueryAndPrimitiveResultStatementPart - : useGraphClause simpleLinearQueryStatement primitiveResultStatement - ; - -focusedPrimitiveResultStatement - : useGraphClause primitiveResultStatement - ; - -focusedNestedQuerySpecification - : useGraphClause nestedQuerySpecification - ; - -ambientLinearQueryStatement - : simpleLinearQueryStatement? primitiveResultStatement - | nestedQuerySpecification - ; - -simpleLinearQueryStatement - : simpleQueryStatement+ - ; - -simpleQueryStatement - : primitiveQueryStatement - | callQueryStatement - ; - -primitiveQueryStatement - : matchStatement - | letStatement - | forStatement - | filterStatement - | orderByAndPageStatement - ; - -// 14.4 - -matchStatement - : simpleMatchStatement - | optionalMatchStatement - ; - -simpleMatchStatement - : MATCH graphPatternBindingTable - ; - -optionalMatchStatement - : OPTIONAL optionalOperand - ; - -optionalOperand - : simpleMatchStatement - | LEFT_BRACE matchStatementBlock RIGHT_BRACE - | LEFT_PAREN matchStatementBlock RIGHT_PAREN - ; - -matchStatementBlock - : matchStatement+ - ; - -// 14.5 - -callQueryStatement - : callProcedureStatement - ; - -// 14.6 - -filterStatement - : FILTER (whereClause | searchCondition) - ; - -// 14.7 - -letStatement - : LET letVariableDefinitionList - ; - -letVariableDefinitionList - : letVariableDefinition (COMMA letVariableDefinition)* - ; - -letVariableDefinition - : valueVariableDefinition - | bindingVariable EQUALS_OPERATOR valueExpression - ; - -// 14.8 - -forStatement - : FOR forItem forOrdinalityOrOffset? - ; - -forItem - : forItemAlias forItemSource - ; - -forItemAlias - : bindingVariable IN - ; - -forItemSource - : valueExpression - ; - -forOrdinalityOrOffset - : WITH (ORDINALITY | OFFSET) bindingVariable - ; - -// 14.9 - -orderByAndPageStatement - : orderByClause offsetClause? limitClause? - | offsetClause limitClause? - | limitClause - ; - -// 14.10 - -primitiveResultStatement - : returnStatement orderByAndPageStatement? - | FINISH - ; - -// 14.11 - -returnStatement - : RETURN returnStatementBody - ; - -returnStatementBody - : setQuantifier? (ASTERISK | returnItemList) groupByClause? - | NO BINDINGS - ; - -returnItemList - : returnItem (COMMA returnItem)* - ; - -returnItem - : aggregatingValueExpression returnItemAlias? - ; - -returnItemAlias - : AS identifier - ; - -// 14.12 + +selectStatement + : SELECT setQuantifier? (ASTERISK | selectItemList) (selectStatementBody whereClause? groupByClause? havingClause? orderByClause? offsetClause? limitClause?)? + ; + +selectItemList + : selectItem (COMMA selectItem)* + ; + +selectItem + : aggregatingValueExpression selectItemAlias? + ; + +selectItemAlias + : AS identifier + ; + +havingClause + : HAVING searchCondition + ; + +selectStatementBody + : FROM (selectGraphMatchList | selectQuerySpecification) + ; + +selectGraphMatchList + : selectGraphMatch (COMMA selectGraphMatch)* + ; + +selectGraphMatch + : graphExpression matchStatement + ; + +selectQuerySpecification + : nestedQuerySpecification + | graphExpression nestedQuerySpecification + ; + +// 15.1 and + +callProcedureStatement + : OPTIONAL? CALL procedureCall + ; + +procedureCall + : inlineProcedureCall + | namedProcedureCall + ; + +// 15.2 + +inlineProcedureCall + : variableScopeClause? nestedProcedureSpecification + ; + +variableScopeClause + : LEFT_PAREN bindingVariableReferenceList? RIGHT_PAREN + ; + +bindingVariableReferenceList + : bindingVariableReference (COMMA bindingVariableReference)* + ; + +// 15.3 + +namedProcedureCall + : procedureReference LEFT_PAREN procedureArgumentList? RIGHT_PAREN yieldClause? + ; + +procedureArgumentList + : procedureArgument (COMMA procedureArgument)* + ; + +procedureArgument + : valueExpression + ; + +// 16.1 + +atSchemaClause + : AT schemaReference + ; + +// 16.2 + +useGraphClause + : USE graphExpression + ; + +// 16.3 + +graphPatternBindingTable + : graphPattern graphPatternYieldClause? + ; + +graphPatternYieldClause + : YIELD graphPatternYieldItemList + ; + +graphPatternYieldItemList + : graphPatternYieldItem (COMMA graphPatternYieldItem)* + | NO BINDINGS + ; + +// and are identical productions, both consisting +// of a single non-terminal . Thus is ambiguous +// from a parsing standpoint. So here we simply use bindingVariableReference. Post parsing code must +// apply the semantics assocaited with each type of . +graphPatternYieldItem + : bindingVariableReference +// : elementVariableReference +// | pathVariableReference + ; + +// 16.4 + +graphPattern + : matchMode? pathPatternList keepClause? graphPatternWhereClause? + ; + +matchMode + : repeatableElementsMatchMode + | differentEdgesMatchMode + ; + +repeatableElementsMatchMode + : REPEATABLE elementBindingsOrElements + ; + +differentEdgesMatchMode + : DIFFERENT edgeBindingsOrEdges + ; + +elementBindingsOrElements + : ELEMENT BINDINGS? + | ELEMENTS + ; + +edgeBindingsOrEdges + : edgeSynonym BINDINGS? + | edgesSynonym + ; + +pathPatternList + : pathPattern (COMMA pathPattern)* + ; + +pathPattern + : pathVariableDeclaration? pathPatternPrefix? pathPatternExpression + ; + +pathVariableDeclaration + : pathVariable EQUALS_OPERATOR + ; + +keepClause + : KEEP pathPatternPrefix + ; + +graphPatternWhereClause + : WHERE searchCondition + ; + +// 16.5 + +insertGraphPattern + : insertPathPatternList + ; + +insertPathPatternList + : insertPathPattern (COMMA insertPathPattern)* + ; + +insertPathPattern + : insertNodePattern (insertEdgePattern insertNodePattern)* + ; + +insertNodePattern + : LEFT_PAREN insertElementPatternFiller? RIGHT_PAREN + ; + +insertEdgePattern + : insertEdgePointingLeft + | insertEdgePointingRight + | insertEdgeUndirected + ; + +insertEdgePointingLeft + : LEFT_ARROW_BRACKET insertElementPatternFiller? RIGHT_BRACKET_MINUS + ; + +insertEdgePointingRight + : MINUS_LEFT_BRACKET insertElementPatternFiller? BRACKET_RIGHT_ARROW + ; + +insertEdgeUndirected + : TILDE_LEFT_BRACKET insertElementPatternFiller? RIGHT_BRACKET_TILDE + ; + +insertElementPatternFiller + : elementVariableDeclaration labelAndPropertySetSpecification? + | elementVariableDeclaration? labelAndPropertySetSpecification + ; + +labelAndPropertySetSpecification + : isOrColon labelSetSpecification elementPropertySpecification? + | (isOrColon labelSetSpecification)? elementPropertySpecification + ; + +// 16.6 + +pathPatternPrefix + : pathModePrefix + | pathSearchPrefix + ; + +pathModePrefix + : pathMode pathOrPaths? + ; + +pathMode + : WALK + | TRAIL + | SIMPLE + | ACYCLIC + ; + +pathSearchPrefix + : allPathSearch + | anyPathSearch + | shortestPathSearch + ; + +allPathSearch + : ALL pathMode? pathOrPaths? + ; + +pathOrPaths + : PATH + | PATHS + ; + +anyPathSearch + : ANY numberOfPaths? pathMode? pathOrPaths? + ; + +numberOfPaths + : nonNegativeIntegerSpecification + ; + +shortestPathSearch + : allShortestPathSearch + | anyShortestPathSearch + | countedShortestPathSearch + | countedShortestGroupSearch + ; + +allShortestPathSearch + : ALL SHORTEST pathMode? pathOrPaths? + ; + +anyShortestPathSearch + : ANY SHORTEST pathMode? pathOrPaths? + ; + +countedShortestPathSearch + : SHORTEST numberOfPaths pathMode? pathOrPaths? + ; + +countedShortestGroupSearch + : SHORTEST numberOfGroups? pathMode? pathOrPaths? (GROUP | GROUPS) + ; + +numberOfGroups + : nonNegativeIntegerSpecification + ; + +// 16.7 + +pathPatternExpression + : pathTerm #ppePathTerm + | pathTerm (MULTISET_ALTERNATION_OPERATOR pathTerm)+ #ppeMultisetAlternation + | pathTerm (VERTICAL_BAR pathTerm)+ #ppePatternUnion + ; + +pathTerm + : pathFactor+ + ; + +pathFactor + : pathPrimary #pfPathPrimary + | pathPrimary graphPatternQuantifier #pfQuantifiedPathPrimary + | pathPrimary QUESTION_MARK #pfQuestionedPathPrimary + ; + +pathPrimary + : elementPattern #ppElementPattern + | parenthesizedPathPatternExpression #ppParenthesizedPathPatternExpression + | simplifiedPathPatternExpression #ppSimplifiedPathPatternExpression + ; + +elementPattern + : nodePattern + | edgePattern + ; + +nodePattern + : LEFT_PAREN elementPatternFiller RIGHT_PAREN + ; + +elementPatternFiller + : elementVariableDeclaration? isLabelExpression? elementPatternPredicate? + ; + +elementVariableDeclaration + : TEMP? elementVariable + ; + +isLabelExpression + : isOrColon labelExpression + ; + +isOrColon + : IS + | COLON + ; + +elementPatternPredicate + : elementPatternWhereClause + | elementPropertySpecification + ; + +elementPatternWhereClause + : WHERE searchCondition + ; + +elementPropertySpecification + : LEFT_BRACE propertyKeyValuePairList RIGHT_BRACE + ; + +propertyKeyValuePairList + : propertyKeyValuePair (COMMA propertyKeyValuePair)* + ; + +propertyKeyValuePair + : propertyName COLON valueExpression + ; + +edgePattern + : fullEdgePattern + | abbreviatedEdgePattern + ; + +fullEdgePattern + : fullEdgePointingLeft + | fullEdgeUndirected + | fullEdgePointingRight + | fullEdgeLeftOrUndirected + | fullEdgeUndirectedOrRight + | fullEdgeLeftOrRight + | fullEdgeAnyDirection + ; + +fullEdgePointingLeft + : LEFT_ARROW_BRACKET elementPatternFiller RIGHT_BRACKET_MINUS + ; + +fullEdgeUndirected + : TILDE_LEFT_BRACKET elementPatternFiller RIGHT_BRACKET_TILDE + ; + +fullEdgePointingRight + : MINUS_LEFT_BRACKET elementPatternFiller BRACKET_RIGHT_ARROW + ; + +fullEdgeLeftOrUndirected + : LEFT_ARROW_TILDE_BRACKET elementPatternFiller RIGHT_BRACKET_TILDE + ; + +fullEdgeUndirectedOrRight + : TILDE_LEFT_BRACKET elementPatternFiller BRACKET_TILDE_RIGHT_ARROW + ; + +fullEdgeLeftOrRight + : LEFT_ARROW_BRACKET elementPatternFiller BRACKET_RIGHT_ARROW + ; + +fullEdgeAnyDirection + : MINUS_LEFT_BRACKET elementPatternFiller RIGHT_BRACKET_MINUS + ; + +abbreviatedEdgePattern + : LEFT_ARROW + | TILDE + | RIGHT_ARROW + | LEFT_ARROW_TILDE + | TILDE_RIGHT_ARROW + | LEFT_MINUS_RIGHT + | MINUS_SIGN + ; + +parenthesizedPathPatternExpression + : LEFT_PAREN subpathVariableDeclaration? pathModePrefix? pathPatternExpression parenthesizedPathPatternWhereClause? RIGHT_PAREN + ; + +subpathVariableDeclaration + : subpathVariable EQUALS_OPERATOR + ; + +parenthesizedPathPatternWhereClause + : WHERE searchCondition + ; + +// 16.8