lucette

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Returned when the typer detects an invalid datetime.
	ErrBadDateTime = errors.Base("bad datetime value")

	// Returned should an attempt be made to `unread` after a rune has
	// already been put back into the reader.
	ErrDoubleUnread = errors.Base("double unread")

	// Returned if the lexer is invoked without a valid reader.
	ErrInvalidReader = errors.Base("reader is not valid")

	// Returned when the code generator detects a label without a target.
	ErrJumpMissingArg = errors.Base("jump missing target arg")

	// Returned when the code generator detects a label with an invalid
	// target.
	ErrJumpNotLabelID = errors.Base("jump target arg not LabelID")

	// Returned when the code generator detects a label with a bad ID.
	ErrLabelBadIDType = errors.Base("LABEL has bad id type")

	// Returned when the code generator detects a label that lacks an ID.
	ErrLabelMissingID = errors.Base("LABEL missing id")

	// Returned when the lexer detects an embedded newline in a field
	// name.
	ErrNewlineInField = errors.Base("embedded newline in field")

	// Returned when the lexer detects an embedded newline in a phrase.
	ErrNewlineInPhrase = errors.Base("embedded newline in phrase")

	// Returned when the lexer detects a newline in a regular expression.
	ErrNewlineInRegex = errors.Base("embedded newline in regular expression")

	// Returned if no tokens were provided.
	ErrNoTokens = errors.Base("no tokens")

	// Returned when the lexer detects unsupported flags in a regular
	// expression.
	ErrRegexFlags = errors.Base("regex flags not supported")

	// Returned when the code generator detects a label that has not been
	// bound to a target.
	ErrUnboundLabel = errors.Base("unbound label")

	// Returned when the lexer detects an unexpected bareword in the
	// source code.
	ErrUnexpectedBareword = errors.Base("unexpected bareword (missing quotes or field?)")

	// Returned when the lexer detects an unexpected character.
	ErrUnexpectedRune = errors.Base("unexpected rune")

	// Returned when the lexer detects an unexpected token in the source
	// code.
	ErrUnexpectedToken = errors.Base("unexpected token")

	// Returned when the typer detects an unknown literal.
	ErrUnknownLiteral = errors.Base("unknown literal")

	// Returned when the lexer detects that a quoted field name is
	// unterminated.
	ErrUnterminatedField = errors.Base("unterminated quoted field")

	// Returned when the lexer detects an unterminated regular expression.
	ErrUnterminatedRegex = errors.Base("unterminated regular expression")

	// Returned when the lexer detects an unterminated quoted string.
	ErrUnterminatedString = errors.Base("unterminated string")
)
View Source
var (
	// A span with zero values.
	ZeroSpan = &Span{}
)

Functions

func ComparatorKindToString

func ComparatorKindToString(kind ComparatorKind) string

Return the string representation for a comparator kind.

func FieldTypeToString

func FieldTypeToString(fType FieldType) string

func LiteralKindToString

func LiteralKindToString(lit LiteralKind) string

Return the string representation of a literal type.

func ModifierKindToString

func ModifierKindToString(kind ModifierKind) string

Return the string representation of a modifier.

func PredicateKindToString

func PredicateKindToString(kind PredicateKind) string

Return the string representation for a predicate kind.

Types

type ASTAnd

type ASTAnd struct {
	Kids []ASTNode // Child nodes.
	// contains filtered or unexported fields
}

An AST node for the `AND' logical operator.

func (ASTAnd) Debug

func (n ASTAnd) Debug(params ...any) *debug.Debug

Display debugging information.

func (ASTAnd) Span

func (n ASTAnd) Span() *Span

Return the span for the AST node.

type ASTComparator

type ASTComparator struct {
	Atom ASTLiteral     // Atom on which to operate.
	Op   ComparatorKind // Comparator operator.
}

Comparator structure.

func (ASTComparator) Debug

func (c ASTComparator) Debug(params ...any) *debug.Debug

Display debugging information.

type ASTLiteral

type ASTLiteral struct {
	String string // String value.

	Kind   LiteralKind // Kind of the literal.
	Number float64     // Numeric value.
	// contains filtered or unexported fields
}

An AST node for a `literal' of some kind.

func (ASTLiteral) Debug

func (n ASTLiteral) Debug(params ...any) *debug.Debug

