gigaparsec/internal/bindgen/seq.go.tmpl

36 lines
954 B
Cheetah
Raw Permalink 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 next = s
{{range .Count}}
r{{.}}, err := p{{.}}(next)
if err != nil {
return Result[In, Out]{}, err
}
anyConsumed = anyConsumed || r{{.}}.Consumed()
success, val{{.}}, next := r{{.}}.Status()
if !success {
2024-09-24 18:56:10 +00:00
return Fail[In, Out](anyConsumed, r{{.}}.Message()), nil
2024-09-14 02:48:33 +00:00
}
{{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}}