func (p *IgnoreParser) Parse(sc scanner.Scanner) result.ParseResult {
	r := p.inner.Parse(sc)
	if r.Matched() {
		return result.Success(r.TextRange(), "")
	}
	return r
}
Parse parses the input.
package parser
import (
	"bytes"
	"fmt"
	"github.com/jmikkola/parsego/parser/result"
	"github.com/jmikkola/parsego/parser/scanner"
	"github.com/jmikkola/parsego/parser/textpos"
)
type Parser interface {
	Parse(sc scanner.Scanner) result.ParseResult
}
func fail(at textpos.TextPos, format string, a ...interface{}) result.ParseResult {
	return result.Failed(textpos.Single(at), fmt.Errorf(format, a...))
}
type EOFParser struct{}
func EOF() Parser {
	return &EOFParser{}
}
func (p *EOFParser) Parse(sc scanner.Scanner) result.ParseResult {
	r, err := sc.Read()
	if err == nil {
		return fail(sc.GetPos(), "expected EOF, got %c", r)
	}
	return result.Success(textpos.Single(sc.GetPos()), "")
}
type CharRangeParser struct {
	min rune  
	max rune
}
func Char(c rune) Parser {
	return &CharRangeParser{c, c}
}
func CharRange(min, max rune) Parser {
	return &CharRangeParser{min, max}
}
func (p *CharRangeParser) Parse(sc scanner.Scanner) result.ParseResult {
	start := sc.GetPos()
	r, err := sc.Read()
	if err != nil {
		return fail(sc.GetPos(), "expected a character, got error %v", err)
	}
	if r < p.min || r > p.max {
		return fail(sc.GetPos(),
			"expected a character in the range '%c' to '%c', got error %c",
			p.min, p.max, r)
	}
	return result.Success(
		textpos.Range(start, sc.GetPos()),
		string(r))
}
type TokenParser struct {
	token string
}
func Token(token string) Parser {
	return &TokenParser{token}
}
func (p *TokenParser) Parse(sc scanner.Scanner) result.ParseResult {
	start := sc.GetPos()
	seen := []rune{}
	for _, c := range p.token {
		r, err := sc.Read()
		seen = append(seen, r)
		if err != nil {
			return fail(sc.GetPos(), "expected '%s', got error %v", p.token, err)
		}
		if r != c {
			return fail(sc.GetPos(), "expected '%s', got '%s'", p.token, string(seen))
		}
	}
	return result.Success(
		textpos.Range(start, sc.GetPos()),
		string(seen))
}
type CharSetParser struct {
	allowed map[rune]struct{}
	invert  bool
}
func AnyChar(rs ...rune) Parser {
	return &CharSetParser{allowed: rarray2rmap(rs), invert: false}
}
func NoneOf(rs ...rune) Parser {
	return &CharSetParser{allowed: rarray2rmap(rs), invert: true}
}
func AnyCharIn(s string) Parser {
	return &CharSetParser{allowed: s2runemap(s), invert: false}
}
func AnyCharNotIn(s string) Parser {
	return &CharSetParser{allowed: s2runemap(s), invert: true}
}
func s2runemap(s string) map[rune]struct{} {
	m := make(map[rune]struct{}, len(s))
	for _, r := range s {
		m[r] = struct{}{}
	}
	return m
}
func rarray2rmap(rs []rune) map[rune]struct{} {
	m := make(map[rune]struct{}, len(rs))
	for _, r := range rs {
		m[r] = struct{}{}
	}
	return m
}
func (p *CharSetParser) Parse(sc scanner.Scanner) result.ParseResult {
	start := sc.GetPos()
	r, err := sc.Read()
	if err != nil {
		return fail(sc.GetPos(), "expected a character, got error %v", err)
	}
	if _, ok := p.allowed[r]; ok == p.invert {
		return fail(sc.GetPos(), "expected a character in the set, got error %c", r)
	}
	return result.Success(textpos.Range(start, sc.GetPos()), string(r))
}
type SeqParser struct {
	parsers []Parser
}
func Sequence(parsers ...Parser) Parser {
	return &SeqParser{parsers}
}
func (p *SeqParser) Parse(sc scanner.Scanner) result.ParseResult {
	start := sc.GetPos()
	var end textpos.TextPos
	results := []interface{}{}
	for _, inner := range p.parsers {
		innerResult := inner.Parse(sc)
		if !innerResult.Matched() {
			return innerResult
		}
		end = innerResult.TextRange().End()
		results = append(results, innerResult.Result())
	}
	return result.Success(textpos.Range(start, end), cleanupResult(results))
}
func cleanupResult(results []interface{}) interface{} {
	var buffer bytes.Buffer
	allStr := true
	for _, result := range results {
		if result == "" {
			continue
		}
		if s, ok := result.(string); ok {
			buffer.WriteString(s)
		} else {
			allStr = false
			break
		}
	}
	if allStr {
		return buffer.String()
	}
	return results
}
type Wrapper struct {
	inner Parser
	fn    func(interface{}) interface{}
}
func ParseWith(p Parser, fn func(interface{}) interface{}) Parser {
	return &Wrapper{inner: p, fn: fn}
}
func (p *Wrapper) Parse(sc scanner.Scanner) result.ParseResult {
	innerResult := p.inner.Parse(sc)
	if innerResult.Matched() {
		return result.Success(
			innerResult.TextRange(),
			p.fn(innerResult.Result()))
	}
	return innerResult
}
type MaybeParser struct {
	inner Parser
}
func Maybe(inner Parser) Parser {
	return &MaybeParser{inner}
}
func (p *MaybeParser) Parse(sc scanner.Scanner) result.ParseResult {
	sc.StartSnapshot()
	innerResult := p.inner.Parse(sc)
	if innerResult.Matched() {
		sc.PopSnapshot()
		return innerResult
	}
	sc.RewindSnapshot()
	return result.Success(textpos.Single(sc.GetPos()), "")
}
type ManyParser struct {
	inner   Parser
	combine bool
}
func ListOf(inner Parser) Parser {
	return &ManyParser{inner: inner, combine: false}
}
func Many(inner Parser) Parser {
	return &ManyParser{inner: inner, combine: true}
}
func (p *ManyParser) Parse(sc scanner.Scanner) result.ParseResult {
	start := sc.GetPos()
	results := []interface{}{}
	for true {
		sc.StartSnapshot()
		innerResult := p.inner.Parse(sc)
		if innerResult.Matched() {
			sc.PopSnapshot()
			results = append(results, innerResult.Result())
		} else {
			sc.RewindSnapshot()
			break
		}
	}
	var output interface{}
	if p.combine {
		output = cleanupResult(results)
	} else {
		output = results
	}
	return result.Success(textpos.Range(start, sc.GetPos()), output)
}
type OrParser struct {
	parsers []Parser
}
func Or(parsers ...Parser) Parser {
	return &OrParser{parsers}
}
func (p *OrParser) Parse(sc scanner.Scanner) result.ParseResult {
	for _, inner := range p.parsers {
		sc.StartSnapshot()
		innerResult := inner.Parse(sc)
		if innerResult.Matched() {
			sc.PopSnapshot()
			return innerResult
		}
		sc.RewindSnapshot()
	}
	return fail(sc.GetPos(), "no parser matched")
}
type Named struct {
	Name   string
	Parser Parser
}
type MapParser struct {
	parsers []Named
	fn      func(map[string]interface{}) interface{}
}
func Map(parsers []Named, fn func(map[string]interface{}) interface{}) Parser {
	return &MapParser{
		parsers: parsers,
		fn:      fn,
	}
}
func (p *MapParser) Parse(sc scanner.Scanner) result.ParseResult {
	parsed := map[string]interface{}{}
	start := sc.GetPos()
	for _, named := range p.parsers {
		innerResult := named.Parser.Parse(sc)
		if !innerResult.Matched() {
			return innerResult
		}
		if named.Name != "" {
			parsed[named.Name] = innerResult.Result()
		}
	}
	return result.Success(textpos.Range(start, sc.GetPos()), p.fn(parsed))
}
type LazyFn struct {
	fn func() Parser
}
func Lazy(fn func() Parser) Parser {
	return &LazyFn{fn}
}
func (p *LazyFn) Parse(sc scanner.Scanner) result.ParseResult {
	actual := p.fn()
	return actual.Parse(sc)
}
type IgnoreParser struct {
	inner Parser
}
func Ignore(inner Parser) Parser {
	return &IgnoreParser{inner}
}