Package ast declares data structures useful for parsed and checked abstract syntax trees
This section is empty.
This section is empty.
AlphaProtoConstantAsVal converts a v1alpha1.Constant protobuf to a CEL-native ref.Val.
ConstantToVal converts a protobuf Constant to a CEL-native ref.Val.
EntryExprToProto converts an ast.EntryExpr to a protobuf CreateStruct entry
ExprToProto serializes an ast.Expr value to a protobuf Expr representation.
Heights computes the heights of all AST expressions and returns a map from expression id to height.
MaxID returns the upper-bound, non-inclusive, of ids present within the AST's Expr value.
PostOrderVisit walks the expression graph and calls the visitor in post-order (bottom-up).
PreOrderVisit walks the expression graph and calls the visitor in pre-order (top-down).
ProtoConstantAsVal converts a canonical celpb.Constant protobuf to a CEL-native ref.Val.
ReferenceInfoToProto converts a ReferenceInfo instance to a protobuf Reference suitable for serialization.
SourceInfoToProto serializes an ast.SourceInfo value to a protobuf SourceInfo object.
ToProto converts an AST to a CheckedExpr protobouf.
ValToConstant converts a CEL-native ref.Val to a protobuf Constant.
Only simple scalar types are supported by this method.
AST contains a protobuf expression and source info along with CEL-native type and reference information.
Copy creates a deep copy of the Expr and SourceInfo values in the input AST.
Copies of the Expr value are generated using an internal default ExprFactory.
NewAST creates a base AST instance with an ast.Expr and ast.SourceInfo value.
NewCheckedAST wraps an parsed AST and augments it with type and reference metadata.
ToAST converts a CheckedExpr protobuf to an AST instance.
Expr returns the root ast.Expr value in the AST.
GetOverloadIDs returns the set of overload function names for a given expression id.
If the expression id is not a function call, or the AST is not type-checked, the result will be empty.
GetType returns the type for the expression at the given id, if one exists, else types.DynType.
IsChecked returns whether the AST is type-checked.
ReferenceMap returns the map of expression id to identifier, constant, and function references.
SetReference adds a reference to the checked AST type map.
SetType sets the type of the expression node at the given id.
SourceInfo returns the source metadata associated with the parse / type-check passes.
TypeMap returns the map of expression ids to type-checked types.
If the AST is not type-checked, the map will be empty.
type CallExpr interface { FunctionName() string IsMemberFunction() bool Target() Expr Args() []Expr }
CallExpr defines an interface for inspecting a function call and its arguments.
ComprehensionExpr defines an interface for inspecting a comprehension expression.
EntryExpr represents the base entry expression in a CEL map or struct literal.
ProtoToEntryExpr converts a protobuf struct/map entry to an ast.EntryExpr
EntryExprKind represents the possible EntryExpr kinds.
Expr represents the base expression node in a CEL abstract syntax tree.
Depending on the `Kind()` value, the Expr may be converted to a concrete expression types as indicated by the `As<Kind>` methods.
ProtoToExpr converts a protobuf Expr value to an ast.Expr value.
type ExprFactory interface { CopyExpr(Expr) Expr CopyEntryExpr(EntryExpr) EntryExpr NewCall(id int64, function string, args ...Expr) Expr NewComprehension(id int64, iterRange Expr, iterVar, accuVar string, accuInit, loopCondition, loopStep, result Expr) Expr NewComprehensionTwoVar(id int64, iterRange Expr, iterVar, iterVar2, accuVar string, accuInit, loopCondition, loopStep, result Expr) Expr NewMemberCall(id int64, function string, receiver Expr, args ...Expr) Expr NewIdent(id int64, name string) Expr NewAccuIdent(id int64) Expr AccuIdentName() string NewLiteral(id int64, value ref.Val) Expr NewList(id int64, elems []Expr, optIndices []int32) Expr NewMap(id int64, entries []EntryExpr) Expr NewMapEntry(id int64, key, value Expr, isOptional bool) EntryExpr NewPresenceTest(id int64, operand Expr, field string) Expr NewSelect(id int64, operand Expr, field string) Expr NewStruct(id int64, typeName string, fields []EntryExpr) Expr NewStructField(id int64, field string, value Expr, isOptional bool) EntryExpr NewUnspecifiedExpr(id int64) Expr }
ExprFactory interfaces defines a set of methods necessary for building native expression values.
NewExprFactory creates an ExprFactory instance.
NewExprFactoryWithAccumulator creates an ExprFactory instance with a custom accumulator identifier name.
ExprKind represents the expression node kind.
const ( UnspecifiedExprKind ExprKind = iota CallKind ComprehensionKind IdentKind ListKind LiteralKind MapKind SelectKind StructKind )
ExprMatcher takes a NavigableExpr in and indicates whether the value is a match.
This function type should be use with the `Match` and `MatchList` calls.
AllMatcher returns true for all descendants of a NavigableExpr, effectively flattening them into a list.
Such a result would work well with subsequent MatchList calls.
ConstantValueMatcher returns an ExprMatcher which will return true if the input NavigableExpr is comprised of all constant values, such as a simple literal or even list and map literal.
FunctionMatcher returns an ExprMatcher which will match NavigableExpr nodes of CallKind type whose function name is equal to `funcName`.
KindMatcher returns an ExprMatcher which will return true if the input NavigableExpr.Kind() matches the specified `kind`.
IDGenerator produces unique ids suitable for tagging expression nodes
type ListExpr interface { Elements() []Expr OptionalIndices() []int32 IsOptional(int32) bool Size() int }
ListExpr defines an interface for inspecting a list literal expression.
type MapEntry interface { Key() Expr Value() Expr IsOptional() bool }
MapEntry defines an interface for inspecting a map entry.
MapExpr defines an interface for inspecting a map expression.
NavigableExpr represents the base navigable expression value with methods to inspect the parent and child expressions.
MatchDescendants takes a NavigableExpr and ExprMatcher and produces a list of NavigableExpr values matching the input criteria in post-order (bottom up).
MatchSubset applies an ExprMatcher to a list of NavigableExpr values and their descendants, producing a subset of NavigableExpr values which match.
NavigateAST converts an AST to a NavigableExpr
NavigateExpr creates a NavigableExpr whose type information is backed by the input AST.
If the expression is already a NavigableExpr, the parent and depth information will be propagated on the new NavigableExpr value; otherwise, the expr value will be treated as though it is the root of the expression graph with a depth of 0.
type OffsetRange struct { Start int32 Stop int32 }
OffsetRange captures the start and stop positions of a section of text in the input expression.
ReferenceInfo contains a CEL native representation of an identifier reference which may refer to either a qualified identifier name, a set of overload ids, or a constant value from an enum.
NewFunctionReference creates a ReferenceInfo instance for a set of function overloads.
NewIdentReference creates a ReferenceInfo instance for an identifier with an optional constant value.
ProtoToReferenceInfo converts a protobuf Reference into a CEL-native ReferenceInfo instance.
AddOverload appends a function overload ID to the ReferenceInfo.
Equals returns whether two references are identical to each other.
type SelectExpr interface { Operand() Expr FieldName() string IsTestOnly() bool }
SelectExpr defines an interface for inspecting a select expression.
type SourceInfo struct { }
SourceInfo records basic information about the expression as a textual input and as a parsed expression value.
CopySourceInfo creates a deep copy of the MacroCalls within the input SourceInfo.
Copies of macro Expr values are generated using an internal default ExprFactory.
NewSourceInfo creates a simple SourceInfo object from an input common.Source value.
ProtoToSourceInfo deserializes the protobuf into a native SourceInfo value.
ClearMacroCall removes the macro call at the given expression id.
ClearOffsetRange removes the OffsetRange for the given expression id.
ComputeOffset calculates the 0-based character offset from a 1-based line and 0-based column.
Description provides information about where the expression came from.
GetLocationByOffset returns the line and column information for a given character offset.
GetMacroCall returns the original ast.Expr value for the given expression if it was generated via a macro replacement.
Note, parsing options must be enabled to track macro calls before this method will return a value.
GetOffsetRange retrieves an OffsetRange for the given expression id if one exists.
GetStartLocation calculates the human-readable 1-based line and 0-based column of the first character of the expression node at the id.
GetStopLocation calculates the human-readable 1-based line and 0-based column of the last character for the expression node at the given id.
If the SourceInfo was generated from a serialized protobuf representation, the stop location will be identical to the start location for the expression.
LineOffsets returns a list of the 0-based character offsets in the input text where newlines appear.
MacroCalls returns a map of expression id to ast.Expr value where the id represents the expression node where the macro was inserted into the AST, and the ast.Expr value represents the original call signature which was replaced.
OffsetRanges returns a map of expression id to OffsetRange values where the range indicates either: the start and end position in the input stream where the expression occurs, or the start position only. If the range only captures start position, the stop position of the range will be equal to the start.
SetMacroCall records a macro call at a specific location.
SetOffsetRange sets the OffsetRange for the given expression id.
SyntaxVersion returns the syntax version associated with the text expression.
StructExpr defines an interfaces for inspecting a struct and its field initializers.
type StructField interface { Name() string Value() Expr IsOptional() bool }
StructField defines an interface for inspecting a struct field initialization.
type Visitor interface { VisitExpr(Expr) VisitEntryExpr(EntryExpr) }
Visitor defines an object for visiting Expr and EntryExpr nodes within an expression graph.
NewExprVisitor creates a visitor which only visits expression nodes.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4