This class, when in scope, enables the use of combinators directly on parsers that interact with the reference system to store and persist results so they can be used multiple times.
Value parameters
con
a conversion that allows values convertible to parsers to be used.
p
the value that this class is enabling methods on.
Attributes
Constructor
This constructor should not be called manually, it is designed to be used via Scala's implicit resolution.
This combinator fills a fresh reference with the result of this parser, this reference is provided to the given function, which continues the parse.
This combinator fills a fresh reference with the result of this parser, this reference is provided to the given function, which continues the parse.
This allows for a more controlled way of creating references during a parse, without explicitly creating them with Ref.make[A] and using put. These references are intended to be fresh every time they are "created", in other words, a recursive call with a fillReg call inside will modify a different reference each time.
Value parameters
body
a function to generate a parser that can interact with the freshly created reference.
Attributes
Since
4.0.0
Example
// this is an efficient implementation for persist.
def persist[B](f: Parsley[A] => Parsley[B]): Parsley[B] = this.fillRef(reg => f(ref.get))
This combinator allows for the result of this parser to be used multiple times within a function, without needing to reparse or recompute.
This combinator allows for the result of this parser to be used multiple times within a function, without needing to reparse or recompute.
Similar to flatMap, except it is much cheaper to do, at the cost of the restriction that the argument is Parsley[A] and not just A.
Value parameters
f
a function to generate a new parser that can observe the result of this parser many times without reparsing.
Attributes
Since
3.2.0
Example
// this is a reasonable implementation, though direct use of `branch` may be more efficent.
def filter(pred: A => Boolean): Parsley[A] = {
this.persist(px => ifS(px.map(pred), px, empty))
}