registers

object registers

This module contains all the functionality and operations for using and manipulating registers.

Since:

2.2.0

class Object
trait Matchable
class Any

Type members

Classlikes

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!

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
object Reg
Companion:
class
final implicit class RegisterMethods[P, A](p: => P)(implicit con: P => Parsley[A])

Value members

Deprecated methods

@deprecated("This combinator will be removed in 4.0.0, use r.get instead", "3.2.0")
def get[S](r: Reg[S]): Parsley[S]

Consumes no input and returns the value stored in one of the parser registers.

Consumes no input and returns the value stored in one of the parser registers.

Type parameters:
S

The type of the value in register r (this will result in a runtime type-check)

Value parameters:
r

The index of the register to collect from

Returns:

The value stored in register r of type S

Since:

2.2.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.gets(f) instead", "3.2.0")
def gets[S, A](r: Reg[S], f: S => A): Parsley[A]

Consumes no input and returns the value stored in one of the parser registers after applying a function.

Consumes no input and returns the value stored in one of the parser registers after applying a function.

Type parameters:
A

The desired result type

S

The type of the value in register r (this will result in a runtime type-check)

Value parameters:
f

The function used to transform the value in the register

r

The index of the register to collect from

Returns:

The value stored in register r applied to f

Since:

2.2.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.gets(pf) instead", "3.2.0")
def gets[S, A](r: Reg[S], pf: Parsley[S => A]): Parsley[A]

Returns the value stored in one of the parser registers after applying a function obtained from given parser.

Returns the value stored in one of the parser registers after applying a function obtained from given parser.

Type parameters:
A

The desired result type

S

The type of the value in register r (this will result in a runtime type-check)

Value parameters:
pf

The parser which provides the function to transform values

r

The index of the register to collect from

Returns:

The value stored in register r applied to f from pf

Since:

2.2.0

Note:

The value is fetched after pf is executed

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.local(x)(p) instead", "3.2.0")
def local[R, A](r: Reg[R], x: R, p: => Parsley[A]): Parsley[A]

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

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

Value parameters:
p

The parser to execute with the adjusted state

r

The index of the register to modify

x

The value to place in the register r

Returns:

The parser that performs p with the modified state

Since:

2.2.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.local(p)(q) instead", "3.2.0")
def local[R, A](r: Reg[R], p: => Parsley[R], q: => Parsley[A]): Parsley[A]

For the duration of parser q the state stored in register r 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 register r 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 register r

q

The parser to execute with the adjusted state

r

The index of the register to modify

Returns:

The parser that performs q with the modified state

Since:

2.2.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.local(f)(p) instead", "3.2.0")
def local[R, A](r: Reg[R], f: R => R, p: => Parsley[A]): Parsley[A]

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

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

Value parameters:
f

The function used to modify the value in register r

p

The parser to execute with the adjusted state

r

The index of the register to modify

Returns:

The parser that performs p with the modified state

Since:

2.2.0

Note:

There are only 4 registers at present.

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.modify(f) instead", "3.2.0")
def modify[S](r: Reg[S], f: S => S): Parsley[Unit]

Modifies the value contained in register r using function f.

Modifies the value contained in register r using function f.

Type parameters:
S

The type of value currently assumed to be in the register

Value parameters:
f

The function used to modify the register

r

The index of the register to modify

Since:

2.2.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.put(x) instead", "3.2.0")
def put[S](r: Reg[S], x: S): Parsley[Unit]

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

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

Value parameters:
r

The index of the register to place the value in

x

The value to place in the register

Since:

2.2.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.put(p) instead", "3.2.0")
def put[S](r: Reg[S], p: => Parsley[S]): Parsley[Unit]

Places the result of running p into register r.

Places the result of running p into register r.

Value parameters:
p

The parser to derive the value from

r

The index of the register to place the value in

Since:

2.2.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use r.puts(p, f) instead", "3.2.0")
def puts[A, S](r: Reg[S], p: => Parsley[A], f: A => S): Parsley[Unit]

Places the result of running p into register r.

Places the result of running p into register r.

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

r

The index of the register to place the value in

Since:

3.0.0

Deprecated
@deprecated("This combinator will be removed in 4.0.0, use reg.rollback(p) instead", "3.2.0")
def rollback[A, B](reg: Reg[A], p: Parsley[B]): Parsley[B]

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

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

Value parameters:
p

The parser to perform

reg

The register to rollback on failure of p

Returns:

The result of the parser p, if any

Since:

2.2.0

Deprecated

Implicits

Implicits

final implicit def RegisterMethods[P, A](p: => P)(implicit con: P => Parsley[A]): RegisterMethods[P, A]