types

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseWithDebug

func ParseWithDebug(debug bool) func(*ParseOptions)

ParseWithDebug enables debug mode on parsing.

Types

type ErrIncompleteParseFailed

type ErrIncompleteParseFailed struct {
	ErrParseFailed
}

func (*ErrIncompleteParseFailed) Error

func (e *ErrIncompleteParseFailed) Error() string

type ErrLeftRecursion

type ErrLeftRecursion struct {
	ErrParseFailed
}

func (*ErrLeftRecursion) Error

func (e *ErrLeftRecursion) Error() string

type ErrParseFailed

type ErrParseFailed struct {
	Text       string
	Position   int
	Expression Expression
}

func (*ErrParseFailed) Error

func (e *ErrParseFailed) Error() string

func (*ErrParseFailed) LineAndColumn

func (e *ErrParseFailed) LineAndColumn() (int, int)

type Expression

type Expression interface {
	fmt.Stringer

	// ExprName returns the name of the expression.
	ExprName() string
	// SetExprName sets the name of the expression.
	// TODO: maybe we should get rid of this?
	SetExprName(string)
	// Match matches the expression against the given text at the given rune position.
	Match(text string, parseOpts *ParseOptions) (*Node, error)
	// contains filtered or unexported methods
}

Expression represents a parsimonious expression.

func ResolveRefsFor

func ResolveRefsFor(v Expression, rules map[string]Expression) (Expression, error)

type Grammar

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

Grammar parses a text into a tree of nodes with defined grammar rules.

func NewGrammar

func NewGrammar(rules map[string]Expression, defaultRule Expression) *Grammar

NewGrammar creates a new grammar with the given rules and default rule.

func (*Grammar) GetRule

func (g *Grammar) GetRule(ruleName string) (Expression, bool)

func (*Grammar) Parse

func (g *Grammar) Parse(text string, parseOpts ...ParseOption) (*Node, error)

func (*Grammar) ParseWithRule

func (g *Grammar) ParseWithRule(ruleName string, text string, parseOpts ...ParseOption) (*Node, error)

func (*Grammar) String

func (g *Grammar) String() string

type LazyReference

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

func NewLazyReference

func NewLazyReference(referenceName string) *LazyReference

func (*LazyReference) ExprName

func (e *LazyReference) ExprName() string

func (*LazyReference) Match

func (e *LazyReference) Match(text string, parseOpts *ParseOptions) (*Node, error)

func (*LazyReference) ResolveRefs

func (r *LazyReference) ResolveRefs(refs map[string]Expression) (Expression, error)

func (*LazyReference) SetExprName

func (e *LazyReference) SetExprName(n string)

func (*LazyReference) String

func (e *LazyReference) String() string

type Literal

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

func NewLiteral

func NewLiteral(literal string) *Literal

func NewLiteralWithName

func NewLiteralWithName(name string, literal string) *Literal

func (*Literal) ExprName

func (e *Literal) ExprName() string

func (*Literal) GetLiteral

func (l *Literal) GetLiteral() string

func (*Literal) Match

func (e *Literal) Match(text string, parseOpts *ParseOptions) (*Node, error)

func (*Literal) SetExprName

func (e *Literal) SetExprName(n string)

func (*Literal) String

func (e *Literal) String() string

type Lookahead

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

func NewLookahead

func NewLookahead(name string, member Expression, negative bool) *Lookahead

func NewNot

func NewNot(member Expression) *Lookahead

func (*Lookahead) ExprName

func (e *Lookahead) ExprName() string

func (*Lookahead) Match

func (e *Lookahead) Match(text string, parseOpts *ParseOptions) (*Node, error)

func (*Lookahead) ResolveRefs

func (l *Lookahead) ResolveRefs(refs map[string]Expression) (Expression, error)

func (*Lookahead) SetExprName

func (e *Lookahead) SetExprName(n string)

func (*Lookahead) String

func (e *Lookahead) String() string

type Node

type Node struct {
	// Expression is the expression that matched this node.
	Expression Expression
	// Text is the text that matched this node.
	Text string
	// Start is the rune start index of the match.
	Start int
	// End is the rune end index of the match.
	End int
	// Children are the child nodes of this node.
	Children []*Node
	// Match is the string that matched this node from the regex expression.
	Match string
}

Node represents a node in the parse tree.

func ParseWithExpression

func ParseWithExpression(expr Expression, text string, opts ...ParseOption) (*Node, error)

ParseWithExpression parses the given text with the given expression.

func (*Node) String

func (n *Node) String() string

type OneOf

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

func NewOneOf

func NewOneOf(name string, members []Expression) *OneOf

func (*OneOf) ExprName

func (e *OneOf) ExprName() string

func (*OneOf) Match

func (e *OneOf) Match(text string, parseOpts *ParseOptions) (*Node, error)

func (*OneOf) ResolveRefs

func (of *OneOf) ResolveRefs(refs map[string]Expression) (Expression, error)

func (*OneOf) SetExprName

func (e *OneOf) SetExprName(n string)

func (*OneOf) SetMembers

func (of *OneOf) SetMembers(members []Expression)

func (*OneOf) String

func (e *OneOf) String() string

type ParseOption

type ParseOption func(*ParseOptions)

ParseOption configures a ParseOptions.

type ParseOptions

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

ParseOptions represents options for parsing.

type Quantifier

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

func NewOneOrMore

func NewOneOrMore(name string, member Expression) *Quantifier

func NewOptional

func NewOptional(name string, member Expression) *Quantifier

func NewZeroOrMore

func NewZeroOrMore(name string, member Expression) *Quantifier

func (*Quantifier) ExprName

func (e *Quantifier) ExprName() string

func (*Quantifier) Match

func (e *Quantifier) Match(text string, parseOpts *ParseOptions) (*Node, error)

func (*Quantifier) ResolveRefs

func (q *Quantifier) ResolveRefs(refs map[string]Expression) (Expression, error)

func (*Quantifier) SetExprName

func (e *Quantifier) SetExprName(n string)

func (*Quantifier) String

func (e *Quantifier) String() string

type Regex

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

func NewRegex

func NewRegex(name string, re *regexp2.Regexp) *Regex

func (*Regex) ExprName

func (e *Regex) ExprName() string

func (*Regex) Match

func (e *Regex) Match(text string, parseOpts *ParseOptions) (*Node, error)

func (*Regex) SetExprName

func (e *Regex) SetExprName(n string)

func (*Regex) String

func (e *Regex) String() string

type Sequence

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

func NewSequence

func NewSequence(name string, members []Expression) *Sequence

func (*Sequence) ExprName

func (e *Sequence) ExprName() string

func (*Sequence) Match

func (e *Sequence) Match(text string, parseOpts *ParseOptions) (*Node, error)

func (*Sequence) ResolveRefs

func (s *Sequence) ResolveRefs(refs map[string]Expression) (Expression, error)

func (*Sequence) SetExprName

func (e *Sequence) SetExprName(n string)

func (*Sequence) String

func (e *Sequence) String() string

Jump to

Keyboard shortcuts

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