combi

package
v0.0.0-...-2a83a55 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Digit = OneOfChar("0123456789")

Functions

This section is empty.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(msg string) *Error

func Parse

func Parse[T any](parser ParseFn[T], content string) (T, *Error)

func Parsed

func Parsed[T any](result Result[T]) (T, *Error)

func (*Error) Error

func (e *Error) Error() string

type Pair

type Pair[T any, S any] struct {
	Left  T
	Right S
}

type ParseFn

type ParseFn[T any] = func(State) Result[T]

func Between

func Between[T any, S any, U any](opening ParseFn[T], p ParseFn[S], closing ParseFn[U]) ParseFn[S]

func Choice

func Choice[T any](ps ...ParseFn[T]) ParseFn[T]

Return first result matching one of the given parsers or error if none of the parsers match.

func Compose

func Compose[T any, S any](p1 ParseFn[T], p2 ParseFn[S]) ParseFn[Pair[T, S]]

func Concat

func Concat[T any](p ParseFn[Pair[[]T, []T]]) ParseFn[[]T]

func Cons

func Cons[T any](left ParseFn[T], right ParseFn[[]T]) ParseFn[[]T]

Construct list from list head and existing list

func Count

func Count[T any](p ParseFn[T], count int) ParseFn[[]T]

func DiscardLeft

func DiscardLeft[T any, S any](p1 ParseFn[T], p2 ParseFn[S]) ParseFn[S]

func DiscardMiddle

func DiscardMiddle[T any, S any, U any](opening ParseFn[T], p ParseFn[S], closing ParseFn[U]) ParseFn[Pair[T, U]]

func DiscardRight

func DiscardRight[T any, S any](p1 ParseFn[T], p2 ParseFn[S]) ParseFn[T]

func ForwardRef

func ForwardRef[T any](fn func() ParseFn[T]) ParseFn[T]

func Left

func Left[T any, S any](p ParseFn[Pair[T, S]]) ParseFn[T]

func Many

func Many[T any](p ParseFn[T]) ParseFn[[]T]

func Many1

func Many1[T any](p ParseFn[T]) ParseFn[[]T]

func Map

func Map[T any, R any](p ParseFn[T], fn func(T) R) ParseFn[R]

func Map2

func Map2[T any, S any, R any](p1 ParseFn[T], p2 ParseFn[S], fn func(T, S) R) ParseFn[R]

func Map3

func Map3[T any, S any, U any, R any](p1 ParseFn[T], p2 ParseFn[S], p3 ParseFn[U], fn func(T, S, U) R) ParseFn[R]

func Map4

func Map4[T any, S any, U any, V any, R any](p1 ParseFn[T], p2 ParseFn[S], p3 ParseFn[U], p4 ParseFn[V], fn func(T, S, U, V) R) ParseFn[R]

func MapError

func MapError[T any](p ParseFn[T], fn func(*Error, State) *Error) ParseFn[T]

func MapErrorValue

func MapErrorValue[T any](p ParseFn[T], error *Error) ParseFn[T]

func MapPair

func MapPair[T any, S any, R any](p ParseFn[Pair[T, S]], fn func(T, S) R) ParseFn[R]

func MapValue

func MapValue[T any, R any](p ParseFn[T], value R) ParseFn[R]

func Memoize

func Memoize[T any](p ParseFn[T]) ParseFn[T]

Memoize the result of the given parser by position

func NoneOfChar

func NoneOfChar(chars string) ParseFn[rune]

func OneOfChar

func OneOfChar(chars string) ParseFn[rune]

func OneOrZero

func OneOrZero[T any](p ParseFn[T]) ParseFn[T]

Parse one of zero matches of the given parser. Returns the type's zero value on zero.

func Pointer

func Pointer[T any](p ParseFn[T]) ParseFn[*T]

Map parser of value to a parser of its pointer type

func Reduce

func Reduce[T any](fn ReduceFn[T], ps ...ParseFn[T]) ParseFn[T]
func Right[T any, S any](p ParseFn[Pair[T, S]]) ParseFn[S]

func SatisfyChar

func SatisfyChar(fn func(rune rune) bool) ParseFn[rune]

func StringFromRunes

func StringFromRunes(p ParseFn[[]rune]) ParseFn[string]

Convenience combinator to go from runes to string

func Token

func Token(word string) ParseFn[string]

func Whitespace

func Whitespace() ParseFn[rune]

func Word

func Word(chars string) ParseFn[string]

type ReduceFn

type ReduceFn[T any] = func(T, T) T

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

func Failed

func Failed[T any](error *Error, state State) Result[T]

func Ok

func Ok[T any](value T, state State) Result[T]

type State

type State struct {
	// contains filtered or unexported fields
}

func NewState

func NewState(content string) State

func (State) CacheKey

func (s State) CacheKey() StateCacheKey

func (State) ConsumeSize

func (s State) ConsumeSize(size int) State

func (State) Eof

func (s State) Eof() bool

func (State) NextRune

func (s State) NextRune() (rune, int)

func (State) Rest

func (s State) Rest() string

type StateCacheKey

type StateCacheKey struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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