parse

package
v0.0.0-...-250c7b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyInput = errors.New("no input to parse")
)

Functions

This section is empty.

Types

type Bool

type Bool struct{}

func (Bool) Parse

func (_ Bool) Parse(input ...string) (bool, error)

type C

type C int

C is a special 'counter' type that tracks the number of times a particular argument is supplied, expecting no value to be supplied - like a boolean flag.

type Counter

type Counter struct{}

Counter is a parser for some C - it tracks how many times the argument was supplied rather than the value supplied.

func (Counter) Parse

func (_ Counter) Parse(input ...string) (C, error)

type File

type File struct {
	Mode *os.FileMode
	Flag *int
}

func (File) Parse

func (f File) Parse(input ...string) (*os.File, error)

type Float64

type Float64 struct{}

func (Float64) Parse

func (_ Float64) Parse(input ...string) (float64, error)

type Func

type Func[T any] func(input ...string) (output T, err error)

A Func is a convenient Parser[T] implementation.

func (Func[T]) Parse

func (fn Func[T]) Parse(input ...string) (T, error)

type I

type I bool

I is a special 'indicator' that acts as a boolean switch that can be supplied multiple times.

type Indicator

type Indicator struct {
	Initial bool
}

Indicator is a parser for some I - it flips the value for each time the input is supplied/detected.

func (Indicator) Parse

func (i Indicator) Parse(input ...string) (I, error)

type Int

type Int struct{}

func (Int) Parse

func (_ Int) Parse(in ...string) (int, error)

type Ints

type Ints struct{}

func (Ints) Parse

func (_ Ints) Parse(input ...string) ([]int, error)

type Parser

type Parser[T any] interface {
	// Parse should attempt to parse a new variable from the given input, returning an informative error on failure
	Parse(input ...string) (T, error)
}

A Parser is responsible for parsing some type T from string input.

func Anonymize

func Anonymize[T any](parser Parser[T]) Parser[any]

Anonymize is a helper function for converting a typed Parser[T] into an untyped Parser[any].

Returned type is a Func[any].

func Slice

func Slice[T any](p Parser[T]) Parser[[]T]

Slice is a helper function to convert a Parser[T] into a Parser[[]T].

Return type is a Func[[]T].

type String

type String struct{}

func (String) Parse

func (_ String) Parse(input ...string) (string, error)

type Strings

type Strings struct{}

func (Strings) Parse

func (_ Strings) Parse(input ...string) ([]string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL