engine

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package engine implements the isnow pattern engine: recognition of pattern source via the grammar repo's ANTLR-generated parser, the shorthand-ladder role assignment, compilation of every field term to a predicate, membership (Holds) over a broken-down instant, and occurrence derivation (Next/Prev) under the 100-year search horizon.

The root go-isnow package is a thin facade over this package: everything exported here is re-exported there unchanged, so external callers never import the engine directly. Errors are the internal/constants sentinels, matchable with errors.Is.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) string

Code returns the stable string code of a library error (syntax, symbol, range, context), or "" if err is nil or not a library error.

func Is

func Is(src PatternText, at time.Time) (bool, error)

Is is the one-shot membership test: Parse then Holds.

Types

type Pattern

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

Pattern is a parsed, canonicalized isnow. The zero value is not usable; obtain one from Parse. Patterns are immutable and safe to copy and share.

func Parse

func Parse(src PatternText) (Pattern, error)

Parse recognizes src, resolves symbols and the shorthand ladder, and validates field domains. It returns one of constants.ErrSyntax, constants.ErrSymbol, constants.ErrRange, or constants.ErrContext.

func (Pattern) Canonical

func (p Pattern) Canonical() string

Canonical returns the fully-qualified seven-field form of the isnow.

func (Pattern) Explain

func (p Pattern) Explain() string

Explain returns a deterministic English description of the isnow, built from the terminology vocabulary. The wording is implementation-defined (not pinned by the conformance corpus).

func (Pattern) Holds

func (p Pattern) Holds(at time.Time) bool

Holds reports whether the isnow holds at the instant: every field constraint and every bound is satisfied. The instant is evaluated in its own location (at.Location()) and truncated to whole seconds.

func (Pattern) Next

func (p Pattern) Next(from time.Time) (time.Time, bool)

Next returns the earliest occurrence strictly after from, or false when none exists within the pattern's window or the 100-year horizon.

func (Pattern) NextContext

func (p Pattern) NextContext(ctx context.Context, from time.Time) (time.Time, bool, error)

NextContext is Next with cancellation: the search aborts and returns ctx's error when the context is done, so an unbounded scan on a pathological pattern (e.g. an impossible bounded window) cannot pin a CPU indefinitely. The context is checked once per civil day, bounding a cancelled search to at most a single day's enumeration.

func (Pattern) Prev

func (p Pattern) Prev(from time.Time) (time.Time, bool)

Prev returns the latest occurrence strictly before from, or false when none.

func (Pattern) PrevContext

func (p Pattern) PrevContext(ctx context.Context, from time.Time) (time.Time, bool, error)

PrevContext is Prev with cancellation (see NextContext).

func (Pattern) String

func (p Pattern) String() string

String returns the canonical form (fmt.Stringer).

type PatternText

type PatternText string

PatternText is isnow pattern source text accepted by Parse. It is exported so callers in other packages can convert their string input at the call site.

Jump to

Keyboard shortcuts

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