parser

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Parser combinator libray using generics. Mostly taken from: https://github.com/jhbrown-veradept/gophercon22-parser-combinators

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMatch = errors.New("no match")
)

Functions

func Fail

func Fail[T any](initial state) (T, state, error)

func Parse

func Parse[T any](p Parser[T], data string) (T, string, error)

Types

type Empty

type Empty struct{}

type Parser

type Parser[T any] func(state) (T, state, error)

func AndThen

func AndThen[T, U any](p Parser[T], fn func(T) Parser[U]) Parser[U]

func Any

func Any(fn func(rune) bool) Parser[Empty]

func AppendKeeping

func AppendKeeping[T, U any](pt Parser[T], pu Parser[U]) Parser[Seq[T, U]]

func AppendSkipping

func AppendSkipping[T, U any](pt Parser[T], pu Parser[U]) Parser[T]

func Apply

func Apply[T, A any](p Parser[Seq[Empty, T]], fn func(T) A) Parser[A]

func Apply2

func Apply2[T, U, A any](p Parser[Seq[Seq[Empty, T], U]], fn func(T, U) A) Parser[A]

func Apply3

func Apply3[T, U, V, A any](p Parser[Seq[Seq[Seq[Empty, T], U], V]], fn func(T, U, V) A) Parser[A]

func Exact

func Exact(token string) Parser[Empty]

func GetString

func GetString[T any](p Parser[T]) Parser[string]

func If

func If(fn func(rune) bool) Parser[Empty]

func Map

func Map[T, U any](p Parser[T], fn func(T) U) Parser[U]

func OneOf

func OneOf[T any](ps ...Parser[T]) Parser[T]

func Some

func Some(fn func(rune) bool) Parser[Empty]

func StartKeeping

func StartKeeping[T any](p Parser[T]) Parser[Seq[Empty, T]]

func StartSkipping

func StartSkipping[T any](p Parser[T]) Parser[Empty]

func Succeed

func Succeed[T any](val T) Parser[T]

type Seq

type Seq[T, U any] struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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