Reg

class Reg[A]

This class is used to index registers within the mutable state. Currently, there are only 4 available registers, so use them wisely!

If you need more than four registers but know that they will be used at different times you can rename your register, as long as they point to the same reference. You may find the Parsley[A].cast[B: ClassTag]: Parsley[B] combinator useful to change the type of a Reg[Any].

Since:

2.2.0

Note:

It is undefined behaviour to use a register in multiple different independent parsers. You should be careful to parameterise the registers in shared parsers and allocate fresh ones for each "top-level" parser you will run.

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def get: Parsley[A]

Consumes no input and returns the value stored in this register

Consumes no input and returns the value stored in this register

Returns:

The value stored in register

Since:

3.2.0

def gets[B](f: A => B): Parsley[B]

Consumes no input and returns the value stored in this register after applying a function.

Consumes no input and returns the value stored in this register after applying a function.

Type parameters:
B

The desired result type

Value parameters:
f

The function used to transform the value in this register

Returns:

The value stored in this register applied to f

Since:

3.2.0

def gets[B](pf: Parsley[A => B]): Parsley[B]

Returns the value stored this register after applying a function obtained from given parser.

Returns the value stored this register after applying a function obtained from given parser.

Type parameters:
B

The desired result type

Value parameters:
pf

The parser which provides the function to transform values

Returns:

The value stored in this register applied to f from pf

Since:

3.2.0

Note:

The value is fetched after pf is executed

def local[B](x: A)(p: => Parsley[B]): Parsley[B]

For the duration of parser p the state stored in this register is instead set to x. The change is undone after p has finished.

For the duration of parser p the state stored in this register is instead set to x. The change is undone after p has finished.

Value parameters:
p

The parser to execute with the adjusted state

x

The value to place into this register

Returns:

The parser that performs p with the modified state

Since:

3.2.0

def local[B](p: => Parsley[A])(q: => Parsley[B]): Parsley[B]

For the duration of parser q the state stored in this register is instead set to the return value of p. The change is undone after q has finished.

For the duration of parser q the state stored in this register is instead set to the return value of p. The change is undone after q has finished.

Value parameters:
p

The parser whose return value is placed in this register

q

The parser to execute with the adjusted state

Returns:

The parser that performs q with the modified state

Since:

3.2.0

def local[B](f: A => A)(p: => Parsley[B]): Parsley[B]

For the duration of parser p the state stored in this register is instead modified with f. The change is undone after p has finished.

For the duration of parser p the state stored in this register is instead modified with f. The change is undone after p has finished.

Value parameters:
f

The function used to modify the value in this register

p

The parser to execute with the adjusted state

Returns:

The parser that performs p with the modified state

Since:

3.2.0

def modify(f: A => A): Parsley[Unit]

Modifies the value contained in this register using function f.

Modifies the value contained in this register using function f.

Value parameters:
f

The function used to modify the register

Since:

3.2.0

def modify(pf: => Parsley[A => A]): Parsley[Unit]

Modifies the value contained in this register using function f obtained from executing p.

Modifies the value contained in this register using function f obtained from executing p.

Value parameters:
f

The function used to modify the register

Since:

3.2.0

Note:

The value is modified after pf is executed

def put(x: A): Parsley[Unit]

Consumes no input and places the value x into this register.

Consumes no input and places the value x into this register.

Value parameters:
x

The value to place in the register

Since:

3.2.0

def put(p: => Parsley[A]): Parsley[Unit]

Places the result of running p into this register.

Places the result of running p into this register.

Value parameters:
p

The parser to derive the value from

Since:

3.2.0

def puts[B](p: => Parsley[B], f: B => A): Parsley[Unit]

Places the result of running p into this register.

Places the result of running p into this register.

Value parameters:
f

A function which adapts the result of p so that it can fit in r

p

The parser to derive the value from

Since:

3.0.0

def rollback[B](p: Parsley[B]): Parsley[B]

rollback(reg, p) will perform p, but if it fails without consuming input, any changes to this register will be reverted.

rollback(reg, p) will perform p, but if it fails without consuming input, any changes to this register will be reverted.

Value parameters:
p

The parser to perform

Returns:

The result of the parser p, if any

Since:

3.2.0