Documentation ¶
Index ¶
- Constants
- Variables
- func Do(p interface{}, ps ParseState) (Parsed, ParseState)
- type BaseParseState
- type ErrParsedType
- type Item
- type LexerIface
- type NamedValue
- type NilParsedType
- type ParseError
- type ParseState
- type Parsed
- type Parser
- func Char(c rune) Parser
- func Many(p interface{}) Parser
- func Many1(p interface{}) Parser
- func Maybe(p interface{}) Parser
- func MaybePeek(p interface{}) Parser
- func Named(ident string, p interface{}) Parser
- func Or(p ...interface{}) Parser
- func Peek(p interface{}) Parser
- func Prod(ident string, p interface{}) Parser
- func Recover(p interface{}, recoverfn RecoverFunc) Parser
- func RecoverTo(token TokenType, p interface{}) Parser
- func Root(p interface{}) Parser
- func SepBy(p, delim interface{}) Parser
- func SepBy1(p, delim interface{}) Parser
- func SepBy1Term(p, delim, terminator interface{}) Parser
- func SepByTerm(p, delim, terminator interface{}) Parser
- func Seq(p ...interface{}) Parser
- func Tok(token TokenType) Parser
- func Try(p interface{}) Parser
- func TryRecover(p interface{}, recoverfn RecoverFunc) Parser
- func TypedProd(ident string, typ interface{}, p interface{}) Parser
- func TypedProdIface(ident string, typ interface{}, p interface{}) Parser
- type Pos
- type Production
- type RecoverFunc
- type Sequence
- type TokenType
Constants ¶
const TOK_EOF = TokenType("")
Variables ¶
var Debug = false
var EOF = Tok(TOK_EOF)
var ErrParsed = ErrParsedType{}
ErrParsed is returned when nothing could be parsed, and an error was raised
var NilItem = Item{}
var NilParsed = NilParsedType{}
NilParsed is returned when nothing could be parsed, but no error was raised
var VisitorTemplate = visitorTemplate{ Productions: make(map[string]reflect.Type), }
Functions ¶
func Do ¶
func Do(p interface{}, ps ParseState) (Parsed, ParseState)
Types ¶
type BaseParseState ¶
type BaseParseState struct {
// contains filtered or unexported fields
}
func (BaseParseState) CloneBase ¶
func (b BaseParseState) CloneBase() BaseParseState
func (*BaseParseState) Errors ¶
func (b *BaseParseState) Errors() []ParseError
func (*BaseParseState) Pos ¶
func (b *BaseParseState) Pos() int
type ErrParsedType ¶
type ErrParsedType struct{}
func (ErrParsedType) String ¶
func (ErrParsedType) String() string
type Item ¶
type LexerIface ¶
type LexerIface interface {
At(state ParseState) Item
}
type NamedValue ¶
func (NamedValue) String ¶
func (n NamedValue) String() string
type NilParsedType ¶
type NilParsedType struct{}
func (NilParsedType) String ¶
func (NilParsedType) String() string
type ParseError ¶
type ParseState ¶
type ParseState interface { Lexer() LexerIface Pos() int Errors() []ParseError Clone() ParseState // contains filtered or unexported methods }
type Parser ¶
type Parser func(p ParseState) (Parsed, ParseState)
func Maybe ¶
func Maybe(p interface{}) Parser
Maybe executes a parser which may fail. If it fails no input is consumed and NilParsed is returned. Errors are not sent to the error handler.
func MaybePeek ¶
func MaybePeek(p interface{}) Parser
MaybePeek parses p without consuming any input. If it fails, NilParsed is returned. Errors are not sent to the error handler.
func Or ¶
func Or(p ...interface{}) Parser
Or accepts 1..n parsers and attempts them one by one. The first successful match is returned. If no parsers succeed, then the error of the most successful (by length) parser is raised.
func Peek ¶
func Peek(p interface{}) Parser
Peek parses p without consuming any input. Errors are sent to the error handler.
func Recover ¶
func Recover(p interface{}, recoverfn RecoverFunc) Parser
Recover parses p. If any errors are raised while parsing p, recoverfn is called and its results become the result of Recover. Errors are sent to the error handler.
func RecoverTo ¶
RecoverTo parses p. If any errors are raised while parsing p, the lexer is fast-fowarded until after the next instance of token. Errors are sent to the error handler.
func Root ¶
func Root(p interface{}) Parser
Root parses p. If any errors are raised while parsing p, ErrParsed is returned. Errors are sent to the error handler.
func SepBy1Term ¶
func SepBy1Term(p, delim, terminator interface{}) Parser
func Seq ¶
func Seq(p ...interface{}) Parser
Sequence accepts 1..n parsers and expects them to succeed in their defined sequence
func Tok ¶
Tok is a parser which matches a given TokenType. The token is only consumed if it matches.
func Try ¶
func Try(p interface{}) Parser
Try parses p. If any errors are raised while parsing p, NilParsed is returned. Errors are not sent to the error handler.
func TryRecover ¶
func TryRecover(p interface{}, recoverfn RecoverFunc) Parser
TryRecover parses p. If any errors are raised while parsing p, recoverfn is called and its results become the result of Recover. Errors are not sent to the error handler.
func TypedProdIface ¶
Parses a named and typed production. Special case for interface typed productions. Usage: TypedProdIface("prod", (*MyIface)(nil))
type Production ¶
func (Production) String ¶
func (t Production) String() string
type RecoverFunc ¶
type RecoverFunc func(start ParseState, end ParseState) (Parsed, ParseState)