Back to godoc.org
github.com/pixeltopic/rematch

Package rematch

v0.1.0
Latest Go to latest

The latest major version is .

Published: Jul 6, 2020 | License: BSD-3-Clause | Module: github.com/pixeltopic/rematch

Index

func Eval

func Eval(expr *Expr, text *Text) (bool, error)

Eval matches an expression against text

func EvalExpr

func EvalExpr(expr *Expr, s string) (bool, error)

EvalExpr matches an expression against a string.

func EvalRawExpr

func EvalRawExpr(expr, s string) (bool, error)

EvalRawExpr matches a raw expression against a string

type EvalError

type EvalError string

EvalError occurs when an expression fails to evaluate because it is in improper RPN

func (EvalError) Error

func (e EvalError) Error() string

type Expr

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

Expr represents a Rematch expression.

func NewExpr

func NewExpr(rawExpr string) *Expr

NewExpr returns a new Expression for evaluation.

func (*Expr) Compile

func (e *Expr) Compile() error

Compile an expression. A compiled expression will not be recompiled. This is useful when reusing an expression multiple times against different texts

func (*Expr) Compiled

func (e *Expr) Compiled() bool

Compiled returns if the expression has been compiled into Reverse Polish notation.

func (*Expr) MarshalJSON

func (e *Expr) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON marshalling

func (*Expr) RPN

func (e *Expr) RPN() []string

RPN returns the expression in Reverse Polish notation.

func (*Expr) Raw

func (e *Expr) Raw() string

Raw returns the raw expression string before conversion into Reverse Polish notation. Validation of a raw expression is not confirmed until it is compiled.

func (*Expr) UnmarshalJSON

func (e *Expr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements JSON unmarshalling

type Result

type Result struct {
	Match   bool
	Strings []string
}

Result is the output after evaluating a query.

Strings contains a non-unique/non-ordered collection of token matches from the given expression.

func ExprFindAll

func ExprFindAll(expr *Expr, s string) (*Result, error)

ExprFindAll matches an expression against a string, returning all matched tokens if true

func FindAll

func FindAll(expr *Expr, text *Text) (*Result, error)

FindAll matches an expression against text, returning all matched tokens if true

func RawExprFindAll

func RawExprFindAll(expr, s string) (*Result, error)

RawExprFindAll matches a raw expression against a string, returning all matched tokens if true

type SyntaxError

type SyntaxError string

SyntaxError occurs when an expression is malformed.

func (SyntaxError) Error

func (e SyntaxError) Error() string

type Text

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

Text contains text to match against an Expression. This may be helpful if you want to match many different expressions against the same block of text without reprocessing it

func NewText

func NewText(s string) *Text

NewText returns a text instance to match against an Expression.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier