type Macro … type MacroFactory … type MacroExprFactory … type MacroExpander … type MacroExprHelper … // GlobalMacro creates a Macro for a global function with the specified arg count. func GlobalMacro(function string, argCount int, factory MacroFactory) Macro { … } // ReceiverMacro creates a Macro for a receiver function matching the specified arg count. func ReceiverMacro(function string, argCount int, factory MacroFactory) Macro { … } // GlobalVarArgMacro creates a Macro for a global function with a variable arg count. func GlobalVarArgMacro(function string, factory MacroFactory) Macro { … } // ReceiverVarArgMacro creates a Macro for a receiver function matching a variable arg count. func ReceiverVarArgMacro(function string, factory MacroFactory) Macro { … } // NewGlobalMacro creates a Macro for a global function with the specified arg count. // // Deprecated: use GlobalMacro func NewGlobalMacro(function string, argCount int, expander MacroExpander) Macro { … } // NewReceiverMacro creates a Macro for a receiver function matching the specified arg count. // // Deprecated: use ReceiverMacro func NewReceiverMacro(function string, argCount int, expander MacroExpander) Macro { … } // NewGlobalVarArgMacro creates a Macro for a global function with a variable arg count. // // Deprecated: use GlobalVarArgMacro func NewGlobalVarArgMacro(function string, expander MacroExpander) Macro { … } // NewReceiverVarArgMacro creates a Macro for a receiver function matching a variable arg count. // // Deprecated: use ReceiverVarArgMacro func NewReceiverVarArgMacro(function string, expander MacroExpander) Macro { … } // HasMacroExpander expands the input call arguments into a presence test, e.g. has(<operand>.field) func HasMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) { … } // ExistsMacroExpander expands the input call arguments into a comprehension that returns true if any of the // elements in the range match the predicate expressions: // <iterRange>.exists(<iterVar>, <predicate>) func ExistsMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) { … } // ExistsOneMacroExpander expands the input call arguments into a comprehension that returns true if exactly // one of the elements in the range match the predicate expressions: // <iterRange>.exists_one(<iterVar>, <predicate>) func ExistsOneMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) { … } // MapMacroExpander expands the input call arguments into a comprehension that transforms each element in the // input to produce an output list. // // There are two call patterns supported by map: // // <iterRange>.map(<iterVar>, <transform>) // <iterRange>.map(<iterVar>, <predicate>, <transform>) // // In the second form only iterVar values which return true when provided to the predicate expression // are transformed. func MapMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) { … } // FilterMacroExpander expands the input call arguments into a comprehension which produces a list which contains // only elements which match the provided predicate expression: // <iterRange>.filter(<iterVar>, <predicate>) func FilterMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) { … } var HasMacro … var AllMacro … var ExistsMacro … var ExistsOneMacro … var MapMacro … var MapFilterMacro … var FilterMacro … var StandardMacros … var NoMacros … type adaptingExpander … func (adapt *adaptingExpander) Expander(eh parser.ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) { … } func wrapErr(id int64, message string, err error) *common.Error { … } type adaptingHelper … // Copy the input expression with a brand new set of identifiers. func (ah *adaptingHelper) Copy(e *exprpb.Expr) *exprpb.Expr { … } // LiteralBool creates an Expr value for a bool literal. func (ah *adaptingHelper) LiteralBool(value bool) *exprpb.Expr { … } // LiteralBytes creates an Expr value for a byte literal. func (ah *adaptingHelper) LiteralBytes(value []byte) *exprpb.Expr { … } // LiteralDouble creates an Expr value for double literal. func (ah *adaptingHelper) LiteralDouble(value float64) *exprpb.Expr { … } // LiteralInt creates an Expr value for an int literal. func (ah *adaptingHelper) LiteralInt(value int64) *exprpb.Expr { … } // LiteralString creates am Expr value for a string literal. func (ah *adaptingHelper) LiteralString(value string) *exprpb.Expr { … } // LiteralUint creates an Expr value for a uint literal. func (ah *adaptingHelper) LiteralUint(value uint64) *exprpb.Expr { … } // NewList creates a CreateList instruction where the list is comprised of the optional set // of elements provided as arguments. func (ah *adaptingHelper) NewList(elems ...*exprpb.Expr) *exprpb.Expr { … } // NewMap creates a CreateStruct instruction for a map where the map is comprised of the // optional set of key, value entries. func (ah *adaptingHelper) NewMap(entries ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr { … } // NewMapEntry creates a Map Entry for the key, value pair. func (ah *adaptingHelper) NewMapEntry(key *exprpb.Expr, val *exprpb.Expr, optional bool) *exprpb.Expr_CreateStruct_Entry { … } // NewObject creates a CreateStruct instruction for an object with a given type name and // optional set of field initializers. func (ah *adaptingHelper) NewObject(typeName string, fieldInits ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr { … } // NewObjectFieldInit creates a new Object field initializer from the field name and value. func (ah *adaptingHelper) NewObjectFieldInit(field string, init *exprpb.Expr, optional bool) *exprpb.Expr_CreateStruct_Entry { … } // Fold creates a fold comprehension instruction. // // - iterVar is the iteration variable name. // - iterRange represents the expression that resolves to a list or map where the elements or // keys (respectively) will be iterated over. // - accuVar is the accumulation variable name, typically parser.AccumulatorName. // - accuInit is the initial expression whose value will be set for the accuVar prior to // folding. // - condition is the expression to test to determine whether to continue folding. // - step is the expression to evaluation at the conclusion of a single fold iteration. // - result is the computation to evaluate at the conclusion of the fold. // // The accuVar should not shadow variable names that you would like to reference within the // environment in the step and condition expressions. Presently, the name __result__ is commonly // used by built-in macros but this may change in the future. func (ah *adaptingHelper) Fold(iterVar string, iterRange *exprpb.Expr, accuVar string, accuInit *exprpb.Expr, condition *exprpb.Expr, step *exprpb.Expr, result *exprpb.Expr) *exprpb.Expr { … } // Ident creates an identifier Expr value. func (ah *adaptingHelper) Ident(name string) *exprpb.Expr { … } // AccuIdent returns an accumulator identifier for use with comprehension results. func (ah *adaptingHelper) AccuIdent() *exprpb.Expr { … } // GlobalCall creates a function call Expr value for a global (free) function. func (ah *adaptingHelper) GlobalCall(function string, args ...*exprpb.Expr) *exprpb.Expr { … } // ReceiverCall creates a function call Expr value for a receiver-style function. func (ah *adaptingHelper) ReceiverCall(function string, target *exprpb.Expr, args ...*exprpb.Expr) *exprpb.Expr { … } // PresenceTest creates a Select TestOnly Expr value for modelling has() semantics. func (ah *adaptingHelper) PresenceTest(operand *exprpb.Expr, field string) *exprpb.Expr { … } // Select create a field traversal Expr value. func (ah *adaptingHelper) Select(operand *exprpb.Expr, field string) *exprpb.Expr { … } // OffsetLocation returns the Location of the expression identifier. func (ah *adaptingHelper) OffsetLocation(exprID int64) common.Location { … } // NewError associates an error message with a given expression id. func (ah *adaptingHelper) NewError(exprID int64, message string) *Error { … } func mustAdaptToExprs(exprs []*exprpb.Expr) []ast.Expr { … } func mustAdaptToExpr(e *exprpb.Expr) ast.Expr { … } func adaptToExpr(e *exprpb.Expr) (ast.Expr, *Error) { … } func mustAdaptToEntryExpr(e *exprpb.Expr_CreateStruct_Entry) ast.EntryExpr { … } func mustAdaptToProto(e ast.Expr) *exprpb.Expr { … } func adaptToProto(e ast.Expr) (*exprpb.Expr, *Error) { … } func mustAdaptToProtoEntry(e ast.EntryExpr) *exprpb.Expr_CreateStruct_Entry { … } func toParserHelper(meh MacroExprHelper) (parser.ExprHelper, *Error) { … }