package script
import "golang.org/x/build/cmd/watchflakes/internal/script"
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 ¶
- func Parse(file, text string, fields []string) (*Script, []*SyntaxError)
- type AndExpr
- type CmpExpr
- type Expr
- type NotExpr
- type OrExpr
- type Record
- type RegExpr
- type Rule
- type Script
- type SyntaxError
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 (*AndExpr) String ¶
type CmpExpr ¶
A CmpExpr is an Expr for a string comparison.
func (*CmpExpr) Match ¶
func (*CmpExpr) 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 (*NotExpr) String ¶
type OrExpr ¶
type OrExpr struct { X, Y Expr }
An OrExpr represents the expression X || Y.
func (*OrExpr) Match ¶
func (*OrExpr) String ¶
type Record ¶
A Record is a set of key:value pairs.
type RegExpr ¶
A RegExpr is an Expr for a regular expression test.
func (*RegExpr) Match ¶
func (*RegExpr) String ¶
type Rule ¶
A Rule is a single Action <- Pattern rule.
type Script ¶
A Script is a sequence of Action <- Pattern rules.
func (*Script) Action ¶
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
Source Files ¶
script.go
- Version
- v0.0.0-20250421191922-3619c213cff3 (latest)
- Published
- Apr 21, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 3 months ago –
Tools for package owners.