gigaparsec

package module
v0.0.0-...-13d83e7 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Unlicense Imports: 6 Imported by: 0

README

Gigaparsec

Go Reference Total garbage.

Monadic parser combinators in Go

I don't recommend using this yet. It is very unfinished and it will break.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pipe

func Pipe[In, Ignore, Through any](p Parser[In, Ignore]) func(Through) Parser[In, Through]

func Run

func Run[In, Out any](p Parser[In, Out], r ReaderAt[In]) (out Out, err error)

Types

type Message

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

func MakeMessage

func MakeMessage(pos uint64, got string, expected ...string) Message

func MessageEnd

func MessageEnd(pos uint64, expected ...string) Message

func MessageOK

func MessageOK(pos uint64) Message

func (Message) Expected

func (m Message) Expected() []string

func (Message) Got

func (m Message) Got() string

func (Message) Pos

func (m Message) Pos() uint64

func (Message) String

func (m Message) String() string

type ParseError

type ParseError Message

func (ParseError) Error

func (pe ParseError) Error() string

type Parser

type Parser[In, Out any] func(State[In]) (Result[In, Out], error)

func Bind

func Bind[In, Out, T any](
	p Parser[In, T],
	f func(T) Parser[In, Out],
) Parser[In, Out]

Bind combines p with a parser created by f that depends on p's result value.

func Bind2

func Bind2[In, Out, T, T2 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, Out],
) Parser[In, Out]

Bind2 is equivalent to 2 nested calls to Bind.

func Bind2Naïve

func Bind2Naïve[In, Out, T, T2 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, Out],
) Parser[In, Out]

func Bind3

func Bind3[In, Out, T, T2, T3 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, Out],
) Parser[In, Out]

Bind3 is equivalent to 3 nested calls to Bind.

func Bind3Naïve

func Bind3Naïve[In, Out, T, T2, T3, T4, T5, T6, T7, T8, T9 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, Out],
) Parser[In, Out]

func Bind4

func Bind4[In, Out, T, T2, T3, T4 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, Out],
) Parser[In, Out]

Bind4 is equivalent to 4 nested calls to Bind.

func Bind4Naïve

func Bind4Naïve[In, Out, T, T2, T3, T4 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, Out],
) Parser[In, Out]

func Bind5

func Bind5[In, Out, T, T2, T3, T4, T5 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, Out],
) Parser[In, Out]

Bind5 is equivalent to 5 nested calls to Bind.

func Bind5Naïve

func Bind5Naïve[In, Out, T, T2, T3, T4, T5 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, Out],
) Parser[In, Out]

func Bind6

func Bind6[In, Out, T, T2, T3, T4, T5, T6 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, Out],
) Parser[In, Out]

Bind6 is equivalent to 6 nested calls to Bind.

func Bind6Naïve

func Bind6Naïve[In, Out, T, T2, T3, T4, T5, T6 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, Out],
) Parser[In, Out]

func Bind7

func Bind7[In, Out, T, T2, T3, T4, T5, T6, T7 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, T7],
	f7 func(T7) Parser[In, Out],
) Parser[In, Out]

Bind7 is equivalent to 7 nested calls to Bind.

func Bind7Naïve

func Bind7Naïve[In, Out, T, T2, T3, T4, T5, T6, T7 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, T7],
	f7 func(T7) Parser[In, Out],
) Parser[In, Out]

func Bind8

func Bind8[In, Out, T, T2, T3, T4, T5, T6, T7, T8 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, T7],
	f7 func(T7) Parser[In, T8],
	f8 func(T8) Parser[In, Out],
) Parser[In, Out]

Bind8 is equivalent to 8 nested calls to Bind.

func Bind8Naïve

func Bind8Naïve[In, Out, T, T2, T3, T4, T5, T6, T7, T8 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, T7],
	f7 func(T7) Parser[In, T8],
	f8 func(T8) Parser[In, Out],
) Parser[In, Out]

func Bind9

func Bind9[In, Out, T, T2, T3, T4, T5, T6, T7, T8, T9 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, T7],
	f7 func(T7) Parser[In, T8],
	f8 func(T8) Parser[In, T9],
	f9 func(T9) Parser[In, Out],
) Parser[In, Out]

Bind9 is equivalent to 9 nested calls to Bind.

func Bind9Naïve

func Bind9Naïve[In, Out, T, T2, T3, T4, T5, T6, T7, T8, T9 any](
	p Parser[In, T],
	f func(T) Parser[In, T2],
	f2 func(T2) Parser[In, T3],
	f3 func(T3) Parser[In, T4],
	f4 func(T4) Parser[In, T5],
	f5 func(T5) Parser[In, T6],
	f6 func(T6) Parser[In, T7],
	f7 func(T7) Parser[In, T8],
	f8 func(T8) Parser[In, T9],
	f9 func(T9) Parser[In, Out],
) Parser[In, Out]

func Choose

func Choose[In, Out any](p Parser[In, Out], ps ...Parser[In, Out]) Parser[In, Out]

func End

func End[In any]() Parser[In, struct{}]

End creates a parser that succeeds at the end of the input and fails otherwise.

func Map

func Map[In, Out1, Out2 any](p Parser[In, Out1], f func(Out1) Out2) Parser[In, Out2]

Map creates a parser that converts the output of p from Out1 to Out2.

func Match

func Match[T comparable](x T) Parser[T, T]

Match creates a parser that attempts to read an input value equal to x. If Match succeeds, it returns the matched input value.

func MatchSlice

func MatchSlice[T comparable](s []T) Parser[T, []T]

