Added Lazy combinator
This commit is contained in:
parent
82ed6b5546
commit
035fa7da14
@ -403,3 +403,12 @@ func Repeat[In, Out any](minCount int, p Parser[In, Out]) Parser[In, []Out] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lazy delays creating a parser from p until the parser is called.
|
||||||
|
// This is useful for preventing recursive function calls in the
|
||||||
|
// definition of a recursive parser.
|
||||||
|
func Lazy[In, Out any](p func() Parser[In, Out]) Parser[In, Out] {
|
||||||
|
return func(s State[In]) (Result[In, Out], error) {
|
||||||
|
return p()(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user