core

package
v0.84.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AbortError = errors.New("abort")

Functions

func DumpAST

func DumpAST(expr Expr, depth int) string

DumpAST returns a human-readable representation of the AST. Use only for debug

func ToFloat

func ToFloat(v Value) (float64, error)

Types

type AbortExpr

type AbortExpr struct {
	Node
}

func (*AbortExpr) Eval

func (e *AbortExpr) Eval(_ EvalContext) (Value, error)

type Argument

type Argument struct {
	Name  string
	Value Expr
}

type ArrayExpr

type ArrayExpr struct {
	Node
	Elements []Expr
}

func (*ArrayExpr) Eval

func (e *ArrayExpr) Eval(ctx EvalContext) (Value, error)

type ArrayValue

type ArrayValue struct{ V []Value }

func (ArrayValue) AsBool

func (ArrayValue) AsBool() bool

func (ArrayValue) Equal

func (v ArrayValue) Equal(other Value) bool

func (ArrayValue) Kind

func (ArrayValue) Kind() ValueKind

func (ArrayValue) String

func (v ArrayValue) String() string

type AssignExpr

type AssignExpr struct {
	Node
	Target Expr
	Value  Expr
}

func (*AssignExpr) Eval

func (e *AssignExpr) Eval(ctx EvalContext) (Value, error)

type BinaryExpr

type BinaryExpr struct {
	Node
	Left  Expr
	Op    string
	Right Expr
}

func (*BinaryExpr) Eval

func (e *BinaryExpr) Eval(ctx EvalContext) (Value, error)

type BoolLit

type BoolLit struct {
	Node
	Value bool
}

func (*BoolLit) Eval

func (e *BoolLit) Eval(_ EvalContext) (Value, error)

type BoolValue

type BoolValue struct{ V bool }

func (BoolValue) AsBool

func (v BoolValue) AsBool() bool

func (BoolValue) Equal

func (v BoolValue) Equal(other Value) bool

func (BoolValue) Kind

func (BoolValue) Kind() ValueKind

func (BoolValue) String

func (v BoolValue) String() string

type CallExpr

type CallExpr struct {
	Node
	Name string
	Args []Argument
}

func (*CallExpr) Eval

func (e *CallExpr) Eval(ctx EvalContext) (Value, error)

type DelExpr

type DelExpr struct {
	Node
	Target *PathExpr
}

func (*DelExpr) Eval

func (e *DelExpr) Eval(ctx EvalContext) (Value, error)

type EvalContext

type EvalContext interface {
	GetVar(string) (Value, bool)
	SetVar(string, Value)
	DeleteVar(string)
	GetTarget() Target
	CallFunc(pos Position, name string, positional []Value, named map[string]Value) (Value, error)
}

type Expr

type Expr interface {
	Pos() Position
	Eval(ctx EvalContext) (Value, error)
}

type FloatLit

type FloatLit struct {
	Node
	Value float64
}

func (*FloatLit) Eval

func (e *FloatLit) Eval(_ EvalContext) (Value, error)

type FloatValue

type FloatValue struct{ V float64 }

func (FloatValue) AsBool

func (FloatValue) AsBool() bool

func (FloatValue) Equal

func (v FloatValue) Equal(other Value) bool

func (FloatValue) Kind

func (FloatValue) Kind() ValueKind

func (FloatValue) String

func (v FloatValue) String() string

type ForExpr

type ForExpr struct {
	Node
	Index string
	Item  string
	Iter  Expr
	Body  []Expr
}

func (*ForExpr) Eval

func (e *ForExpr) Eval(ctx EvalContext) (Value, error)

type IdentExpr

type IdentExpr struct {
	Node
	Name string
}

func (*IdentExpr) Eval

func (e *IdentExpr) Eval(ctx EvalContext) (Value, error)

type IfExpr

type IfExpr struct {
	Node
	Condition Expr
	Then      []Expr
	Else      []Expr
}

func (*IfExpr) Eval

func (e *IfExpr) Eval(ctx EvalContext) (Value, error)

type IndexExpr

type IndexExpr struct {
	Node
	Object Expr
	Index  Expr
}

func (*IndexExpr) Eval

func (e *IndexExpr) Eval(ctx EvalContext) (Value, error)

Eval resolves arr[n] and obj["key"] on local variables and call results.

type IntLit

type IntLit struct {
	Node
	Value int64
}

func (*IntLit) Eval

func (e *IntLit) Eval(_ EvalContext) (Value, error)

type IntegerValue

type IntegerValue struct{ V int64 }

func (IntegerValue) AsBool

func (IntegerValue) AsBool() bool

func (IntegerValue) Equal

func (v IntegerValue) Equal(other Value) bool

func (IntegerValue) Kind

func (IntegerValue) Kind() ValueKind

func (IntegerValue) String

func (v IntegerValue) String() string

type JSONNodeValue

type JSONNodeValue struct{ N *insaneJSON.Node }

func (JSONNodeValue) AsBool

func (v JSONNodeValue) AsBool() bool

func (JSONNodeValue) Equal

func (v JSONNodeValue) Equal(other Value) bool

func (JSONNodeValue) Kind

func (v JSONNodeValue) Kind() ValueKind

func (JSONNodeValue) String

func (v JSONNodeValue) String() string

type KVPair

type KVPair struct {
	Key   string
	Value Expr
}

type Node

