gigaparsec/internal/bindgen/seq.go.tmpl
2024-09-13 20:48:33 -06:00

35 lines
926 B
Cheetah

{{define "func"}}{{if gt . 1 -}}
func Seq{{.}}[In, Out{{range .Count}}, T{{.}}{{end}} any](
{{- range .Count}}
p{{.}} Parser[In, T{{.}}],{{end}}
f func({{range .Count}}{{if ne . 1}}, {{end}}T{{.}}{{end}}) Out,
) Parser[In, Out] {
return func(s State[In]) (Result[In, Out], error) {
var anyConsumed bool
var failed bool
var msg Message
var next = s
{{range .Count}}
r{{.}}, err := p{{.}}(next)
if err != nil {
return Result[In, Out]{}, err
}
anyConsumed = anyConsumed || r{{.}}.Consumed()
failed, _, msg = r{{.}}.Failed()
if failed {
return Fail[In, Out](anyConsumed, msg), nil
}
_, _, val{{.}}, next, _ := r{{.}}.Succeeded()
{{end}}
final := f({{range .Count}}{{if ne . 1}}, {{end}}val{{.}}{{end}})
return Succeed(anyConsumed, final, next, MessageOK(s.Pos())), nil
}
}{{end}}{{end -}}
// GENERATED FILE. DO NOT EDIT.
package {{.Package}}
{{range .Count}}{{template "func" .}}
{{end}}