parser

package
v0.0.0-...-4e7f2dc Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AndKeyword    = "AND"
	AssignKeyword = "="
	ListKeyword   = ","
	OrKeyword     = "OR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AstNode

type AstNode interface {
	Format(args FormatArgs) error
	Fields(args *FieldArgs) error
}

AstNode defines the basic interface for evaluating expressions.

func NewAst

func NewAst(tokens ...any) (AstNode, error)

NewAst answers a new AST based on the supplied tokens. Tokens will be interpreted as keywords if they exist. This bypasses the parsing stage so it can only be used to build simple ASTs.

func Parse

func Parse(term string) (AstNode, error)

Parse converts an expression string into an AST.

type FieldArgs

type FieldArgs struct {
	Fields []string
	Ctx    FormatContext
}

type Format

type Format interface {
	// Translate a keyword to the local format.
	// Example, "AND" might become "&&".
	Keyword(s string) string

	// Convert a value to a string.
	Value(v interface{}) (string, error)
}

Format provides the tokens and rules used when converting an AST to a string

func DefaultFormat

func DefaultFormat() Format

type FormatArgs

type FormatArgs struct {
	Writer io.StringWriter
	Format Format
	Ctx    FormatContext
	Eb     errors.Block
}

type FormatContext

type FormatContext int
const (
	NoFormatContext FormatContext = iota
	ValueContext                  // A value, i.e. the RHS of an assignment
)

type Opt

type Opt struct {
	// Strict causes sloppy conditions to become errors. For example, comparing a
	// number to a string is false if strict is off, but error if it's on.
	Strict bool
	// OnError is a value returned when one of the typed Eval() statements returns an error.
	// Must match the type. For example, the value must be assigend a string if using EvalString().
	OnError interface{}
}

Opt contains options for evaluation.

Jump to

Keyboard shortcuts

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