matcher

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrVarAssigned error
	ErrVarAssigned = errors.New("variable is already assigned")
)

Functions

This section is empty.

Types

type Context

type Context struct {
	Fset    *token.FileSet
	FileEnd token.Pos
}

Context represents the context of a matching process.

func (*Context) NewError

func (p *Context) NewError(pos token.Pos, msg string) *Error

func (*Context) NewErrorf

func (p *Context) NewErrorf(pos token.Pos, format string, args ...any) error

type Error

type Error struct {
	Fset *token.FileSet
	Pos  token.Pos
	Msg  string
}

Error represents a matching error.

func (*Error) Error

func (p *Error) Error() string

type Matcher

type Matcher interface {
	Match(src []*types.Token, ctx *Context) (n int, result any, err error)
}

Matcher represents a matcher.

func Choice

func Choice(options ...Matcher) Matcher

Choice: R1 | R2 | ... | Rn

func List

func List(a, b Matcher) Matcher

List: R1 % R2 is equivalent to R1 *(R2 R1)

func Literal

func Literal(tok token.Token, lit string) Matcher

Literal: "abc", 'a', 123, 1.23, etc.

func Repeat0

func Repeat0(r Matcher) Matcher

Repeat0: *R

func Repeat01

func Repeat01(r Matcher) Matcher

Repeat01: ?R

func Repeat1

func Repeat1(r Matcher) Matcher

Repeat1: +R

func Sequence

func Sequence(items ...Matcher) Matcher

Sequence: R1 R2 ... Rn

func Token

func Token(tok token.Token) Matcher

Token: ADD, SUB, IDENT, INT, FLOAT, CHAR, STRING, etc.

type Var

type Var struct {
	Elem Matcher
	Name string
	Pos  token.Pos
}

func NewVar

func NewVar(pos token.Pos, name string) *Var

NewVar creates a new Var instance.

func (*Var) Assign

func (p *Var) Assign(elem Matcher) error

Assign assigns a value to this variable.

func (*Var) Match

func (p *Var) Match(src []*types.Token, ctx *Context) (n int, result any, err error)

Jump to

Keyboard shortcuts

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