Display debugging information.

func (ASTLiteral) Span

func (n ASTLiteral) Span() *Span

Return the span for the AST node.

type ASTModifier

type ASTModifier struct {
	Kid ASTNode // Node to which the modifier applies.

	Kind ModifierKind // Modifier kind.
	// contains filtered or unexported fields
}

An AST node for a `modifier' to an operation..

func (ASTModifier) Debug

func (n ASTModifier) Debug(params ...any) *debug.Debug

Display debugging information.

func (ASTModifier) Span

func (n ASTModifier) Span() *Span

Return the span for the AST node.

type ASTNode

type ASTNode interface {
	// Return the span for this node.
	//
	// Spans can be used in diagnostics to show where in the source file
	// an issue exists.
	Span() *Span

	// Print debugging information for the given node.
	Debug(...any) *debug.Debug
}

Abstract Syntax Tree.

type ASTNot

type ASTNot struct {
	Kid ASTNode // Child node.
	// contains filtered or unexported fields
}

An AST node for the `NOT' logical operator.

func (ASTNot) Debug

func (n ASTNot) Debug(params ...any) *debug.Debug

Display debugging information.

func (ASTNot) Span

func (n ASTNot) Span() *Span

Return the span for the AST node.

type ASTOr

type ASTOr struct {
	Kids []ASTNode // Child nodes.
	// contains filtered or unexported fields
}

An AST node for the `OR' logical operator.

func (ASTOr) Debug

func (n ASTOr) Debug(params ...any) *debug.Debug

Display debugging information.

func (ASTOr) Span

func (n ASTOr) Span() *Span

Return the span for the AST node.

type ASTPredicate

type ASTPredicate struct {
	Range *ASTRange // Target range value

	Comparator *ASTComparator // Comparator to use.
	Fuzz       *float64       // Levenshtein Distance.
	Boost      *float64       // Boost value.
	Field      string         // Target field.
	String     string         // Target string value.
	Regex      string         // Target regex pattern.

	Kind      PredicateKind // Predicate kind.
	Number    float64       // Target numeric value.
	Proximity int           // String promity.
	// contains filtered or unexported fields
}

An AST node for predicates.

func (ASTPredicate) Debug

func (n ASTPredicate) Debug(params ...any) *debug.Debug

Display debugging information.

func (ASTPredicate) Span

func (n ASTPredicate) Span() *Span

Return the span for the AST node.

type ASTRange

type ASTRange struct {
	Lo   *ASTLiteral // Start of range.
	Hi   *ASTLiteral // End of range.
	IncL bool        // Start is inclusive?
	IncH bool        // End is inclusive?
}

Range structure.

func (ASTRange) Debug

func (r ASTRange) Debug(params ...any) *debug.Debug

Display debugging information.

type BooleOp

type BooleOp int

Boolean operation type.

const (
	BooleAnd BooleOp = iota
	BooleOr
)

type ComparatorKind

type ComparatorKind int

Comparator kind type.

const (
	ComparatorLT  ComparatorKind = iota // Comparator is `LT'.
	ComparatorLTE                       // Comparator is `LTE'.
	ComparatorGT                        // Comparator is `GT'.
	ComparatorGTE                       // Comparator is `GTE'.
	ComparatorEQ                        // Comparator is `EQ'.
	ComparatorNEQ                       // Comparator is `NEQ'.
)

func InvertComparator

func InvertComparator(kind ComparatorKind) ComparatorKind

type Diagnostic

type Diagnostic struct {
	Msg  string // Diagnostic message.
	At   *Span  // Location within source code.
	Hint string // Hint message, if applicable.
}

func NewDiagnostic

func NewDiagnostic(msg string, at *Span) Diagnostic

func NewDiagnosticHint

func NewDiagnosticHint(msg, hint string, at *Span) Diagnostic

func (Diagnostic) String

func (d Diagnostic) String() string

Return the string representation of a diagnostic.

type Disassembler

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

func NewDefaultDisassembler

func NewDefaultDisassembler() *Disassembler

func NewDisassembler

func NewDisassembler(opts DisassemblerOpts) *Disassembler

func (*Disassembler) Dissassemble

func (d *Disassembler) Dissassemble(writer io.Writer)

func (*Disassembler) SetProgram

