36 lines
986 B
Cheetah
36 lines
986 B
Cheetah
|
{{define "fparams" -}}
|
||
|
{{with $max := .}}{{range .Count}} f{{.}} func(T{{.}}) Parser[In, {{if eq . $max}}Out{{else}}T{{.Next}}{{end}}],
|
||
|
{{end}}{{end}}{{end -}}
|
||
|
|
||
|
{{define "func" -}}
|
||
|
func Bind{{.}}[In, Out{{range .Count}}, T{{.}}{{end}} any](
|
||
|
p Parser[In, T],
|
||
|
{{template "fparams" .}}) 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 .Next.Count}}
|
||
|
r{{.}}, err := {{if eq . 1}}p(next){{else}}f{{.Prev}}(val{{.Prev}})(next){{end}}
|
||
|
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}}
|
||
|
return Succeed(anyConsumed, val{{.Next}}, next, MessageOK(s.Pos())), nil
|
||
|
}
|
||
|
}{{end -}}
|
||
|
|
||
|
// GENERATED FILE. DO NOT EDIT.
|
||
|
|
||
|
package {{.Package}}
|
||
|
{{range .Count}}
|
||
|
{{template "func" .}}
|
||
|
{{end}}
|