Documentation
¶
Index ¶
- Variables
- func Format(ast *AST, mode PrintMode) string
- func IndexFuncArg[T any](args map[string]any, name string) (T, error)
- func IndexKV(m KV, key string) (any, bool)
- func NodeCallName(node ASTNode) (string, bool)
- func NodeLiteral(node ASTNode) (raw string, ok bool)
- func NodeRawOperator(node ASTNode) string
- func Rewrite(ast *AST, edits []Edit, mode PrintMode) (string, error)
- func SetErrorVerbose(bool)
- type AST
- type ASTKind
- type ASTNode
- type ArrayValue
- type Diagnostic
- type DiagnosticCode
- type Edit
- type ErrInvalidFunctionArg
- type FieldValue
- type Function
- type FunctionArg
- type FunctionValue
- type HexString
- type Input
- type JSONOptions
- type KV
- type LazyContextValue
- type LazyValue
- type LiteralValue
- type Macro
- type MacroSet
- type Operator
- type Opts
- type ParseError
- type PathSegment
- type PathValue
- type PrintMode
- type Result
- type Rule
- type RuleFunc
- type Span
- type Token
- type Trace
- type TraceStatus
- type ValueParseError
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidOperation = errors.New("invalid operation")
var StdlibFuncs = map[string]*Function{ "starts_with": { Args: []FunctionArg{ {Name: "value"}, {Name: "prefix"}, }, Eval: func(args map[string]any) Result { value, err := IndexFuncArg[any](args, "value") if err != nil { return Result{Error: err} } prefix, err := IndexFuncArg[any](args, "prefix") if err != nil { return Result{Error: err} } return Result{ Value: strings.HasPrefix(fmt.Sprint(value), fmt.Sprint(prefix)), } }, }, }
Functions ¶
func NodeCallName ¶
NodeCallName returns the function or macro name for call nodes.
func NodeLiteral ¶
NodeLiteral returns the raw literal token for literal nodes.
func NodeRawOperator ¶
NodeRawOperator returns the source operator spelling for unary and binary nodes.
func SetErrorVerbose ¶
func SetErrorVerbose(bool)
SetErrorVerbose is retained for API compatibility. The hand-written parser always returns verbose ParseError values.
Types ¶
type AST ¶
type AST struct {
// contains filtered or unexported fields
}
AST is a parsed expression tree. The current public AST is immutable; callers that edit expressions should parse, inspect, and compile replacement trees.
type ArrayValue ¶
type ArrayValue struct {
// contains filtered or unexported fields
}
func (*ArrayValue) Print ¶
func (a *ArrayValue) Print(PrintMode) string
func (*ArrayValue) String ¶
func (a *ArrayValue) String() string
type Diagnostic ¶
type Diagnostic struct {
Code DiagnosticCode
Message string
LeftType string
Operator string
RightType string
}
Diagnostic provides optional evaluation details for trace consumers.
type DiagnosticCode ¶
type DiagnosticCode string
const ( DiagnosticComparisonIncomparable DiagnosticCode = "comparison_incomparable" DiagnosticComparisonInvalidShape DiagnosticCode = "comparison_invalid_shape" DiagnosticComparisonUnsupportedOperator DiagnosticCode = "comparison_unsupported_operator" )
type ErrInvalidFunctionArg ¶
func (*ErrInvalidFunctionArg) Error ¶
func (e *ErrInvalidFunctionArg) Error() string
type FieldValue ¶
type FieldValue string
func (FieldValue) Print ¶
func (f FieldValue) Print(PrintMode) string
func (FieldValue) String ¶
func (f FieldValue) String() string
type Function ¶
type Function struct {
// Args is an optional list of arguments that the function expects.
// If set, rulekit will ensure validity of the arguments and pass them as a named map to the Eval function.
Args []FunctionArg
// Eval is the function that will be called with the arguments.
Eval func(map[string]any) Result
}
type FunctionArg ¶
type FunctionArg struct {
Name string
}
type FunctionValue ¶
type FunctionValue struct {
// contains filtered or unexported fields
}
func (*FunctionValue) Print ¶
func (f *FunctionValue) Print(PrintMode) string
func (*FunctionValue) String ¶
func (f *FunctionValue) String() string
func (*FunctionValue) ValidateStdlibFnArgs ¶
func (f *FunctionValue) ValidateStdlibFnArgs() error
type HexString ¶
type HexString struct {
Bytes []byte
// contains filtered or unexported fields
}
HexString represents a hex-encoded string retaining the original input string
func ParseHexString ¶
type JSONOptions ¶
type KV ¶
func DecodeJSON ¶
func DecodeJSON(data []byte, opts JSONOptions) (KV, error)
DecodeJSON decodes a JSON object into a Rulekit KV value map.
type LiteralValue ¶
type LiteralValue[T any] struct { // contains filtered or unexported fields }
func (*LiteralValue[T]) Print ¶
func (l *LiteralValue[T]) Print(PrintMode) string
func (*LiteralValue[T]) String ¶
func (l *LiteralValue[T]) String() string
type Operator ¶
type Operator int
Operator identifies normalized unary and binary operators.
func NodeOperator ¶
NodeOperator returns a normalized operator for unary and binary nodes.
type ParseError ¶
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type PathSegment ¶
PathSegment is a public read-only path segment value.
func NodePath ¶
func NodePath(node ASTNode) ([]PathSegment, bool)
NodePath returns path segments for path nodes.
type PathValue ¶
type PathValue struct {
// contains filtered or unexported fields
}
PathValue evaluates an explicit map/slice path, including bracket key and numeric index segments.
type PrintMode ¶
type PrintMode interface {
// contains filtered or unexported methods
}
PrintMode selects how a rule or AST should be printed.
type Result ¶
func (Result) Complete ¶
Complete returns true if the rule evaluated without errors or missing fields.
func (Result) Fail ¶
Fail returns true if the rule is ok and returns a zero value. This is usually used for boolean rules.
func (Result) Ok ¶
Ok returns true if the rule evaluated completely without errors or missing fields.
type Rule ¶
type Rule interface {
// Evaluates the rule with the context and input.
Eval(context.Context, Input, Opts) Result
// Print prints the rule with the requested mode.
Print(PrintMode) string
// String representation of the rule
String() string
}
type Trace ¶
type Trace struct {
Node ASTNode
Expr string
Value any
Error error
MissingFields []string
Diagnostics []Diagnostic
Status TraceStatus
Active bool
Pruned bool
Children []*Trace
}
Trace explains how a rule evaluation reached its result.
type TraceStatus ¶
type TraceStatus string
const ( TraceUnknown TraceStatus = "unknown" TracePassed TraceStatus = "passed" TraceFailed TraceStatus = "failed" TraceMissing TraceStatus = "missing" TraceError TraceStatus = "error" TracePruned TraceStatus = "pruned" )
type ValueParseError ¶
func (ValueParseError) Error ¶
func (e ValueParseError) Error() string
