Document Bind and friends

This commit is contained in:
Brandon Dyck 2024-09-13 19:24:23 -06:00
parent 3e8b0e663c
commit 6256b73325
2 changed files with 7 additions and 0 deletions

View File

@ -2,6 +2,7 @@
package gigaparsec package gigaparsec
// Bind combines p with a parser created by f that depends on p's result value.
func Bind[In, Out, T any]( func Bind[In, Out, T any](
p Parser[In, T], p Parser[In, T],
f func(T) Parser[In, Out], f func(T) Parser[In, Out],
@ -38,6 +39,7 @@ func Bind[In, Out, T any](
} }
} }
// Bind2 is equivalent to 2 nested calls to Bind.
func Bind2[In, Out, T, T2 any]( func Bind2[In, Out, T, T2 any](
p Parser[In, T], p Parser[In, T],
f func(T) Parser[In, T2], f func(T) Parser[In, T2],
@ -86,6 +88,7 @@ func Bind2[In, Out, T, T2 any](
} }
} }
// Bind3 is equivalent to 3 nested calls to Bind.
func Bind3[In, Out, T, T2, T3 any]( func Bind3[In, Out, T, T2, T3 any](
p Parser[In, T], p Parser[In, T],
f func(T) Parser[In, T2], f func(T) Parser[In, T2],
@ -146,6 +149,7 @@ func Bind3[In, Out, T, T2, T3 any](
} }
} }
// Bind4 is equivalent to 4 nested calls to Bind.
func Bind4[In, Out, T, T2, T3, T4 any]( func Bind4[In, Out, T, T2, T3, T4 any](
p Parser[In, T], p Parser[In, T],
f func(T) Parser[In, T2], f func(T) Parser[In, T2],
@ -218,6 +222,7 @@ func Bind4[In, Out, T, T2, T3, T4 any](
} }
} }
// Bind5 is equivalent to 5 nested calls to Bind.
func Bind5[In, Out, T, T2, T3, T4, T5 any]( func Bind5[In, Out, T, T2, T3, T4, T5 any](
p Parser[In, T], p Parser[In, T],
f func(T) Parser[In, T2], f func(T) Parser[In, T2],

View File

@ -3,6 +3,8 @@
{{end}}{{end}}{{end -}} {{end}}{{end}}{{end -}}
{{define "func" -}} {{define "func" -}}
{{if eq . 1}}// Bind combines p with a parser created by f that depends on p's result value.
{{- else}}// Bind{{.}} is equivalent to {{.}} nested calls to Bind.{{end}}
func Bind{{.}}[In, Out{{range .Count}}, T{{.}}{{end}} any]( func Bind{{.}}[In, Out{{range .Count}}, T{{.}}{{end}} any](
p Parser[In, T], p Parser[In, T],
{{template "fparams" .}}) Parser[In, Out] { {{template "fparams" .}}) Parser[In, Out] {