type Node struct {
	// contains filtered or unexported fields
}

func NewNode

func NewNode(pos Position) Node

func (Node) Pos

func (n Node) Pos() Position

type NullLit

type NullLit struct {
	Node
}

func (*NullLit) Eval

func (e *NullLit) Eval(_ EvalContext) (Value, error)

type NullValue

type NullValue struct{}

func (NullValue) AsBool

func (NullValue) AsBool() bool

func (NullValue) Equal

func (NullValue) Equal(other Value) bool

func (NullValue) Kind

func (NullValue) Kind() ValueKind

func (NullValue) String

func (NullValue) String() string

type ObjectExpr

type ObjectExpr struct {
	Node
	Pairs []KVPair
}

func (*ObjectExpr) Eval

func (e *ObjectExpr) Eval(ctx EvalContext) (Value, error)

type ObjectValue

type ObjectValue struct{ V map[string]Value }

func (ObjectValue) AsBool

func (ObjectValue) AsBool() bool

func (ObjectValue) Equal

func (v ObjectValue) Equal(other Value) bool

func (ObjectValue) Kind

func (ObjectValue) Kind() ValueKind

func (ObjectValue) String

func (v ObjectValue) String() string

type Path

type Path struct {
	Root     PathRoot  // EventRoot (.field) or MetadataRoot (%field)
	Segments []Segment // empty == event root or metadata root
}

Path is a fully-resolved runtime path produced by the interpreter after evaluating any dynamic index expressions inside PathExpr.

type PathExpr

type PathExpr struct {
	Node
	Root     PathRoot
	Segments []PathSegment
}

func (*PathExpr) Eval

func (e *PathExpr) Eval(ctx EvalContext) (Value, error)

type PathRoot

type PathRoot int
const (
	EventRoot PathRoot = iota
	MetadataRoot
)

type PathSegment

type PathSegment struct {
	Field string
	Index Expr
}

func (PathSegment) IsField

func (s PathSegment) IsField() bool

func (PathSegment) IsIndex

func (s PathSegment) IsIndex() bool

type Position

type Position interface {
	String() string
}

type RegexLit

type RegexLit struct {
	Node
	Pattern  string
	Compiled *regexp.Regexp
}

func (*RegexLit) Eval

func (e *RegexLit) Eval(_ EvalContext) (Value, error)

type RegexValue

type RegexValue struct{ V *regexp.Regexp }

func (RegexValue) AsBool

func (RegexValue) AsBool() bool

func (RegexValue) Equal

func (v RegexValue) Equal(other Value) bool

func (RegexValue) Kind

func (RegexValue) Kind() ValueKind

func (RegexValue) String

func (v RegexValue) String() string

type Segment

type Segment struct {
	Field string // .fieldname - active when IsIndex is false
	Idx   int    // [n]        - active when IsIndex is true; negative == from end
}

Segment is a single resolved step in a runtime path. Exactly one mode is active per segment.

func FieldSeg

func FieldSeg(name string) Segment

func IndexSeg

func IndexSeg(idx int) Segment

func (Segment) IsField

func (s Segment) IsField() bool

func (Segment) IsIndex

func (s Segment) IsIndex() bool

type StringLit

type StringLit struct {
	Node
	Value string
}

func (*StringLit) Eval

func (e *StringLit) Eval(_ EvalContext) (Value, error)

type StringValue

type StringValue struct{ V string }

func (StringValue) AsBool

func (StringValue) AsBool() bool

func (StringValue) Equal

func (v StringValue) Equal(other Value) bool

func (StringValue) Kind

func (StringValue) Kind() ValueKind

func (StringValue) String

func (v StringValue) String() string

type Target

type Target interface {
	// Get retrieves the value at path.
	Get(path Path) (Value, error)

	// Set writes value at path, creating missing nodes as needed.
	Set(path Path, value Value) error

	// Delete removes the node at path. No-op when the path does not exist.
	Delete(path Path) error
}

Abstraction over the event being processed.

The interpreter accesses all data exclusively through this interface.

type TimestampLit

type TimestampLit struct {
	Node
	Value  string
	Parsed time.Time
}

func (*TimestampLit) Eval

func (e *TimestampLit) Eval(_ EvalContext) (Value, error)

type TimestampValue

type TimestampValue struct{ V time.Time }

func (TimestampValue) AsBool

func (TimestampValue) AsBool() bool

func (TimestampValue) Equal

func (v TimestampValue) Equal(other Value) bool

func (TimestampValue) Kind

func (TimestampValue) Kind() ValueKind

func (TimestampValue) String

func (v TimestampValue) String() string

type UnaryExpr

type UnaryExpr struct {
	Node
	Op      string
	Operand Expr
}

func (*UnaryExpr) Eval

func (e *UnaryExpr) Eval(ctx EvalContext) (Value, error)

type Value

type Value interface {
	Kind() ValueKind
	AsBool() bool
	Equal(Value) bool
	String() string
}

func JsonNodeToValue

func JsonNodeToValue(node *insaneJSON.Node) Value

JsonNodeToValue converts a single insaneJSON node to a Value. The conversion is recursive for arrays and objects.

type ValueKind

type ValueKind int
const (
	KindNull ValueKind = iota
	KindBool
	KindInteger
	KindFloat
	KindString
	KindArray
	KindObject
	KindRegex
	KindTimestamp
)

func (ValueKind) String

func (k ValueKind) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL