309 lines
7.2 KiB
Go
309 lines
7.2 KiB
Go
// GENERATED FILE. DO NOT EDIT.
|
|
|
|
package gigaparsec
|
|
|
|
// Bind combines p with a parser created by f that depends on p's result value.
|
|
func Bind[In, Out, T any](
|
|
p Parser[In, T],
|
|
f func(T) Parser[In, 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
|
|
|
|
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()
|
|
|
|
r2, err := f(val)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r2.Consumed()
|
|
failed, _, msg = r2.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val2, next, _ := r2.Succeeded()
|
|
|
|
return Succeed(anyConsumed, val2, next, MessageOK(s.Pos())), nil
|
|
}
|
|
}
|
|
|
|
// Bind2 is equivalent to 2 nested calls to Bind.
|
|
func Bind2[In, Out, T, T2 any](
|
|
p Parser[In, T],
|
|
f func(T) Parser[In, T2],
|
|
f2 func(T2) Parser[In, 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
|
|
|
|
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()
|
|
|
|
r2, err := f(val)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r2.Consumed()
|
|
failed, _, msg = r2.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val2, next, _ := r2.Succeeded()
|
|
|
|
r3, err := f2(val2)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r3.Consumed()
|
|
failed, _, msg = r3.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val3, next, _ := r3.Succeeded()
|
|
|
|
return Succeed(anyConsumed, val3, next, MessageOK(s.Pos())), nil
|
|
}
|
|
}
|
|
|
|
// Bind3 is equivalent to 3 nested calls to Bind.
|
|
func Bind3[In, Out, T, T2, T3 any](
|
|
p Parser[In, T],
|
|
f func(T) Parser[In, T2],
|
|
f2 func(T2) Parser[In, T3],
|
|
f3 func(T3) Parser[In, 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
|
|
|
|
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()
|
|
|
|
r2, err := f(val)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r2.Consumed()
|
|
failed, _, msg = r2.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val2, next, _ := r2.Succeeded()
|
|
|
|
r3, err := f2(val2)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r3.Consumed()
|
|
failed, _, msg = r3.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val3, next, _ := r3.Succeeded()
|
|
|
|
r4, err := f3(val3)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r4.Consumed()
|
|
failed, _, msg = r4.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val4, next, _ := r4.Succeeded()
|
|
|
|
return Succeed(anyConsumed, val4, next, MessageOK(s.Pos())), nil
|
|
}
|
|
}
|
|
|
|
// Bind4 is equivalent to 4 nested calls to Bind.
|
|
func Bind4[In, Out, T, T2, T3, T4 any](
|
|
p Parser[In, T],
|
|
f func(T) Parser[In, T2],
|
|
f2 func(T2) Parser[In, T3],
|
|
f3 func(T3) Parser[In, T4],
|
|
f4 func(T4) Parser[In, 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
|
|
|
|
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()
|
|
|
|
r2, err := f(val)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r2.Consumed()
|
|
failed, _, msg = r2.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val2, next, _ := r2.Succeeded()
|
|
|
|
r3, err := f2(val2)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r3.Consumed()
|
|
failed, _, msg = r3.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val3, next, _ := r3.Succeeded()
|
|
|
|
r4, err := f3(val3)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r4.Consumed()
|
|
failed, _, msg = r4.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val4, next, _ := r4.Succeeded()
|
|
|
|
r5, err := f4(val4)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r5.Consumed()
|
|
failed, _, msg = r5.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val5, next, _ := r5.Succeeded()
|
|
|
|
return Succeed(anyConsumed, val5, next, MessageOK(s.Pos())), nil
|
|
}
|
|
}
|
|
|
|
// Bind5 is equivalent to 5 nested calls to Bind.
|
|
func Bind5[In, Out, T, T2, T3, T4, T5 any](
|
|
p Parser[In, T],
|
|
f func(T) Parser[In, T2],
|
|
f2 func(T2) Parser[In, T3],
|
|
f3 func(T3) Parser[In, T4],
|
|
f4 func(T4) Parser[In, T5],
|
|
f5 func(T5) Parser[In, 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
|
|
|
|
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()
|
|
|
|
r2, err := f(val)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r2.Consumed()
|
|
failed, _, msg = r2.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val2, next, _ := r2.Succeeded()
|
|
|
|
r3, err := f2(val2)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r3.Consumed()
|
|
failed, _, msg = r3.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val3, next, _ := r3.Succeeded()
|
|
|
|
r4, err := f3(val3)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r4.Consumed()
|
|
failed, _, msg = r4.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val4, next, _ := r4.Succeeded()
|
|
|
|
r5, err := f4(val4)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r5.Consumed()
|
|
failed, _, msg = r5.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val5, next, _ := r5.Succeeded()
|
|
|
|
r6, err := f5(val5)(next)
|
|
if err != nil {
|
|
return Result[In, Out]{}, err
|
|
}
|
|
anyConsumed = anyConsumed || r6.Consumed()
|
|
failed, _, msg = r6.Failed()
|
|
if failed {
|
|
return Fail[In, Out](anyConsumed, msg), nil
|
|
}
|
|
_, _, val6, next, _ := r6.Succeeded()
|
|
|
|
return Succeed(anyConsumed, val6, next, MessageOK(s.Pos())), nil
|
|
}
|
|
}
|