RegisterMethods

parsley.registers$.RegisterMethods
final implicit class RegisterMethods[P, A](p: P)(implicit con: P => Parsley[A])

This class, when in scope, enables the use of combinators directly on parsers that interact with the register system to store and persist results so they can be used multiple times.

Attributes

con

a conversion that allows values convertible to parsers to be used.

p

the value that this class is enabling methods on.

Constructor:

This constructor should not be called manually, it is designed to be used via Scala's implicit resolution.

Source:
registers.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

def fillReg[B](body: Reg[A] => Parsley[B]): Parsley[B]

This combinator fills a fresh register with the result of this parser, this register is provided to the given function, which continues the parse.

This combinator fills a fresh register with the result of this parser, this register is provided to the given function, which continues the parse.

This allows for a more controlled way of creating registers during a parse, without explicitly creating them with Reg.make[A] and using put. These registers 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 register each time.

Attributes

body

a function to generate a parser that can interact with the freshly created register.

Since:

4.0.0

Example:

// this is an efficient implementation for persist.
def persist[B](f: Parsley[A] => Parsley[B]): Parsley[B] = this.fillReg(reg => f(reg.get))
Source:
registers.scala
def persist[B](f: Parsley[A] => Parsley[B]): Parsley[B]

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.

Attributes

f

a function to generate a new parser that can observe the result of this parser many times without reparsing.

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 => ifP(px.map(pred), px, empty))
}
Source:
registers.scala