gigaparsec/internal/bindgen/seq.go.tmpl

39 lines
1013 B
Cheetah
Raw Normal View History

{{/* SPDX-License-Identifier: Unlicense */ -}}
2024-09-14 02:48:33 +00:00
{{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.
// SPDX-License-Identifier: Unlicense
2024-09-14 02:48:33 +00:00
package {{.Package}}
{{range .Count}}{{template "func" .}}
{{end}}