func (d *Disassembler) SetProgram(program *Program)

type DisassemblerOpts

type DisassemblerOpts struct {
	WithComments bool // Include decoded comments?
	AddrWidth    int  // Width of an address.  0 = auto.
	OpcodeWidth  int  // Pad opcode column. 0 auto.
	OperandWidth int  // Pad operand column. 0 = auto.
}

func NewDefaultDisassemblerOpts

func NewDefaultDisassemblerOpts() DisassemblerOpts

type FieldSpec

type FieldSpec struct {
	Name     string    // Name of the field.
	FType    FieldType // Field type of the field.
	Analyser string    // Unused.
	Layouts  []string  // Layouts used for type parsers.
}

type FieldType

type FieldType int
const (
	FTKeyword FieldType = iota
	FTText
	FTNumeric
	FTDateTime
	FTIP
)

type IRAnd

type IRAnd struct {
	Kids []IRNode
}

func (IRAnd) Debug

func (n IRAnd) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRAnd) Emit

func (n IRAnd) Emit(program *Program, tLabel, fLabel LabelID)

Emit opcode.

func (IRAnd) Key

func (n IRAnd) Key() string

Generate key.

type IRAny

type IRAny struct {
	Field string
}

func (IRAny) Debug

func (n IRAny) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRAny) Emit

func (n IRAny) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRAny) Key

func (n IRAny) Key() string

Generate the key.

type IRFalse

type IRFalse struct {
}

func (IRFalse) Debug

func (n IRFalse) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRFalse) Emit

func (n IRFalse) Emit(_ *Program, _, _ LabelID)

Emit opcode.

func (IRFalse) Key

func (n IRFalse) Key() string

Generate key.

type IRGlob

type IRGlob struct {
	Field string
	Glob  string
}

func (IRGlob) Debug

func (n IRGlob) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRGlob) Emit

func (n IRGlob) Emit(program *Program, trueLabel, falseLabel LabelID)

Emit opcode.

func (IRGlob) Key

func (n IRGlob) Key() string

Generate the key.

type IRIPCmp

type IRIPCmp struct {
	Field string
	Op    ComparatorKind
	Value netip.Addr
}

func (IRIPCmp) Debug

func (n IRIPCmp) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRIPCmp) Emit

func (n IRIPCmp) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRIPCmp) Key

func (n IRIPCmp) Key() string

Generate the key.

type IRIPRange

type IRIPRange struct {
	Field string
	Lo    netip.Addr
	Hi    netip.Addr
	IncL  bool
	IncH  bool
}

func (IRIPRange) Debug

func (n IRIPRange) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRIPRange) Emit

func (n IRIPRange) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRIPRange) Key

func (n IRIPRange) Key() string

Generate the key.

type IRNode

type IRNode interface {
	// Return a unique key for the node.
	//
	// This is used during code generation.
	Key() string

	// Print debugging information.
	Debug(...any) *debug.Debug

	// Emit code.
	Emit(*Program, LabelID, LabelID)
}

An intermediate representation node of a syntactic element.

type IRNot

type IRNot struct {
	Kid IRNode
}

func (IRNot) Debug

func (n IRNot) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRNot) Emit

func (n IRNot) Emit(program *Program, trueLabel, falseLabel LabelID)

Emit opcode.

func (IRNot) Key

func (n IRNot) Key() string

Generate key.

type IRNumberCmp

type IRNumberCmp struct {
	Field string
	Op    ComparatorKind
	Value float64
}

func (IRNumberCmp) Debug

func (n IRNumberCmp) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRNumberCmp) Emit

func (n IRNumberCmp) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRNumberCmp) Key

func (n IRNumberCmp) Key() string

Generate the key.

type IRNumberRange

type IRNumberRange struct {
	Field string
	Lo    *float64
	Hi    *float64
	IncL  bool
	IncH  bool
}

func (IRNumberRange) Debug

func (n IRNumberRange) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRNumberRange) Emit

func (n IRNumberRange) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRNumberRange) Key

func (n IRNumberRange) Key() string

Generate the key.

type IROr

type IROr struct {
	Kids []IRNode
}

func (IROr) Debug

func (n IROr) Debug(params ...any) *debug.Debug

Display debugging information.

func (IROr) Emit

func (n IROr) Emit(program *Program, trueLabel, falseLabel LabelID)

