Documentation ¶
Overview ¶
Package rd provides recursive descent parser helpers. This is not really intended of use outside of this library, but some objects here are exposed and could be useful in some applications. This should probably be a separate package library.
Index ¶
- type ATag
- type Match
- func BuildMatch(t ATag, ms ...interface{}) (m *Match)
- func MatchLongest(cs []byte, ms ...Matcher) (*Match, []byte)
- func MatchMany(t ATag, cs []byte, min int, mtch Matcher) (*Match, []byte)
- func MatchManyWithSep(t ATag, cs []byte, min int, mtch Matcher, sep Matcher) (*Match, []byte)
- func MatchOne(t ATag, cs []byte, pred func(c byte) bool) (*Match, []byte)
- func MatchOneRune(t ATag, cs []byte, c rune) (*Match, []byte)
- type Matcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Match ¶
type Match struct { Tag ATag // an identifier describing what the match represents Content []byte // the full content of the match Group map[string]*Match // identifies named submatches Submatch []*Match // identifies a list of submatches Made interface{} // a place to put high-level objects generated from this match }
Match is the object used to represent some segment of a parsed string.
func BuildMatch ¶
BuildMatch is a short hand for building a match with named submatches.
func MatchLongest ¶
MatchLongest tries all the given matchers against the current input. It then returns whichever of these matches works to match the most input.
func MatchMany ¶
MatchMany matches the given matcher as many times as possible one after another on the input. If the number of matches is fewer than min, it returns a failure.
func MatchManyWithSep ¶
MatchManyWithSep matches the given matcher against the input provided that the separator matcher matches in between. It returns a match containing those matches. If fewer than min matches are present, the match returns no match.
func MatchOne ¶
MatchOne matches exactly one byte if the next byte in the input matches the given predicate.
func MatchOneRune ¶
MatchOneRune matches the next byte if it exactly matches the given rune.
type Matcher ¶
Matcher is the type for matching functions. These accept a list of bytes to start matching from and return a pointer to a Match and a list of remaining unmatched bytes.
If the match is successful, then a pointer to a Match is returned and the remaining input is also returned. It is possible for a match to match zero bytes.
If the match fails, then the Match should be returned as nil. Usually the remaining input is also returned as nil in that case.