func initSemanticBQL() { SemanticBQL = Grammar{} cloneGrammar(&SemanticBQL, &BQL) // Insert and Delete semantic hooks addition. symbols := []semantic.Symbol{"INSERT_OBJECT", "INSERT_DATA", "DELETE_OBJECT", "DELETE_DATA"} for _, sym := range symbols { for _, cls := range SemanticBQL[sym] { cls.ProcessedElement = semantic.DataAccumulatorHook() } } for _, cls := range SemanticBQL["INSERT_OBJECT"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Insert) } for _, cls := range SemanticBQL["DELETE_OBJECT"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Delete) } for _, cls := range SemanticBQL["START"] { if t := cls.Elements[0].Token(); t != lexer.ItemInsert && t != lexer.ItemDelete { continue } cls.ProcessedElement = semantic.DataAccumulatorHook() } // Query semantic hooks. for _, cls := range SemanticBQL["WHERE"] { cls.ProcessStart = semantic.WhereInitWorkingClauseHook() } for _, cls := range SemanticBQL["NORE_CLAUSES"] { cls.ProcessEnd = semantic.WhereNextWorkingClauseHook() } // Create and Drop semantic hooks for type. for _, cls := range SemanticBQL["CREATE_GRAPHS"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Create) } for _, cls := range SemanticBQL["DROP_GRAPHS"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Drop) } // Add graph binding collection to GRAPHS and MORE_GRAPHS clauses. graphSymbols := []semantic.Symbol{"GRAPHS", "MORE_GRAPHS"} for _, sym := range graphSymbols { for _, cls := range SemanticBQL[sym] { cls.ProcessedElement = semantic.GraphAccumulatorHook() } } }
func initSemanticBQL() { semanticBQL = &Grammar{} cloneGrammar(semanticBQL, bql) // Create and Drop semantic hooks for type. for _, cls := range (*semanticBQL)["CREATE_GRAPHS"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Create) } for _, cls := range (*semanticBQL)["DROP_GRAPHS"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Drop) } // Add graph binding collection to GRAPHS and MORE_GRAPHS clauses. graphSymbols := []semantic.Symbol{"GRAPHS", "MORE_GRAPHS"} for _, sym := range graphSymbols { for _, cls := range (*semanticBQL)[sym] { cls.ProcessedElement = semantic.GraphAccumulatorHook() } } // Insert and Delete semantic hooks addition. symbols := []semantic.Symbol{ "INSERT_OBJECT", "INSERT_DATA", "DELETE_OBJECT", "DELETE_DATA", } for _, sym := range symbols { for _, cls := range (*semanticBQL)[sym] { cls.ProcessedElement = semantic.DataAccumulatorHook() } } for _, cls := range (*semanticBQL)["INSERT_OBJECT"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Insert) } for _, cls := range (*semanticBQL)["DELETE_OBJECT"] { cls.ProcessEnd = semantic.TypeBindingClauseHook(semantic.Delete) } for _, cls := range (*semanticBQL)["START"] { if t := cls.Elements[0].Token(); t != lexer.ItemInsert && t != lexer.ItemDelete { continue } cls.ProcessedElement = semantic.DataAccumulatorHook() } // Query semantic hooks. for _, cls := range (*semanticBQL)["WHERE"] { cls.ProcessStart = semantic.WhereInitWorkingClauseHook() } for _, cls := range (*semanticBQL)["NORE_CLAUSES"] { cls.ProcessEnd = semantic.WhereNextWorkingClauseHook() } subSymbols := []semantic.Symbol{"SUBJECT_EXTRACT", "SUBJECT_TYPE", "SUBJECT_ID"} for _, sym := range subSymbols { for _, cls := range (*semanticBQL)[sym] { cls.ProcessedElement = semantic.WhereSubjectClauseHook() } } predSymbols := []semantic.Symbol{ "PREDICATE", "PREDICATE_AS", "PREDICATE_ID", "PREDICATE_AT", "PREDICATE_BOUND_AT", "PREDICATE_BOUND_AT_BINDINGS", "PREDICATE_BOUND_AT_BINDINGS_END", } for _, sym := range predSymbols { for _, cls := range (*semanticBQL)[sym] { cls.ProcessedElement = semantic.WherePredicateClauseHook() } } objSymbols := []semantic.Symbol{ "OBJECT", "OBJECT_SUBJECT_EXTRACT", "OBJECT_SUBJECT_TYPE", "OBJECT_SUBJECT_ID", "OBJECT_PREDICATE_AS", "OBJECT_PREDICATE_ID", "OBJECT_PREDICATE_AT", "OBJECT_PREDICATE_BOUND_AT", "OBJECT_PREDICATE_BOUND_AT_BINDINGS", "OBJECT_PREDICATE_BOUND_AT_BINDINGS_END", "OBJECT_LITERAL_AS", "OBJECT_LITERAL_BINDING_AS", "OBJECT_LITERAL_BINDING_TYPE", "OBJECT_LITERAL_BINDING_ID", "OBJECT_LITERAL_BINDING_AT", } for _, sym := range objSymbols { for _, cls := range (*semanticBQL)[sym] { cls.ProcessedElement = semantic.WhereObjectClauseHook() } } }
func initSemanticBQL() { semanticBQL = &Grammar{} cloneGrammar(semanticBQL, bql) // Create and Drop semantic hooks for type. setClauseHook([]semantic.Symbol{"CREATE_GRAPHS"}, nil, semantic.TypeBindingClauseHook(semantic.Create)) setClauseHook([]semantic.Symbol{"DROP_GRAPHS"}, nil, semantic.TypeBindingClauseHook(semantic.Drop)) // Add graph binding collection to GRAPHS and MORE_GRAPHS clauses. graphSymbols := []semantic.Symbol{"GRAPHS", "MORE_GRAPHS"} setElementHook(graphSymbols, semantic.GraphAccumulatorHook(), nil) // Insert and Delete semantic hooks addition. insertSymbols := []semantic.Symbol{ "INSERT_OBJECT", "INSERT_DATA", "DELETE_OBJECT", "DELETE_DATA", } setElementHook(insertSymbols, semantic.DataAccumulatorHook(), nil) setClauseHook([]semantic.Symbol{"INSERT_OBJECT"}, nil, semantic.TypeBindingClauseHook(semantic.Insert)) setClauseHook([]semantic.Symbol{"DELETE_OBJECT"}, nil, semantic.TypeBindingClauseHook(semantic.Delete)) // Query semantic hooks. setClauseHook([]semantic.Symbol{"WHERE"}, semantic.WhereInitWorkingClauseHook(), semantic.VarBindingsGraphChecker()) clauseSymbols := []semantic.Symbol{ "CLAUSES", "MORE_CLAUSES", } setClauseHook(clauseSymbols, semantic.WhereNextWorkingClauseHook(), semantic.WhereNextWorkingClauseHook()) subSymbols := []semantic.Symbol{ "CLAUSES", "SUBJECT_EXTRACT", "SUBJECT_TYPE", "SUBJECT_ID", } setElementHook(subSymbols, semantic.WhereSubjectClauseHook(), nil) predSymbols := []semantic.Symbol{ "PREDICATE", "PREDICATE_AS", "PREDICATE_ID", "PREDICATE_AT", "PREDICATE_BOUND_AT", "PREDICATE_BOUND_AT_BINDINGS", "PREDICATE_BOUND_AT_BINDINGS_END", } setElementHook(predSymbols, semantic.WherePredicateClauseHook(), nil) objSymbols := []semantic.Symbol{ "OBJECT", "OBJECT_SUBJECT_EXTRACT", "OBJECT_SUBJECT_TYPE", "OBJECT_SUBJECT_ID", "OBJECT_PREDICATE_AS", "OBJECT_PREDICATE_ID", "OBJECT_PREDICATE_AT", "OBJECT_PREDICATE_BOUND_AT", "OBJECT_PREDICATE_BOUND_AT_BINDINGS", "OBJECT_PREDICATE_BOUND_AT_BINDINGS_END", "OBJECT_LITERAL_AS", "OBJECT_LITERAL_BINDING_AS", "OBJECT_LITERAL_BINDING_TYPE", "OBJECT_LITERAL_BINDING_ID", "OBJECT_LITERAL_BINDING_AT", } setElementHook(objSymbols, semantic.WhereObjectClauseHook(), nil) // Collect binding variables variables. varSymbols := []semantic.Symbol{ "VARS", "VARS_AS", "MORE_VARS", "COUNT_DISTINCT", } setElementHook(varSymbols, semantic.VarAccumulatorHook(), nil) // Collect and valiadate group by bindinds. grpSymbols := []semantic.Symbol{"GROUP_BY", "GROUP_BY_BINDINGS"} setElementHook(grpSymbols, semantic.GroupByBindings(), nil) setClauseHook([]semantic.Symbol{"GROUP_BY"}, nil, semantic.GroupByBindingsChecker()) // Collect and validate order by bindings. ordSymbols := []semantic.Symbol{"ORDER_BY", "ORDER_BY_DIRECTION", "ORDER_BY_BINDINGS"} setElementHook(ordSymbols, semantic.OrderByBindings(), nil) setClauseHook([]semantic.Symbol{"ORDER_BY"}, nil, semantic.OrderByBindingsChecker()) // Collect the tokens that form the having clause and build the function // that will evaluate the result rows. havingSymbols := []semantic.Symbol{"HAVING", "HAVING_CLAUSE", "HAVING_CLAUSE_BINARY_COMPOSITE"} setElementHook(havingSymbols, semantic.HavingExpression(), nil) setClauseHook([]semantic.Symbol{"HAVING"}, nil, semantic.HavingExpressionBuilder()) // Global time bound semantic hooks addition. globalSymbols := []semantic.Symbol{"GLOBAL_TIME_BOUND"} setElementHook(globalSymbols, semantic.CollectGlobalBounds(), nil) // LIMIT clause semantic hook addition. limitSymbols := []semantic.Symbol{"LIMIT"} setElementHook(limitSymbols, semantic.LimitCollection(), nil) // Global data accumulator hook. setElementHook([]semantic.Symbol{"START"}, semantic.DataAccumulatorHook(), func(cls *Clause) bool { if t := cls.Elements[0].Token(); t != lexer.ItemInsert && t != lexer.ItemDelete { return false } return true }) setClauseHook([]semantic.Symbol{"START"}, nil, semantic.GroupByBindingsChecker()) }