Emit opcode.

func (IROr) Key

func (n IROr) Key() string

Generate key.

type IRPhrase

type IRPhrase struct {
	Field     string
	Phrase    string
	Proximity int
	Fuzz      *float64
	Boost     *float64
}

func (IRPhrase) Debug

func (n IRPhrase) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRPhrase) Emit

func (n IRPhrase) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRPhrase) HasWildcard

func (n IRPhrase) HasWildcard() bool

func (IRPhrase) Key

func (n IRPhrase) Key() string

Generate the key.

type IRPrefix

type IRPrefix struct {
	Field  string
	Prefix string
}

func (IRPrefix) Debug

func (n IRPrefix) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRPrefix) Emit

func (n IRPrefix) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRPrefix) Key

func (n IRPrefix) Key() string

Generate a key.

type IRRegex

type IRRegex struct {
	Field    string
	Pattern  string
	Compiled *regexp.Regexp
}

func (IRRegex) Debug

func (n IRRegex) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRRegex) Emit

func (n IRRegex) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRRegex) Key

func (n IRRegex) Key() string

Generate the key.

type IRStringEQ

type IRStringEQ struct {
	Field string
	Value string
}

func (IRStringEQ) Debug

func (n IRStringEQ) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRStringEQ) Emit

func (n IRStringEQ) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRStringEQ) Key

func (n IRStringEQ) Key() string

Generate the key.

type IRStringNEQ

type IRStringNEQ struct {
	Field string
	Value string
}

func (IRStringNEQ) Debug

func (n IRStringNEQ) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRStringNEQ) Emit

func (n IRStringNEQ) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRStringNEQ) Key

func (n IRStringNEQ) Key() string

Generate the key.

type IRTimeCmp

type IRTimeCmp struct {
	Field string
	Op    ComparatorKind
	Value int64
}

func (IRTimeCmp) Debug

func (n IRTimeCmp) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRTimeCmp) Emit

func (n IRTimeCmp) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRTimeCmp) Key

func (n IRTimeCmp) Key() string

Generate the key.

type IRTimeRange

type IRTimeRange struct {
	Field string
	Lo    *int64
	Hi    *int64
	IncL  bool
	IncH  bool
}

func (IRTimeRange) Debug

func (n IRTimeRange) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRTimeRange) Emit

func (n IRTimeRange) Emit(program *Program, trueLabel, falseLabel LabelID)

Generate opcode.

func (IRTimeRange) Key

func (n IRTimeRange) Key() string

Generate the key.

type IRTrue

type IRTrue struct {
}

func (IRTrue) Debug

func (n IRTrue) Debug(params ...any) *debug.Debug

Display debugging information.

func (IRTrue) Emit

func (n IRTrue) Emit(_ *Program, _, _ LabelID)

Emit opcode.

func (IRTrue) Key

func (n IRTrue) Key() string

Generate key.

type Instr

type Instr struct {
	Op   OpCode // Instruction's opcode.
	Args []any  // Instruction's operands.
}

func (Instr) IsJump

func (isn Instr) IsJump() bool

Is the instruction a jump of some kind?

func (Instr) String

func (isn Instr) String() string

Return the string representation of an instruction.

type LabelID

type LabelID int

Label identifier type.

type LexedToken

type LexedToken struct {
	Literal Literal  // Literal value for the token.
	Lexeme  string   // Lexeme for the token.
	Start   Position // Start position within source code.
	End     Position // End position within source code.
	Token   Token    // The token.
}

A lexed token.

func NewLexedToken

func NewLexedToken(token Token, lexeme string, start, end Position) LexedToken

Return a new lexed token with the given lexeme.

func NewLexedTokenWithError

func NewLexedTokenWithError(token Token, lexeme string, err error, start, end Position) LexedToken

Return a new lexed token with the given lexeme and error message.

func NewLexedTokenWithLiteral

func NewLexedTokenWithLiteral(token Token, lexeme string, lit any, start, end Position) LexedToken

Return a new lexed token with the given lexeme and literal.

func (*LexedToken) Debug

func (lt *LexedToken) Debug(params ...any) *debug.Debug

Display debugging information.

func (*LexedToken) String

func (lt *LexedToken) String() string

type Lexer

