Documentation
¶
Overview ¶
Package parcom provides parser combinators to parse CFG or position-aware grammars.
Index ¶
- type Error
- type Parser
- type PositionalState
- func (s *PositionalState) Block(p Parser) Parser
- func (s *PositionalState) Block1(p Parser) Parser
- func (s *PositionalState) ExhaustiveBlock(p Parser) Parser
- func (s *PositionalState) HeteroBlock(ps ...Parser) Parser
- func (s *PositionalState) Indent(p Parser) Parser
- func (s *PositionalState) SameColumn(p Parser) Parser
- func (s *PositionalState) SameLine(p Parser) Parser
- func (s *PositionalState) SameLineOrIndent(p Parser) Parser
- func (s *PositionalState) WithBlock(p, pp Parser) Parser
- func (s *PositionalState) WithBlock1(p, pp Parser) Parser
- func (s *PositionalState) WithPosition(p Parser) Parser
- type State
- func (s *State) And(ps ...Parser) Parser
- func (s *State) App(f func(interface{}) (interface{}, error), p Parser) Parser
- func (s *State) Char(r rune) Parser
- func (s *State) Chars(cs string) Parser
- func (s State) Column() int
- func (s *State) Exhaust(p Parser) Parser
- func (s *State) ExhaustiveMany(p Parser) Parser
- func (s *State) Lazy(f func() Parser) Parser
- func (s State) Line() int
- func (s *State) Many(p Parser) Parser
- func (s *State) Many1(p Parser) Parser
- func (s *State) Maybe(p Parser) Parser
- func (s *State) None() Parser
- func (s *State) NotChar(r rune) Parser
- func (s *State) NotChars(str string) Parser
- func (s *State) Or(ps ...Parser) Parser
- func (s *State) Prefix(p, q Parser) Parser
- func (s *State) Str(str string) Parser
- func (s *State) Stringify(p Parser) Parser
- func (s *State) Suffix(p, q Parser) Parser
- func (State) Void(p Parser) Parser
- func (s *State) Wrap(l, m, r Parser) Parser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is an parsing error.
type PositionalState ¶
type PositionalState struct {
State
// contains filtered or unexported fields
}
PositionalState is a position-aware parser state.
func NewPositionalState ¶
func NewPositionalState(s string) *PositionalState
NewPositionalState creates a parser state.
func (*PositionalState) Block ¶
func (s *PositionalState) Block(p Parser) Parser
Block parses a block of a given parser.
func (*PositionalState) Block1 ¶
func (s *PositionalState) Block1(p Parser) Parser
Block1 is the same as Block but blocks must have at least one element.
func (*PositionalState) ExhaustiveBlock ¶
func (s *PositionalState) ExhaustiveBlock(p Parser) Parser
ExhaustiveBlock parses a block of a given parser exhaustively.
func (*PositionalState) HeteroBlock ¶
func (s *PositionalState) HeteroBlock(ps ...Parser) Parser
HeteroBlock creates a parser to parse something all in the same column.
func (*PositionalState) Indent ¶
func (s *PositionalState) Indent(p Parser) Parser
Indent creates a parser which parses an indent before running a given parser. It is equivalent to a given parser and parses no indent if no position is saved beforehand.
func (*PositionalState) SameColumn ¶
func (s *PositionalState) SameColumn(p Parser) Parser
SameColumn creates a parser which parses something in the same column.
func (*PositionalState) SameLine ¶
func (s *PositionalState) SameLine(p Parser) Parser
SameLine creates a parser which parses something in the same line.
func (*PositionalState) SameLineOrIndent ¶
func (s *PositionalState) SameLineOrIndent(p Parser) Parser
SameLineOrIndent creates a parser which parses something in the same line or indented.
func (*PositionalState) WithBlock ¶
func (s *PositionalState) WithBlock(p, pp Parser) Parser
WithBlock creates a parser which parses a block of the second parsers prefixed by the first parser. Blocks must have at least one element.
func (*PositionalState) WithBlock1 ¶
func (s *PositionalState) WithBlock1(p, pp Parser) Parser
WithBlock1 creates a parser which parses a block of the second parsers prefixed by the first parser. Blocks must have at least one element.
func (*PositionalState) WithPosition ¶
func (s *PositionalState) WithPosition(p Parser) Parser
WithPosition creates a parser saving a current position.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is a parser state.
func (*State) Exhaust ¶
Exhaust creates a parser which fails when a source string is not exhausted after running a given parser.
func (*State) ExhaustiveMany ¶
ExhaustiveMany creates a parser of more than or equal to 0 repetition of a given parser which continues parsing until a source is exhausted.
func (*State) Lazy ¶
Lazy creates a parser which runs a parser created by a given constructor. This combinator is useful to define recursive parsers.
func (*State) Maybe ¶
Maybe creates a parser which runs a given parser or parses nothing when it fails.
func (*State) NotChar ¶
NotChar creates a parser to parse a character which is not the one of an argument.
func (*State) Prefix ¶
Prefix creates a parser with 2 parsers which returns the second one's result.
func (*State) Stringify ¶
Stringify creates a parser which returns a string converted from a result of a given parser. The result of a given parser must be a rune, a string or a sequence of them in []interface{}.