expr

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package expr compiles a small row-predicate language into a function over decoded records.

The grammar:

expr     = or
or       = and { "or" and }
and      = not { "and" not }
not      = "not" not | primary
primary  = "(" expr ")" | path op literal | path ["not"] "in" "(" literal {"," literal} ")"
         | path "is" ["not"] "empty" | path ("contains" | "starts_with") string
op       = "=" | "!=" | "<" | "<=" | ">" | ">="
path     = name { "." name }        name is an identifier or a `quoted` segment
literal  = number | 'string' | "string" | true | false

A literal's type decides how a value is compared: a string literal compares the value's text, a number literal compares numerically (a text value is parsed), a boolean literal compares true or false. A missing, null or empty value matches no comparison; use "is empty" to test for it.

Index

Constants

This section is empty.

Variables

View Source
var ErrSyntax = errors.New("syntax error")

ErrSyntax is wrapped by every parse error.

View Source
var ErrUncomparable = errors.New("value cannot be compared")

ErrUncomparable is returned in strict mode when a value cannot be compared with its literal's type.

Functions

func Option

func Option(src string, strict bool) (options.Option, error)

Option returns the pipeline option that keeps only records satisfying src, or the parse error.

Types

type Evaluator

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

Evaluator evaluates a Predicate on records. It owns scratch buffers, so one serves one worker.

func (*Evaluator) Columns

func (e *Evaluator) Columns() ([]string, []bool)

Columns returns the columns the expression compares and, for each, whether any record had it. `is empty` tests are left out: asking about a column that may be absent is their point.

func (*Evaluator) Match

func (e *Evaluator) Match(rec record.Record) (bool, error)

Match reports whether rec satisfies the predicate.

func (*Evaluator) Misses

func (e *Evaluator) Misses() int64

Misses is how many comparisons found a value of the wrong type for their literal and did not match. A comparison that is not reached because of and/or short-circuiting is not counted. It is always zero in strict mode, which fails instead.

type Predicate

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

Predicate is a compiled expression. Build one worker's evaluator with NewEvaluator; a Predicate itself holds only the parsed tree and is safe to share.

func Compile

func Compile(src string, strict bool) (*Predicate, error)

Compile parses src. In strict mode a value that cannot be compared with its literal (a non-numeric string against a number) is an error; otherwise it simply doesn't match and is counted.

func (*Predicate) NewEvaluator

func (p *Predicate) NewEvaluator() *Evaluator

NewEvaluator builds an evaluator for one worker.

func (*Predicate) Source

func (p *Predicate) Source() string

Source returns the expression text.

Jump to

Keyboard shortcuts

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