filter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Fields = map[string]Field{
	"status": {
		Name: "status",
		Type: "enum",
		Extract: func(ub api.UserBook) any {
			return statusIDToName(ub.StatusID)
		},
	},
	"owned": {
		Name: "owned",
		Type: "boolean",
		Extract: func(ub api.UserBook) any {
			return ub.Owned
		},
	},
	"rating": {
		Name: "rating",
		Type: "number",
		Extract: func(ub api.UserBook) any {
			return ub.Rating
		},
	},
	"year": {
		Name: "year",
		Type: "number",
		Extract: func(ub api.UserBook) any {
			if len(ub.DateAdded) >= 4 {
				y, err := strconv.Atoi(ub.DateAdded[:4])
				if err == nil {
					return y
				}
			}
			return 0
		},
	},
	"pages": {
		Name: "pages",
		Type: "number",
		Extract: func(ub api.UserBook) any {
			if ub.Edition != nil && ub.Edition.Pages > 0 {
				return ub.Edition.Pages
			}
			return ub.Book.Pages
		},
	},
	"added": {
		Name: "added",
		Type: "date",
		Extract: func(ub api.UserBook) any {
			return ub.DateAdded
		},
	},
	"title": {
		Name: "title",
		Type: "string",
		Extract: func(ub api.UserBook) any {
			return ub.Book.Title
		},
	},
	"author": {
		Name: "author",
		Type: "string",
		Extract: func(ub api.UserBook) any {
			var authors []string
			for _, c := range ub.Book.Contributions {
				authors = append(authors, c.Author.Name)
			}
			return strings.Join(authors, ", ")
		},
	},
}

Functions

func Eval

func Eval(expr Expr, ub api.UserBook) (bool, error)

Types

type Comparison

type Comparison struct {
	Field string
	Op    string
	Value any
}

type Expr

type Expr interface{}

func Parse

func Parse(input string) (Expr, error)

type Field

type Field struct {
	Name    string
	Type    string
	Extract func(api.UserBook) any
}

type Lexer

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

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) Tokenize

func (l *Lexer) Tokenize() []Token

type Logical

type Logical struct {
	Op    string
	Left  Expr
	Right Expr
}

type Not

type Not struct {
	Expr Expr
}

type Parser

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

func NewParser

func NewParser(tokens []Token) *Parser

func (*Parser) Parse

func (p *Parser) Parse() (Expr, error)

type Token

type Token struct {
	Type  TokenType
	Value string
	Pos   int
}

func (*Token) String

func (t *Token) String() string

type TokenType

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenIdent
	TokenString
	TokenNumber
	TokenBool
	TokenDate
	TokenOp
	TokenAnd
	TokenOr
	TokenNot
	TokenLParen
	TokenRParen
)

Jump to

Keyboard shortcuts

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