Documentation ¶
Index ¶
- func Byte[T ~byte](in string) (T, error)
- func Rune(in string) (rune, error)
- func Signed[T constraints.Signed](in string) (T, error)
- func String[T ~string](in string) (T, error)
- func Unsigned[T constraints.Unsigned](in string) (T, error)
- type Parser
- func Any[T any](p ...any) Parser[T]
- func Array[A, T any](s split.Func, p Parser[T]) Parser[A]
- func Blocks[T any](p Parser[T]) Parser[[]T]
- func Enum[T ~byte | ~rune | ~string](opts ...T) Parser[T]
- func Fields[T any](p Parser[T]) Parser[[]T]
- func Lines[T any](p Parser[T]) Parser[[]T]
- func Map[K comparable, V any](split, cut split.Func, k Parser[K], v Parser[V]) Parser[map[K]V]
- func MapParser[A, B any](p Parser[A], f func(A) (B, error)) Parser[B]
- func Prefix[T any](prefix string, p Parser[T]) Parser[T]
- func Slice[T any](s split.Func, p Parser[T]) Parser[[]T]
- func Struct[S any](s split.Func, fields ...any) Parser[S]
- func TrimSpace[T any](p Parser[T]) Parser[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Parser ¶
A Parser is a generic, composable parser.
func Any ¶
Any runs a set of parser, one after the other, returning the first succesful result. The parsers don't have to return the same type, but they must return something assignable to T.
func Array ¶
Array splits a string and calls p for each piece. A must be an array type with element type T.
func Map ¶
Map parses a map. It uses split to separate the input into key/value pairs and then uses cut to cut them up into a key and a value, which are parsed using k and v respectively.
It errors if a key is duplicated.
func Struct ¶
Struct splits a string and parses the result into the fields of a struct using the given parsers.
S must be a struct type with the same number of exported fields as split returns. The variadic fields argument must all be of type Parser[T] and T must match the exported field of S in the same sequence.