goast

package
v0.0.0-...-d3a9360 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssertTypeMatch

type AssertTypeMatch struct {
	Value preserves.Value
	M     Match
}

func NewAssertTypeMatch

func NewAssertTypeMatch(value preserves.Value, m Match) *AssertTypeMatch

func (*AssertTypeMatch) Match

func (a *AssertTypeMatch) Match(value preserves.Value) bool

func (*AssertTypeMatch) Stmt

func (a *AssertTypeMatch) Stmt() (stmts []ast.Stmt)

type BoolMatch

type BoolMatch interface {
	Match(preserves.Value) bool
}
type LengthRangeMatch struct {
	From int
	To   int
	M    Match
}

func NewLengthRangeMatch(from int, to int, m Match) *LengthRangeMatch {
	return &LengthRangeMatch{From: from, To: to, M: m}
}

func (l *LengthRangeMatch) FromPreserves(values []preserves.Value) any {
	if len(values) > l.From && len(values) < l.To {
		return l.M.FromPreserves(values)
	}

	return nil
}

func (l *LengthRangeMatch) Stmt() (stmts []ast.Stmt) {
	stmts = append(stmts, &ast.IfStmt{
		Cond: &ast.BinaryExpr{
			X: &ast.BinaryExpr{
				X: &ast.CallExpr{
					Fun:  ast.NewIdent("len"),
					Args: []ast.Expr{ast.NewIdent("value")}},
				Op: token.GTR,
				Y:  ast.NewIdent(strconv.Itoa(l.From)),
			},
			Op: token.LAND,
			Y: &ast.BinaryExpr{
				X: &ast.CallExpr{
					Fun:  ast.NewIdent("len"),
					Args: []ast.Expr{ast.NewIdent("values")}},
				Op: token.LSS,
				Y:  ast.NewIdent(strconv.Itoa(l.To)),
			},
		},
		Body: &ast.BlockStmt{List: l.M.Stmt()},
	})
	return
}

type LengthExactMatch struct {
	L int
	M Match
}

func NewLengthExactMatch(l int, m Match) *LengthExactMatch {
	return &LengthExactMatch{L: l, M: m}
}

func (l *LengthExactMatch) FromPreserves(values preserves.Value) any {
	if len(values) == l.L {
		return l.M.FromPreserves(values)
	}

	return nil
}

func (l *LengthExactMatch) Stmt() (stmts []ast.Stmt) {
	stmts = append(stmts, &ast.IfStmt{
		Cond: &ast.BinaryExpr{
			X: &ast.CallExpr{
				Fun:  ast.NewIdent("len"),
				Args: []ast.Expr{ast.NewIdent("values")}},
			Op: token.EQL,
			Y:  ast.NewIdent(strconv.Itoa(l.From)),
		},
		Body: &ast.BlockStmt{List: l.M.Stmt()},
	})

	return
}
func (r *Rec) Matcher() Match {
	return NewAssertTypeMatch(&preserves.Record{}, )
}

type ListMatch

type ListMatch struct {
	B []BoolMatch
	M Match
}

func NewListMatch

func NewListMatch(m Match, b ...BoolMatch) *ListMatch

func (*ListMatch) FromPreserves

func (l *ListMatch) FromPreserves(value preserves.Value) any

func (*ListMatch) Stmt

func (l *ListMatch) Stmt() (stmts []ast.Stmt)

type Match

type Match interface {
	Stmt() []ast.Stmt
	FromPreserves(preserves.Value) any
}

type RecordKeyBoolMatch

type RecordKeyBoolMatch string

func NewRecordKeyBoolMatch

func NewRecordKeyBoolMatch(s string) *RecordKeyBoolMatch

func (*RecordKeyBoolMatch) Match

func (r *RecordKeyBoolMatch) Match(value preserves.Value) bool

Jump to

Keyboard shortcuts

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