parser

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions

type Actions cfg.Actions

Actions contains the actions to be applied to a set of emails.

type CriteriaAST

type CriteriaAST interface {
	// RootOperation returns the operation performed by the root node,
	// or the grouping, if the root is a leaf.
	RootOperation() OperationType
	// RootOperation returns the function performed by the root node,
	// if any.
	RootFunction() FunctionType
	// IsLeaf returns true if the root node is a leaf.
	IsLeaf() bool
	// AcceptVisitor implements the visitor pattern.
	AcceptVisitor(v Visitor)
	// Clone returns a deep copy of the tree.
	Clone() CriteriaAST
}

CriteriaAST is the abstract syntax tree of a filter criteria.

func SimplifyCriteria

func SimplifyCriteria(tree CriteriaAST) (CriteriaAST, error)

SimplifyCriteria applies multiple simplifications to a criteria.

type FunctionType

type FunctionType int

FunctionType is the type of a function.

const (
	FunctionNone FunctionType = iota
	FunctionFrom
	FunctionTo
	FunctionCc
	FunctionBcc
	FunctionReplyTo
	FunctionSubject
	FunctionList
	FunctionHas
	FunctionQuery
)

Functions.

func (FunctionType) String

func (f FunctionType) String() string

type Leaf

type Leaf struct {
	Function FunctionType
	Grouping OperationType
	Args     []string
	IsRaw    bool
}

Leaf is an AST node with no children.

If the function has multiple arguments, they are grouped together with a logical operator. For example: from:{a b} has two arguments grouped with an OR and from:(a b) is grouped with an AND.

func (*Leaf) AcceptVisitor

func (n *Leaf) AcceptVisitor(v Visitor)

AcceptVisitor implements the visitor pattern.

func (*Leaf) Clone

func (n *Leaf) Clone() CriteriaAST

Clone returns a deep copy of the leaf node.

func (*Leaf) IsLeaf

func (n *Leaf) IsLeaf() bool

IsLeaf will always return true.

func (*Leaf) RootFunction

func (n *Leaf) RootFunction() FunctionType

RootFunction returns the function of the leaf.

func (*Leaf) RootOperation

func (n *Leaf) RootOperation() OperationType

RootOperation returns the grouping of the leaf.

type Node

type Node struct {
	Operation OperationType
	Children  []CriteriaAST
}

Node is an AST node with children nodes. It can only be a logical operator.

func (*Node) AcceptVisitor

func (n *Node) AcceptVisitor(v Visitor)

AcceptVisitor implements the visitor pattern.

func (*Node) Clone

func (n *Node) Clone() CriteriaAST

Clone returns a deep copy of the tree.

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

IsLeaf will always return false.

func (*Node) RootFunction

func (n *Node) RootFunction() FunctionType

RootFunction will always return 'none'.

func (*Node) RootOperation

func (n *Node) RootOperation() OperationType

RootOperation returns the operation performed by the root node.

type OperationType

type OperationType int

OperationType is the type of logical operator.

const (
	OperationNone OperationType = iota
	OperationAnd
	OperationOr
	OperationNot
)

Logical operations.

func (OperationType) String

func (t OperationType) String() string

type Rule

type Rule struct {
	Criteria CriteriaAST
	Actions  Actions
}

Rule is an intermediate representation of a Gmail filter.

func Parse

func Parse(config cfg.Config) ([]Rule, error)

Parse parses config file rules into their intermediate representation.

Note that the number of rules and their contents might be different than the original, because symplifications will be performed on the data.

type Visitor

type Visitor interface {
	VisitNode(n *Node)
	VisitLeaf(n *Leaf)
}

Visitor implements the visitor pattern for CriteriaAST.

Jump to

Keyboard shortcuts

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