script

package
v0.0.0-...-027bb57 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package script implements a simple classification scripting language. A script is a sequence of rules of the form “action <- pattern”, meaning send results matching pattern to the named action.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(file, text string, fields []string) (*Script, []*SyntaxError)

Parse parses text as a script, returning the parsed form and any parse errors found. (The parser attempts to recover after parse errors by starting over at the next newline, so multiple parse errors are possible.) The file argument is used for reporting the file name in errors and in the Script's File field; Parse does not read from the file itself.

Types

type AndExpr

type AndExpr struct {
	X, Y Expr
}

An AndExpr represents the expression X && Y.

func (*AndExpr) Match

func (x *AndExpr) Match(record Record) bool

func (*AndExpr) String

func (x *AndExpr) String() string

type CmpExpr

type CmpExpr struct {
	Field   string
	Op      string
	Literal string
}

A CmpExpr is an Expr for a string comparison.

func (*CmpExpr) Match

func (x *CmpExpr) Match(record Record) bool

func (*CmpExpr) String

func (x *CmpExpr) String() string

type Expr

type Expr interface {
	// String returns the syntax for the pattern.
	String() string

	// Match reports whether the pattern matches the record.
	Match(record Record) bool
}

An Expr is a pattern expression that can evaluate itself on a Record. The underlying concrete type is *CmpExpr, *AndExpr, *OrExpr, *NotExpr, or *RegExpr.

type NotExpr

type NotExpr struct {
	X Expr
}

A NotExpr represents the expression !X (the negation of X).

func (*NotExpr) Match

func (x *NotExpr) Match(record Record) bool

func (*NotExpr) String

func (x *NotExpr) String() string

type OrExpr

type OrExpr struct {
	X, Y Expr
}

An OrExpr represents the expression X || Y.

func (*OrExpr) Match

func (x *OrExpr) Match(record Record) bool

func (*OrExpr) String

func (x *OrExpr) String() string

type Record

type Record map[string]string

A Record is a set of key:value pairs.

type RegExpr

type RegExpr struct {
	Field  string
	Not    bool
	Regexp *regexp.Regexp
}

A RegExpr is an Expr for a regular expression test.

func (*RegExpr) Match

func (x *RegExpr) Match(record Record) bool

func (*RegExpr) String

func (x *RegExpr) String() string

type Rule

type Rule struct {
	Action  string // "skip", "post", and so on
	Pattern Expr   // pattern expression
}

A Rule is a single Action <- Pattern rule.

type Script

type Script struct {
	File  string
	Rules []*Rule
}

A Script is a sequence of Action <- Pattern rules.

func (*Script) Action

func (s *Script) Action(record Record) string

Action returns the action specified by the script for the given record.

type SyntaxError

type SyntaxError struct {
	File   string // input file
	Line   int    // line number where error was detected (1-indexed)
	Offset int    // byte offset in line where error was detected (1-indexed)
	Err    string // description of error
}

A SyntaxError reports a syntax error in a parsed match expression.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Jump to

Keyboard shortcuts

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