Documentation ¶
Index ¶
- type ExpectedError
- type ExpectedFatalError
- type PositionalError
- type Result
- type Type
- func Array() Type
- func BestMatch(parsers ...Type) Type
- func Boolean() Type
- func Char(c rune) Type
- func Comment() Type
- func Delimited(primary, delimiter Type) Type
- func DelimitedPattern(start, primary, delimiter, stop Type, allowTrailing, returnDelimiters bool) Type
- func Discard(parser Type) Type
- func DiscardAll(parser Type) Type
- func Expect(parser Type, expected ...string) Type
- func InRange(lower, upper rune) Type
- func InSet(set ...rune) Type
- func JoinStringPayloads(p Type) Type
- func LiteralValue() Type
- func MustBe(parser Type) Type
- func Newline() Type
- func NewlineAllowComment() Type
- func NotChar(c rune) Type
- func NotEnd(p Type, exp ExpectedError) Type
- func Null() Type
- func Number() Type
- func Object() Type
- func OneOf(parsers ...Type) Type
- func Optional(parser Type) Type
- func QuotedString() Type
- func Sequence(parsers ...Type) Type
- func SnakeCase() Type
- func SpacesAndTabs() Type
- func Term(str string) Type
- func TripleQuoteString() Type
- func UntilFail(parser Type) Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpectedError ¶
type ExpectedError []string
ExpectedError represents a parser error where one of a list of possible tokens was expected but not found.
func (ExpectedError) Append ¶ added in v3.16.0
func (e ExpectedError) Append(exp ExpectedError) ExpectedError
Append an expected error to another (and remove duplicates).
func (ExpectedError) Error ¶
func (e ExpectedError) Error() string
Error returns a human readable error string.
type ExpectedFatalError ¶ added in v3.13.0
type ExpectedFatalError []string
ExpectedFatalError represents a parser error where one of a list of possible tokens was expected but not found, and this is a fatal error.
func (ExpectedFatalError) Error ¶ added in v3.13.0
func (e ExpectedFatalError) Error() string
Error returns a human readable error string.
type PositionalError ¶
PositionalError represents an error that has occurred at a particular position in the input.
func ErrAtPosition ¶
func ErrAtPosition(i int, err error) PositionalError
ErrAtPosition takes an error and returns a positional wrapper. If the provided error is itself a positional type then the position is aggregated.
func (PositionalError) Error ¶
func (e PositionalError) Error() string
Error returns a human readable error string.
func (PositionalError) Expand ¶
func (e PositionalError) Expand(fn func(error) error) PositionalError
Expand the underlying error with more context.
func (PositionalError) Unwrap ¶
func (e PositionalError) Unwrap() error
Unwrap returns the underlying error.
type Type ¶
Type is a general parser method.
func BestMatch ¶ added in v3.13.0
BestMatch accepts one or more parsers and tries them all against an input. If any parser returns a non ExpectedError error then it is returned. If all parsers return either a result or an ExpectedError then the parser that got further through the input will have its result returned. This means that an error may be returned even if a parser was successful.
For example, given two parsers, A searching for 'aa', and B searching for 'aaaa', if the input 'aaab' were provided then an error from parser B would be returned, as although the input didn't match, it matched more of parser B than parser A.
func Comment ¶ added in v3.13.0
func Comment() Type
Comment parses a # comment (always followed by a line break).
func Delimited ¶ added in v3.13.0
Delimited attempts to parse one or more primary parsers, where after the first parse a delimiter is expected. Parsing is stopped only once a delimiter parse is not successful.
Two slices are returned, the first element being a slice of primary results and the second element being the delimiter results.
func DelimitedPattern ¶ added in v3.13.0
func DelimitedPattern( start, primary, delimiter, stop Type, allowTrailing, returnDelimiters bool, ) Type
DelimitedPattern attempts to parse zero or more primary parsers in between an start and stop parser, where after the first parse a delimiter is expected. Parsing is stopped only once an explicit stop parser is successful.
If allowTrailing is set to false and a delimiter is parsed but a subsequent primary parse fails then an error is returned.
Only the results of the primary parser are returned, the results of the start, delimiter and stop parsers are discarded. If returnDelimiters is set to true then two slices are returned, the first element being a slice of primary results and the second element being the delimiter results.
func Discard ¶ added in v3.13.0
Discard the result of a child parser, regardless of the result. This has the effect of running the parser and returning only Remaining.
func DiscardAll ¶ added in v3.13.0
DiscardAll the results of a child parser, applied until it fails. This has the effect of running the parser and returning only Remaining.
func Expect ¶ added in v3.14.0
Expect applies a parser and if an ExpectedError (or ExpectedFatalError) is returned its contents are replaced with the provided list. This is useful for providing better context to users.
func JoinStringPayloads ¶ added in v3.14.0
JoinStringPayloads wraps a parser that returns a []interface{} of exclusively string values and returns a result of a joined string of all the elements.
Warning! If the result is not a []interface{}, or if an element is not a string, then this parser returns a zero value instead.
func LiteralValue ¶ added in v3.13.0
func LiteralValue() Type
LiteralValue parses a literal bool, number, quoted string, null value, array of literal values, or object.
func MustBe ¶ added in v3.13.0
MustBe applies a parser and if the result is an ExpectedError converts it into a fatal error in order to prevent fallback parsers during AnyOf.
func NewlineAllowComment ¶ added in v3.13.0
func NewlineAllowComment() Type
NewlineAllowComment parses an optional comment followed by a mandatory line break.
func NotEnd ¶
func NotEnd(p Type, exp ExpectedError) Type
NotEnd parses zero characters from an input and expects it to not have ended. An ExpectedError must be provided which provides the error returned on empty input.
func Number ¶
func Number() Type
Number parses any number of numerical characters into either an int64 or, if the number contains float characters, a float64.
func OneOf ¶ added in v3.14.0
OneOf accepts one or more parsers and tries them in order against an input. If a parser returns an ExpectedError then the next parser is tried and so on. Otherwise, the result is returned.
func Optional ¶ added in v3.13.0
Optional applies a child parser and if it returns an ExpectedError then it is cleared and a nil result is returned instead. Any other form of error will be returned unchanged.
func QuotedString ¶
func QuotedString() Type
QuotedString parses a single instance of a quoted string. The result is the inner contents unescaped.
func Sequence ¶ added in v3.13.0
Sequence applies a sequence of parsers and returns either a slice of the results or an error if any parser fails.
func SnakeCase ¶ added in v3.13.0
func SnakeCase() Type
SnakeCase parses any number of characters of a camel case string. This parser is very strict and does not support double underscores, prefix or suffix underscores.
func SpacesAndTabs ¶
func SpacesAndTabs() Type
SpacesAndTabs parses any number of space or tab characters.
func TripleQuoteString ¶ added in v3.16.0
func TripleQuoteString() Type
TripleQuoteString parses a single instance of a triple-quoted multiple line string. The result is the inner contents.