Files
gigaparsec/internal/bindgen/bind.go.tmpl
T
b c7a743b07e
Test and check / test-and-check (push) Canceled after 0s
Apostrophes are serious business
2026-08-21 23:11:15 -06:00

39 lines
1.2 KiB
Cheetah
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{/* SPDX-License-Identifier: Unlicense */ -}}
{{define "fparams" -}}
{{with $max := .}}{{range .Count}} f{{.}} func(T{{.}}) Parser[In, {{if eq . $max}}Out{{else}}T{{.Next}}{{end}}],
{{end}}{{end}}{{end -}}
{{define "func" -}}
{{if eq . 1}}// Bind combines p with a parser created by f that depends on ps result value.
{{- else}}// Bind{{.}} is equivalent to {{.}} nested calls to Bind.{{end}}
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 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()
success, val{{.}}, next := r{{.}}.Status()
if !success {
return Fail[In, Out](anyConsumed, r{{.}}.Message()), nil
}
{{end}}
return Succeed(anyConsumed, val{{.Next}}, next, s.MessageOK()), nil
}
}{{end -}}
// GENERATED FILE. DO NOT EDIT.
// SPDX-License-Identifier: Unlicense
package {{.Package}}
{{range .Count}}
{{template "func" .}}
{{end}}