Documentation ¶
Index ¶
- func ParseWithDebug(debug bool) func(*ParseOptions)
- type ErrIncompleteParseFailed
- type ErrLeftRecursion
- type ErrParseFailed
- type Expression
- type Grammar
- type LazyReference
- type Literal
- type Lookahead
- type Node
- type OneOf
- func (e *OneOf) ExprName() string
- func (e *OneOf) Match(text string, parseOpts *ParseOptions) (*Node, error)
- func (of *OneOf) ResolveRefs(refs map[string]Expression) (Expression, error)
- func (e *OneOf) SetExprName(n string)
- func (of *OneOf) SetMembers(members []Expression)
- func (e *OneOf) String() string
- type ParseOption
- type ParseOptions
- type Quantifier
- type Regex
- type Sequence
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) Parse ¶
func (g *Grammar) Parse(text string, parseOpts ...ParseOption) (*Node, error)
func (*Grammar) ParseWithRule ¶
type LazyReference ¶
type LazyReference struct {
// contains filtered or unexported fields
}
func NewLazyReference ¶
func NewLazyReference(referenceName string) *LazyReference
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)
type Literal ¶
type Literal struct {
// contains filtered or unexported fields
}
func NewLiteral ¶
func NewLiteralWithName ¶
func (*Literal) GetLiteral ¶
func (*Literal) Match ¶
func (e *Literal) Match(text string, parseOpts *ParseOptions) (*Node, error)
func (*Literal) SetExprName ¶
func (e *Literal) SetExprName(n 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) 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)
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.
type OneOf ¶
type OneOf struct {
// contains filtered or unexported fields
}
func NewOneOf ¶
func NewOneOf(name string, members []Expression) *OneOf
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)
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) 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)
type Regex ¶
type Regex struct {
// contains filtered or unexported fields
}
func (*Regex) SetExprName ¶
func (e *Regex) SetExprName(n string)
type Sequence ¶
type Sequence struct {
// contains filtered or unexported fields
}
func NewSequence ¶
func NewSequence(name string, members []Expression) *Sequence
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)
Click to show internal directories.
Click to hide internal directories.