Documentation
¶
Index ¶
- Constants
- Variables
- func CompareNumbers(left, right Expression, bindings Binding, op string) bool
- func EvaluateCondition(condition Expression, bindings Binding) bool
- func GetNumber(expr Expression) (float64, bool)
- func IsFail(bindings Binding) bool
- func IsList(expr Expression) bool
- func IsSegmentPattern(expr Expression) bool
- func IsSinglePattern(expr Expression) bool
- func IsVariable(expr Expression) bool
- func TestPredicate(predicate string, value Expression) bool
- type Atom
- type Binding
- func ExtendBindings(variable string, value Expression, bindings Binding) Binding
- func MatchAnd(pattern Expression, input Expression, bindings Binding) Binding
- func MatchIf(pattern Expression, input Expression, bindings Binding) Binding
- func MatchIs(pattern Expression, input Expression, bindings Binding) Binding
- func MatchNot(pattern Expression, input Expression, bindings Binding) Binding
- func MatchOr(pattern Expression, input Expression, bindings Binding) Binding
- func MatchVariable(pattern Expression, input Expression, bindings Binding) Binding
- func PatMatch(pattern Expression, input Expression, bindings Binding) Binding
- func SegmentMatch(pattern Expression, input Expression, bindings Binding, minLength int) Binding
- func SegmentMatchPlus(pattern Expression, input Expression, bindings Binding) Binding
- func SegmentMatchQuestion(pattern Expression, input Expression, bindings Binding) Binding
- func SegmentMatchStar(pattern Expression, input Expression, bindings Binding) Binding
- func SegmentMatchZeroOrOne(pattern Expression, input Expression, bindings Binding) Binding
- func SegmentMatcher(pattern Expression, input Expression, bindings Binding) Binding
- func SingleMatcher(pattern Expression, input Expression, bindings Binding) Binding
- type Cons
- type Expression
- func ConsToSlice(expr Expression) []Expression
- func GetBinding(variable string, bindings Binding) (Expression, bool)
- func Lookup(variable string, bindings Binding) Expression
- func Parse(input string) (Expression, error)
- func ParseAll(input string) ([]Expression, error)
- func ResolveValue(expr Expression, bindings Binding) Expression
- func SliceToCons(elements []Expression) Expression
- type Parser
- type SegmentMatchFunc
- type SingleMatchFunc
- type Symbol
- type Token
Constants ¶
const ( TokenLParen = "LPAREN" TokenRParen = "RPAREN" TokenSymbol = "SYMBOL" TokenNumber = "NUMBER" TokenString = "STRING" TokenEOF = "EOF" )
Variables ¶
var ( NoBindings = Binding{} Fail = Binding{"__FAIL__": Symbol{Name: "__FAIL__"}} )
Special binding values
Functions ¶
func CompareNumbers ¶
func CompareNumbers(left, right Expression, bindings Binding, op string) bool
func EvaluateCondition ¶
func EvaluateCondition(condition Expression, bindings Binding) bool
func GetNumber ¶
func GetNumber(expr Expression) (float64, bool)
func IsSegmentPattern ¶
func IsSegmentPattern(expr Expression) bool
func IsSinglePattern ¶
func IsSinglePattern(expr Expression) bool
func IsVariable ¶
func IsVariable(expr Expression) bool
func TestPredicate ¶
func TestPredicate(predicate string, value Expression) bool
Types ¶
type Atom ¶
type Atom struct {
Value interface{}
}
Atom represents a Lisp atom (number, string, etc.)
func (Atom) Equal ¶
func (a Atom) Equal(other Expression) bool
type Binding ¶
type Binding map[string]Expression
Binding represents variable bindings
func ExtendBindings ¶
func ExtendBindings(variable string, value Expression, bindings Binding) Binding
ExtendBindings adds a new variable binding
func MatchAnd ¶
func MatchAnd(pattern Expression, input Expression, bindings Binding) Binding
func MatchIf ¶
func MatchIf(pattern Expression, input Expression, bindings Binding) Binding
func MatchIs ¶
func MatchIs(pattern Expression, input Expression, bindings Binding) Binding
Single pattern matching functions
func MatchNot ¶
func MatchNot(pattern Expression, input Expression, bindings Binding) Binding
func MatchOr ¶
func MatchOr(pattern Expression, input Expression, bindings Binding) Binding
func MatchVariable ¶
func MatchVariable(pattern Expression, input Expression, bindings Binding) Binding
MatchVariable matches a variable pattern against input
func PatMatch ¶
func PatMatch(pattern Expression, input Expression, bindings Binding) Binding
PatMatch is the main pattern matching function
func SegmentMatch ¶
func SegmentMatch(pattern Expression, input Expression, bindings Binding, minLength int) Binding
SegmentMatch implements the core segment matching algorithm
func SegmentMatchPlus ¶
func SegmentMatchPlus(pattern Expression, input Expression, bindings Binding) Binding
func SegmentMatchQuestion ¶
func SegmentMatchQuestion(pattern Expression, input Expression, bindings Binding) Binding
func SegmentMatchStar ¶
func SegmentMatchStar(pattern Expression, input Expression, bindings Binding) Binding
Segment matching functions
func SegmentMatchZeroOrOne ¶
func SegmentMatchZeroOrOne(pattern Expression, input Expression, bindings Binding) Binding
SegmentMatchZeroOrOne handles (?? var) patterns
func SegmentMatcher ¶
func SegmentMatcher(pattern Expression, input Expression, bindings Binding) Binding
SegmentMatcher handles segment patterns like (?* ?x)
func SingleMatcher ¶
func SingleMatcher(pattern Expression, input Expression, bindings Binding) Binding
SingleMatcher handles single patterns like (?is ?x numberp)
type Cons ¶
type Cons struct {
Car Expression
Cdr Expression
}
Cons represents a Lisp cons cell (for lists)
func (Cons) Equal ¶
func (c Cons) Equal(other Expression) bool
type Expression ¶
type Expression interface {
String() string
Equal(other Expression) bool
}
Expression represents a Lisp-like expression
func GetBinding ¶
func GetBinding(variable string, bindings Binding) (Expression, bool)
GetBinding finds a variable binding
func Lookup ¶
func Lookup(variable string, bindings Binding) Expression
Lookup gets the value of a variable from bindings
func ParseAll ¶
func ParseAll(input string) ([]Expression, error)
Helper function to parse multiple expressions
func ResolveValue ¶
func ResolveValue(expr Expression, bindings Binding) Expression
func SliceToCons ¶
func SliceToCons(elements []Expression) Expression
Helper function to convert slice to Cons cells
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser
func (*Parser) ParseExpression ¶
func (p *Parser) ParseExpression() (Expression, error)
type SegmentMatchFunc ¶
type SegmentMatchFunc func(pattern Expression, input Expression, bindings Binding) Binding
Type definitions for match functions
func GetSegmentMatchFunc ¶
func GetSegmentMatchFunc(operator string) SegmentMatchFunc
GetSegmentMatchFunc returns the appropriate segment match function
type SingleMatchFunc ¶
type SingleMatchFunc func(pattern Expression, input Expression, bindings Binding) Binding
func GetSingleMatchFunc ¶
func GetSingleMatchFunc(operator string) SingleMatchFunc
GetSingleMatchFunc returns the appropriate single match function