type Lexer interface {
	Reset()
	Tokens() []LexedToken
	Lex(io.Reader) ([]LexedToken, error)
}

func NewLexer

func NewLexer() Lexer

Create a new lexer.

type Literal

type Literal struct {
	Value any   // The literal value.
	Err   error // The error to pass as a literal.
}

Literal value structure.

func NewErrorLiteral

func NewErrorLiteral(err error) Literal

Create a new error literal.

func NewLiteral

func NewLiteral(value any) Literal

Create a new value literal.

func (Literal) Error

func (l Literal) Error() string

Return the error message if one is present.

func (Literal) IsError

func (l Literal) IsError() bool

Is the literal an error?

func (Literal) String

func (l Literal) String() string

Return the string representation of the literal.

type LiteralKind

type LiteralKind int

Literal kind type.

const (
	LString    LiteralKind = iota // Literal is a string.
	LNumber                       // Literal is a number.
	LUnbounded                    // Literal has no value bound to it.
)

type ModifierKind

type ModifierKind int

Modifier kind type.

const (
	// This modifier will mark the predicate to which it is attached as
	// having a required value.  If the value is not present, then the
	// predicate will fail.
	ModRequire ModifierKind = iota

	// This modifier will mark the predicate to which it is attached as
	// having a prohibited value.  If the value is present, then the
	// predicate will fail.
	ModProhibit
)

type NNF

type NNF interface {
	NNF(IRNode) IRNode
}

func NewNNF

func NewNNF() NNF

type OpCode

type OpCode int

Opcode.

const (

	// No operation.
	OpNoOp OpCode = iota

	// Return the contents of the accumulator.
	//
	// `RET: <- ACC`
	OpReturn

	// Special instruction used by the code generator to mark a
	// program location as a label for use by the jump instructions.
	//
	// This instruction is not part of the bytecode.  It is removed
	// when the label resolver processes code for jump addresses.
	//
	// Should it be included in a bytecode instruction stream, it will
	// equate to a NOP.
	OpLabel

	// Jump to label.
	//
	// `JMP lbl: (jump)`
	OpJump

	// Jump to label if accumulator is zero.
	//
	// `JZ lbl: (jump if ACC == 0)`
	OpJumpZ

	// Jump to label if accumulator is non-zero.
	//
	// `JNZ lbl: (jump if ACC > 0)`
	OpJumpNZ

	// Negate the value in the accumulator.
	//
	// `NOT: `ACC <- !ACC`
	OpNot

	// Load an immediate into accumulator.
	//
	// `LDA imm: ACC <- imm`
	OpLoadA

	// Load a field ID into the field register.
	//
	// `LDFLD fid: `FIELD <- fid`
	OpLoadField

	// Load a value into the boost register.
	//
	// `LDBST imm: `BOOST <- imm`
	OpLoadBoost

	// Load a value into the fuzzy register.
	//
	// `LDFZY imm: `FUZZY <- imm`
	OpLoadFuzzy

	// Compare the current field to the given string constant for
	// equality.
	//
	// Stores the result in the accumulator.
	//
	// `EQ.S sIdx: ACC <- field[FIELD} == string[sIdx]`
	OpStringEQ

	// Compare the current field to the given string constant for
	// inequality.
	//
	// Stores the result in the accumulator.
	//
	// `EQ.S sIdx: ACC <- field[FIELD} != string[sIdx]`
	OpStringNEQ

	// Test whether the current field has the given string constant as
	// a prefix.
	//
	// Stores the result in the accumulator.
	//
	// `PFX.S sIdx: ACC <- HasPrefix(field[FIELD], string[sIdx])`
	OpPrefix

	// Test whether the current field matches the given glob pattern.
	//
	// Stores the result in the accumulator.
	//
	// `GLB.S sIdx: ACC <- MatchesGlob(field[FIELD], string[sIdx])`
	OpGlob

	// Perform a regular expression match of the current field against
	// the given regular expression constant.
	//
	// Stores the result in the accumulator.
	//
	// `REX.S rIdx: ACC <- MatchesRexeg(field[FIELD], regex[rIdx])`
	OpRegex

	// Test whether the current field contains the given string constant
	// as a phrase.
	//
	// If non-zero, the `prox` argument specifies maximum Levenshtein
	// distance (proximity) allowed for a match.
	//
	// Stores the result in the accumulator.
	//
	// `PHR.S sIdx: ACC <- MatchesPhrase(field[FIELD], string[sIdx])`
	OpPhrase

	// Test whether the current field has any value at all.
	//
	// Stores the result in the accumulator.
	//
	// `ANY: ACC <- HasAnyValue(field[FIELD])`
	OpAny

	// Test whether the current field has equality with the given
	// number constant.
	//
	// Stores the result in the accumulator.
	//
	// `EQ.N nIdx: ACC <- (field[FIELD] == number[nIdx])`
	OpNumberEQ

	// Test whether the current field has inequality with the given
	// number constant.
	//
	// Stores the result in the accumulator.
	//
	// `NEQ.N nIdx: ACC <- (field[FIELD] != number[nIdx])`
	OpNumberNEQ

	// Test whether the current field has a value that is lesser than
	// the given number constant.
	//
	// Stores the result in the accumulator.
	//
	// `LT.N nIdx: ACC <- (field[FIELD] < number[nIdx])
	OpNumberLT

	// Test whether the current field has a value that is lesser than or
	// equal to the given number constant.
	//
	// Stores the result in the accumulator.
	//
	// `LTE.N nIdx: ACC <- (field[FIELD] <= number[nIdx])
	OpNumberLTE

	// Test whether the current field has a value that is greater than
	// the given number constant.
	//
	// Stores the result in the accumulator.
	//
	// `GT.N nIdx: ACC <- (field[FIELD] > number[nIdx])
	OpNumberGT

	// Test whether the current field has a value that is greater than or
	// equal to the given number constant.
	//
	// Stores the result in the accumulator.
	//
	// `GTE.N nIdx: ACC <- (field[FIELD] >= number[nIdx])
	OpNumberGTE

	// Test whether the current field has a value that falls within the
	// given range.
	//
	// `loIdx` is the starting number in the range.
	// `hiIdx` is the ending number in the range.
	// `incL` is non-zero if the range is to be inclusive at the lowest.
	// `incH' is non-zero if the range is to be inclusive at the highest.
	//
	// Stores the results in the accumulator.
	//
	// RNG.N loIdx hiIdx incL incH: ACC <- inRange(field[field]...)`
	OpNumberRange

	// Test whether the current field has equality with the given
	// date/time constant.
	//
	// Stores the result in the accumulator.
	//
	// `EQ.T tIdx: ACC <- (field[FIELD] == time[tIdx])`
	OpTimeEQ

	// Test whether the current field has inequality with the given
	// date/time constant.
	//
	// Stores the result in the accumulator.
	//
	// `NEQ.T tIdx: ACC <- (field[FIELD] != time[tIdx])`
	OpTimeNEQ

	// Test whether the current field has a value that is lesser than
	// the given date/time constant.
	//
	// Stores the result in the accumulator.
	//
	// `LT.T tIdx: ACC <- (field[FIELD] < time[tIdx])
	OpTimeLT

	// Test whether the current field has a value that is lesser than or
	// equal to the given date/time constant.
	//
	// Stores the result in the accumulator.
	//
	// `LTE.T tIdx: ACC <- (field[FIELD] <= time[tIdx])
	OpTimeLTE

	// Test whether the current field has a value that is greater than
	// the given date/time constant.
	//
	// Stores the result in the accumulator.
	//
	// `GT.T nIdx: ACC <- (field[FIELD] > time[tIdx])
	OpTimeGT

	// Test whether the current field has a value that is greater than or
	// equal to the given date/time constant.
	//
	// Stores the result in the accumulator.
	//
	// `GTE.T tIdx: ACC <- (field[FIELD] >= timer[tIdx])
	OpTimeGTE

	// Test whether the current field has a value that falls within the
	// given range.
	//
	// `loIdx` is the starting date/time in the range.
	// `hiIdx` is the ending date/time in the range.
	// `incL` is non-zero if the range is to be inclusive at the lowest.
	// `incH' is non-zero if the range is to be inclusive at the highest.
	//
	// Stores the results in the accumulator.
	//
	// RNG.T loIdx hiIdx incL incH: ACC <- inRange(field[field]...)`
	OpTimeRange

	// Test whether the current field has equality with the given
	// IP address constant.
	//
	// Stores the result in the accumulator.
	//
	// `EQ.IP ipIdx: ACC <- (field[FIELD] == address[ipIdx])`
	OpIPEQ

	// Test whether the current field has inequality with the given
	// IP address constant.
	//
	// Stores the result in the accumulator.
	//
	// `NEQ.IP ipIdx: ACC <- (field[FIELD] != address[ipIdx])`
	OpIPNEQ

	// Test whether the current field has a value that is lesser than
	// the given IP address constant.
	//
	// Stores the result in the accumulator.
	//
	// `LT.IP ipIdx: ACC <- (field[FIELD] < address[ipIdx])
	OpIPLT

	// Test whether the current field has a value that is lesser than or
	// equal to the given IP address constant.
	//
	// Stores the result in the accumulator.
	//
	// `LTE.IP ipIdx: ACC <- (field[FIELD] <= address[ipIdx])
	OpIPLTE

	// Test whether the current field has a value that is greater than
	// the given IP address constant.
	//
	// Stores the result in the accumulator.
	//
	// `GT.IP ipIdx: ACC <- (field[FIELD] > address[ipIdx])
	OpIPGT

	// Test whether the current field has a value that is greater than or
	// equal to the given IP address constant.
	//
	// Stores the result in the accumulator.
	//
	// `GTE.IP ipIdx: ACC <- (field[FIELD] >= address[ipIdx])
	OpIPGTE

	// Test whether the current field has a value that falls within the
	// given range.
	//
	// `loIdx` is the starting IP address in the range.
	// `hiIdx` is the ending IP address in the range.
	// `incL` is non-zero if the range is to be inclusive at the lowest.
	// `incH' is non-zero if the range is to be inclusive at the highest.
	//
	// Stores the results in the accumulator.
	//
	// RNG.IP loIdx hiIdx incL incH: ACC <- inRange(field[field]...)`
	OpIPRange

	// Test whether the current field is within a CIDR range.
	//
	// `IN.CIDR ipIdx, prefix: ACC <- (field[FIELD] = cidr[ipIdx,prefix])`
	OpInCIDR

	// Maximum number of opcode currently supported.
	OpMaximum
)

