goparsecomb

Go Reference

Go Parser Combinator with Go Generics.

How to use

currently this library is so simple. you only should follow 2 steps as below.

  • initializes parser.Parser[I, O]
  • call func (p Parser[I, O]) Parse(input I) (I, O, parser.ParseError) method

Example

package main

import (
    "github.com/Drumato/goparsecomb/pkg/strparse"
    "github.com/Drumato/goparsecomb/pkg/combinator"
)

func main() {
	subsubP := strparse.Rune('a')
	subP := strparse.TakeWhile1(subsubP)
	p := combinator.Map(subP, func(s string) (int, error) { return len(s), nil })
	i, o, err := p.Parse("aaaabaaaa")
	fmt.Println(i)
	fmt.Printf("%d\n", o)
	fmt.Println(err)
}

$ go run main.go
baaaa
4
<nil>

GitHub

View Github