Documentation
¶
Index ¶
- func Match(program *Pattern, input string) (interface{}, error, int)
- type CapStack
- type CaptureEntry
- type CaptureHandler
- type CaptureResult
- type ConstCapture
- type FunctionCapture
- type IAny
- type IBackCommit
- type ICall
- type IChar
- type ICharset
- type IChoice
- type ICloseCapture
- type ICommit
- type IEmptyCapture
- type IEnd
- type IFail
- type IFailTwice
- type IFullCapture
- type IGiveUp
- type IJump
- type IOpenCall
- type IOpenCapture
- type IPartialCommit
- type IReturn
- type ISpan
- type Instruction
- type ListCapture
- type Pattern
- func And(p *Pattern) *Pattern
- func Any(n int) *Pattern
- func Cconst(value interface{}) *Pattern
- func Cfunc(p *Pattern, f func([]*CaptureResult) (interface{}, error)) *Pattern
- func Char(char byte) *Pattern
- func Clist(p *Pattern) *Pattern
- func Cposition() *Pattern
- func Csimple(p *Pattern) *Pattern
- func Cstring(p *Pattern, format string) *Pattern
- func Csubst(p *Pattern) *Pattern
- func Fail() *Pattern
- func Grm(start string, grammar map[string]*Pattern) *Pattern
- func Lit(text string) *Pattern
- func NegSet(chars string) *Pattern
- func Not(p *Pattern) *Pattern
- func Or(p1, p2 *Pattern) *Pattern
- func Pat(value interface{}) *Pattern
- func Ref(name string) *Pattern
- func Rep(p *Pattern, min, max int) *Pattern
- func Seq(args ...interface{}) *Pattern
- func Seq2(args []interface{}) *Pattern
- func Set(chars string) *Pattern
- func Succ() *Pattern
- func (p *Pattern) Cfunc(f func([]*CaptureResult) (interface{}, error)) *Pattern
- func (p *Pattern) Clist() *Pattern
- func (p *Pattern) Csimple() *Pattern
- func (p *Pattern) Cstring(format string) *Pattern
- func (p *Pattern) Csubst() *Pattern
- func (p *Pattern) Exc(pred *Pattern) *Pattern
- func (p *Pattern) Or(ps ...interface{}) *Pattern
- func (p *Pattern) Rep(min, max int) *Pattern
- func (p *Pattern) Resolve(name string, target *Pattern) *Pattern
- func (p *Pattern) String() string
- type PositionCapture
- type SimpleCapture
- type Stack
- type StackEntry
- type StringCapture
- type SubstCapture
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CapStack ¶
type CapStack struct {
// contains filtered or unexported fields
}
func NewCapStack ¶
func NewCapStack() *CapStack
func (*CapStack) Close ¶
func (s *CapStack) Close(end int) (*CaptureEntry, int)
Close and return the closest open capture
func (*CapStack) Open ¶
func (s *CapStack) Open(p int, start int) *CaptureEntry
Open and return an new capture
func (*CapStack) Pop ¶
func (s *CapStack) Pop(count int) []*CaptureResult
Pop and return the top `count` captures
type CaptureEntry ¶
type CaptureEntry struct {
// contains filtered or unexported fields
}
type CaptureHandler ¶
type CaptureHandler interface {
Process(input string, start, end int, captures *CapStack, subcaps int) (interface{}, error)
}
Interface for all capture handlers
type CaptureResult ¶
type CaptureResult struct {
// contains filtered or unexported fields
}
Used when returning the values Similar to CaptureEntry, but without some internal values
type ConstCapture ¶
type ConstCapture struct {
// contains filtered or unexported fields
}
Captures a constant value
func (*ConstCapture) String ¶
func (h *ConstCapture) String() string
type FunctionCapture ¶
type FunctionCapture struct {
// contains filtered or unexported fields
}
Calls a function with all sub-captures, and captures the return value. If functions reports an error, let it bubble up.
func (*FunctionCapture) String ¶
func (h *FunctionCapture) String() string
type IAny ¶
type IAny struct {
// contains filtered or unexported fields
}
Match `count` of any character
type IBackCommit ¶
type IBackCommit struct {
// contains filtered or unexported fields
}
Backtracks to a fallback-point, and does a relative jump.
func (*IBackCommit) String ¶
func (op *IBackCommit) String() string
type ICall ¶
type ICall struct {
// contains filtered or unexported fields
}
Push return address to stack, and do a relative jump.
type IChar ¶
type IChar struct {
// contains filtered or unexported fields
}
Match a single character.
type ICharset ¶
type ICharset struct {
// contains filtered or unexported fields
}
Match a character from a set TODO(mizardx): Unicode?
type IChoice ¶
type IChoice struct {
// contains filtered or unexported fields
}
Add a fallback point at offset, and continue on next instruction.
type ICloseCapture ¶
type ICloseCapture struct {
// contains filtered or unexported fields
}
Close the nearest open capture
func (*ICloseCapture) String ¶
func (op *ICloseCapture) String() string
type ICommit ¶
type ICommit struct {
// contains filtered or unexported fields
}
Pop a fallback point, and do a relative jump.
type IEmptyCapture ¶
type IEmptyCapture struct {
// contains filtered or unexported fields
}
Open and close a new empty capture
func (*IEmptyCapture) String ¶
func (op *IEmptyCapture) String() string
type IFailTwice ¶
type IFailTwice struct{}
Roll back to the next closest fallback point.
func (*IFailTwice) String ¶
func (op *IFailTwice) String() string
type IFullCapture ¶
type IFullCapture struct {
// contains filtered or unexported fields
}
Open and close a new capture of fixed size
func (*IFullCapture) String ¶
func (op *IFullCapture) String() string
type IOpenCall ¶
type IOpenCall struct {
// contains filtered or unexported fields
}
Unresolved call. Used by grammars.
type IOpenCapture ¶
type IOpenCapture struct {
// contains filtered or unexported fields
}
Open a new capture
func (*IOpenCapture) String ¶
func (op *IOpenCapture) String() string
type IPartialCommit ¶
type IPartialCommit struct {
// contains filtered or unexported fields
}
Update top stack entry, and do a relative jump.
func (*IPartialCommit) String ¶
func (op *IPartialCommit) String() string
type Instruction ¶
Interface for instructions. XXX(mizardx): Make this more specific?
type ListCapture ¶
type ListCapture struct{}
Captures a list of all sub-captures
func (*ListCapture) String ¶
func (h *ListCapture) String() string
type Pattern ¶
type Pattern []Instruction
func Cfunc ¶
func Cfunc(p *Pattern, f func([]*CaptureResult) (interface{}, error)) *Pattern
Does a function capture.
func Pat ¶
func Pat(value interface{}) *Pattern
Resolve a value to a pattern. Patterns are return unmodified.
- true gives a pattern that always succeeds. Equivalent to Succ().
- false gives a pattern that always fails. Equivalent to Fail().
- n < 0 asserts that there are at least -n characters. Equivalent to And(Any(n)).
- n >= 0 matches n characters. Equivalent to Any(n).
- A string matches itself. Equivalent to Lit(value)
func Seq ¶
func Seq(args ...interface{}) *Pattern
A sequence of values, instructions and other patterns. (See Seq2)
func Seq2 ¶
func Seq2(args []interface{}) *Pattern
A sequence of values, instructions and other patterns Instructions that represent jumps are updated to match the sizes of the argument.
func (*Pattern) Cfunc ¶
func (p *Pattern) Cfunc(f func([]*CaptureResult) (interface{}, error)) *Pattern
A function capture of this pattern.
type PositionCapture ¶
type PositionCapture struct{}
Captures the current input position
func (*PositionCapture) String ¶
func (h *PositionCapture) String() string
type SimpleCapture ¶
type SimpleCapture struct{}
Captures the matched substring
func (*SimpleCapture) String ¶
func (h *SimpleCapture) String() string
type StackEntry ¶
type StackEntry struct {
// contains filtered or unexported fields
}
type StringCapture ¶
type StringCapture struct {
// contains filtered or unexported fields
}
Capture a string created from a format applied to the sub-captures.
func (*StringCapture) String ¶
func (h *StringCapture) String() string
type SubstCapture ¶
type SubstCapture struct{}
Capture a string, with all sub-captures replaced by their string-representation. XXX(mizardx): Better explaination?
func (*SubstCapture) String ¶
func (h *SubstCapture) String() string