MatchSlice creates a parser that attempts to read the contents of s from the input. If MatchSlice succeeds, it returns a copy of the matched input values.

func Repeat

func Repeat[In, Out any](minCount int, p Parser[In, Out]) Parser[In, []Out]

Repeat applies p until p fails, and returns the collected outputs. It succeeds if and only if p succeeds at least minCount times. It consumes if and only if at least one of the applications of p consumes.

func Return

func Return[In, Out any](value Out) Parser[In, Out]

Return creates a parser that always succeeds and returns value without consuming any input.

func Satisfy

func Satisfy[T any](pred func(T) bool) Parser[T, T]

Satisfy creates a parser that attempts to read an input value for which pred returns true. If Satisfy succeeds, it returns the matched input value.

func Seq2

func Seq2[In, Out, T, T2 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	f func(T, T2) Out,
) Parser[In, Out]

func Seq3

func Seq3[In, Out, T, T2, T3 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	p3 Parser[In, T3],
	f func(T, T2, T3) Out,
) Parser[In, Out]

func Seq4

func Seq4[In, Out, T, T2, T3, T4 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	p3 Parser[In, T3],
	p4 Parser[In, T4],
	f func(T, T2, T3, T4) Out,
) Parser[In, Out]

func Seq5

func Seq5[In, Out, T, T2, T3, T4, T5 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	p3 Parser[In, T3],
	p4 Parser[In, T4],
	p5 Parser[In, T5],
	f func(T, T2, T3, T4, T5) Out,
) Parser[In, Out]

func Seq6

func Seq6[In, Out, T, T2, T3, T4, T5, T6 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	p3 Parser[In, T3],
	p4 Parser[In, T4],
	p5 Parser[In, T5],
	p6 Parser[In, T6],
	f func(T, T2, T3, T4, T5, T6) Out,
) Parser[In, Out]

func Seq7

func Seq7[In, Out, T, T2, T3, T4, T5, T6, T7 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	p3 Parser[In, T3],
	p4 Parser[In, T4],
	p5 Parser[In, T5],
	p6 Parser[In, T6],
	p7 Parser[In, T7],
	f func(T, T2, T3, T4, T5, T6, T7) Out,
) Parser[In, Out]

func Seq8

func Seq8[In, Out, T, T2, T3, T4, T5, T6, T7, T8 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	p3 Parser[In, T3],
	p4 Parser[In, T4],
	p5 Parser[In, T5],
	p6 Parser[In, T6],
	p7 Parser[In, T7],
	p8 Parser[In, T8],
	f func(T, T2, T3, T4, T5, T6, T7, T8) Out,
) Parser[In, Out]

func Seq9

func Seq9[In, Out, T, T2, T3, T4, T5, T6, T7, T8, T9 any](
	p Parser[In, T],
	p2 Parser[In, T2],
	p3 Parser[In, T3],
	p4 Parser[In, T4],
	p5 Parser[In, T5],
	p6 Parser[In, T6],
	p7 Parser[In, T7],
	p8 Parser[In, T8],
	p9 Parser[In, T9],
	f func(T, T2, T3, T4, T5, T6, T7, T8, T9) Out,
) Parser[In, Out]

func Try

func Try[In, Out any](p Parser[In, Out]) Parser[In, Out]

Try behaves identically to p, except that if p returns an error, Try will pretend that no input was consumed. This allows infinite lookahead: Since Choose only calls another parser when the previous parser consumed nothing, Try will allow backing out of a complex parser that partially succeeded.

func (Parser[In, Out]) Label

func (p Parser[In, Out]) Label(label string) Parser[In, Out]

Label creates a parser identical to p, except that a failed result will include label as an expected parse.

type ReaderAt

type ReaderAt[T any] interface {
	ReadAt(p []T, off int64) (n int, err error)
}

type Result

type Result[In, Out any] struct {
	// contains filtered or unexported fields
}

func Fail

func Fail[In, Out any](consumed bool, msg Message) Result[In, Out]

func Succeed

func Succeed[In, Out any](consumed bool, value Out, next State[In], msg Message) Result[In, Out]

func (Result[In, Out]) Consume

func (r Result[In, Out]) Consume(consumed bool) Result[In, Out]

func (Result[In, Out]) Consumed

func (r Result[In, Out]) Consumed() bool

func (Result[In, Out]) Message

func (r Result[In, Out]) Message() Message

func (Result[In, Out]) Status

func (r Result[In, Out]) Status() (success bool, value Out, next State[In])

type SliceReaderAt

type SliceReaderAt[T any] []T

func (SliceReaderAt[T]) ReadAt

func (s SliceReaderAt[T]) ReadAt(dst []T, off int64) (n int, err error)

type State

type State[In any] struct {
	// contains filtered or unexported fields
}

func MakeState

func MakeState[In any](r ReaderAt[In]) State[In]

func (State[In]) At

func (s State[In]) At(pos uint64) State[In]

At returns a State pointing at pos in the same data source.

func (State[In]) Pos

func (s State[In]) Pos() uint64

Pos returns this State's position.

func (State[In]) Read

func (s State[In]) Read(dst []In) (n uint64, next State[In], err error)

Read fills dst with data from this State's position in the underlying source. It returns the number of data it read and a new State for the position at which the read ended, and an error if the read either (1) failed or (2) reached the end of the source before filling dst. All reads from a given State will return data from the same position the source. If the source had too few data left to fill dst, or if the State's position is at or past the end of the source, err will be io.EOF.

Directories

Path Synopsis
internal
Package test contains helpers for testing parsers.
Package test contains helpers for testing parsers.

Jump to

Keyboard shortcuts

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