func GetIPComparator

func GetIPComparator(cmp ComparatorKind, def OpCode) OpCode

Return the relevant IP address opcode for the given comparator.

If no opcode is found, then `def` will be used instead.

func GetNumberComparator

func GetNumberComparator(cmp ComparatorKind, def OpCode) OpCode

Return the relevant numeric opcode for the given comparator.

If no opcode is found, then `def` will be used instead.

func GetTimeComparator

func GetTimeComparator(cmp ComparatorKind, def OpCode) OpCode

Return the relevant date/time opcode for the given comparator.

If no opcode is found, then `def` will be used instead.

type Parser

type Parser interface {
	// Reset the parser state.
	Reset()

	// Parse the list of lexed tokens and generate an AST.
	Parse([]LexedToken) (ASTNode, []Diagnostic)

	// Return a list of diagnostic messages.
	Diagnostics() []Diagnostic
}

func NewParser

func NewParser() Parser

Create a new parser instance.

type Position

type Position struct {
	Line   int // Line number.
	Column int // Column number.
}

Position within source code.

func NewEmptyPosition

func NewEmptyPosition() Position

Create a new empty position.

func NewPosition

func NewPosition(line, col int) Position

Create a new position with the given line and column numbers.

func (Position) String

func (p Position) String() string

Return the string representation of a position.

type PredicateKind

type PredicateKind int

Predicate kind type.

const (
	PredicateCMP    PredicateKind = iota // Predicate is a comparator.
	PredicateEQS                         // Predicate is `EQ.S'.
	PredicateANY                         // Predicate is `ANY'.
	PredicateGLOB                        // Predicate is `GLOB'.
	PredicateNEQS                        // Predicate is `NEQ.S'.
	PredicatePHRASE                      // Predicate is `PHRASE'.
	PredicatePREFIX                      // Predicate is `PREFIX'.
	PredicateRANGE                       // Predicate is `RANGE'.
	PredicateREGEX                       // Predicate is `REGEX'.
)

type Program

type Program struct {
	Fields   []string         // Field constants.
	Strings  []string         // String constants.
	Numbers  []float64        // Number constants.
	Times    []int64          // Date/time constants.
	IPs      []netip.Addr     // IP address constants.
	Patterns []*regexp.Regexp // Regular expression constants.
	Code     []Instr          // Bytecode.
	// contains filtered or unexported fields
}

func NewProgram

func NewProgram() *Program

Create a new program instance.

func (*Program) AddFieldConstant

func (p *Program) AddFieldConstant(val string) int

Add a field name constant.

If the given constant value exists, then an index to its array position is returned.

func (*Program) AddIPConstant

func (p *Program) AddIPConstant(val netip.Addr) int

Add an IP address constant.

If the given constant value exists, then an index to its array position is returned.

func (*Program) AddNumberConstant

func (p *Program) AddNumberConstant(val float64) int

Add a numeric constant.

If the given constant value exists, then an index to its array position is returned.

func (*Program) AddRegexConstant

func (p *Program) AddRegexConstant(val *regexp.Regexp) int

Add a regular expression constant.

If the given constant value exists, then an index to its array position is returned.

func (*Program) AddStringConstant

func (p *Program) AddStringConstant(val string) int

Add a string constant.

If the given constant value exists, then an index to its array position is returned.

func (*Program) AddTimeConstant

func (p *Program) AddTimeConstant(val int64) int

Add a date/time constant.

If the given constant value exists, then an index to its array position is returned.

func (*Program) AppendIsn

func (p *Program) AppendIsn(opCode OpCode, args ...any)

Append an instruction to the bytecode.

Any provided arguments will be added as the instruction's operands.

func (*Program) AppendJump

func (p *Program) AppendJump(opCode OpCode, target LabelID)

Append a jump instruction to the bytecode.

The instruction's operand will be the target label ID.

func (*Program) BindLabel

func (p *Program) BindLabel(id LabelID)

Append a `LABEL` instruction bound to the given label identifier.

The instruction will be removed by the label resolver.

func (*Program) Emit

func (p *Program) Emit(irNode IRNode)

func (*Program) NewLabel

func (p *Program) NewLabel() LabelID

Generate a new label identifier and return it.

func (*Program) Peephole

func (p *Program) Peephole()

type Schema

type Schema map[string]FieldSpec

type Simplifier

type Simplifier interface {
	Simplify(IRNode) IRNode
}

func NewSimplifier

func NewSimplifier() Simplifier

type Span

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

Span within source code.

func NewEmptySpan

func NewEmptySpan() *Span

Create a new empty span.

func NewSpan

func NewSpan(start, end Position) *Span

Create a new span with the given start and end positions.

func (*Span) End

func (s *Span) End() Position

Return the span's ending position.

func (*Span) Start

func (s *Span) Start() Position

Return the span's starting position.

func (*Span) String

func (s *Span) String() string

Return the string representation of a span.

type Token

type Token int

Lucette token type.

const (
	TokenEOF Token = iota // End of file.

	TokenNumber // Numeric value.
	TokenPhrase // String phrase value.
	TokenField  // Field name.
	TokenRegex  // Regular expression.

	TokenPlus     // '+'
	TokenMinus    // '-'
	TokenStar     // '*'
	TokenQuestion // '?'
	TokenLParen   // '('
	TokenLBracket // '['
	TokenLCurly   // '{'
	TokenRParen   // ')'
	TokenRBracket // ']'
	TokenRCurly   // '}'
	TokenColon    // ':'
	TokenTilde    // '~'
	TokenCaret    // '^'

	TokenTo  // 'TO'.
	TokenAnd // 'AND'/'&&'.
	TokenOr  // 'OR'/'||'.
	TokenNot // 'NOT'/'!'.
	TokenLT  // '<'.
	TokenLTE // '<='.
	TokenGT  // '>'
	TokenGTE // '>='

	TokenIllegal // Illegal token.
	TokenUnknown // Unknown token.
)

func (Token) Literal

func (t Token) Literal() string

Return the literal string representation of a token if it has one.

func (Token) String

func (t Token) String() string

Return the string representation of a token.

type Typer

type Typer interface {
	// Generate typed IR from the given AST root node.
	Type(ASTNode) (IRNode, []Diagnostic)

	// Return the diagnostic messages generated during IR generation.
	Diagnostics() []Diagnostic
}

func NewTyper

func NewTyper(sch Schema) Typer

Jump to

Keyboard shortcuts

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