class Ref[A] extends AnyRef
This class is used to index references within the mutable state.
- Source
- state.scala
- Note
it is undefined behaviour to use a reference in multiple different independent parsers. You should be careful to parameterise the references in shared parsers and allocate fresh ones for each "top-level" parser you will run.
- Grouped
- Alphabetic
- By Inheritance
- Ref
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def get: Parsley[A]
This combinator injects the value stored in this reference into a parser.
This combinator injects the value stored in this reference into a parser.
Allows for the value stored in this reference to be purely injected into the parsing context. No input is consumed in this process, and it cannot fail.
- returns
a parser that returns the value stored in this reference.
Get-Get Law:
r.get *> r.get == r.get r.get <~> r.get == r.get.map(x => (x, x))
- Since
3.2.0
Example: - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def gets[B](pf: Parsley[(A) => B]): Parsley[B]
This combinator injects the value stored in this reference into a parser after applying a function obtained from a parser to it.
This combinator injects the value stored in this reference into a parser after applying a function obtained from a parser to it.
First,
pf
is parsed, producing the functionf
on success. Then, the value stored in this referencex
is applied to the functionf
. The combinator returnsf(x)
. Onlypf
is allowed to consume input. Ifpf
fails, the combinator fails, otherwise it will succeed.- B
the desired result type.
- pf
the parser that produces the function used to transform the value in this reference.
- returns
the value stored in this reference applied to a function generated from
pf
.
- Since
3.2.0
- def gets[B](f: (A) => B): Parsley[B]
This combinator injects the value stored in this reference into a parser after applying a function to it.
This combinator injects the value stored in this reference into a parser after applying a function to it.
Allows for the value stored in this reference to be purely injected into the parsing context but the function
f
is applied first. No input is consumed in this process, and it cannot fail.- B
the desired result type.
- f
the function used to transform the value in this reference.
- returns
the value stored in this reference applied to
f
.
- Since
3.2.0
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def rollback[B](p: Parsley[B]): Parsley[B]
This combinator rolls-back any changes to this reference made by a given parser if it fails.
This combinator rolls-back any changes to this reference made by a given parser if it fails.
First get the current value in this reference
xold
. Then parsep
, if it succeeds, producingy
, theny
is returned and this reference retains its value post-p
. Otherwise, ifp
failed without consuming input,xold
is placed back into this reference and this combinator fails.This can be used in conjunction with local to make an almost unconditional state restore:
// `r`'s state is always rolled back after `p` unless it fails having consumed input. r.rollback(r.local(x)(p))
- p
the parser to perform.
- returns
the result of the parser
p
, if any.
- Since
3.2.0
- def set(p: Parsley[A]): Parsley[Unit]
This combinator stores a new value into this reference.
This combinator stores a new value into this reference.
First, parse
p
to obtain its resultx
. Then storex
into this reference without any further effect. Ifp
fails this combinator fails.- p
the parser that produces the value to store in the reference.
Get-Set Law:
r.set(r.get) == unit
, Set-Set Law:
// only when `q` does not inspect the value of `r`! r.set(p) *> r.set(q) == p *> r.set(q)
- Since
4.5.0
Examples: - def set(x: A): Parsley[Unit]
This combinator stores a new value into this reference.
This combinator stores a new value into this reference.
Without any other effect, the value
x
will be placed into this reference.- x
the value to place in the reference.
Set-Get Law:
r.set(x) *> r.get == r.set(x).as(x)
, Set-Set Law:
r.set(x) *> r.set(y) == r.set(y)
- Since
4.5.0
Examples: - def setDuring[B](p: Parsley[A])(q: => Parsley[B]): Parsley[B]
This combinator changed the value stored in this reference for the duration of a given parser, resetting it afterwards.
This combinator changed the value stored in this reference for the duration of a given parser, resetting it afterwards.
First get the current value in this reference
xold
, then parsep
to get the resultx
, placing it into this reference without any further effect. Then, parseq
, producing resulty
on success. Finally, putxold
back into this reference and returny
. Ifp
orq
fail, the whole combinator fails and the state is not restored.- p
the parser whose return value is placed in this reference.
- q
the parser to execute with the adjusted state.
- returns
the parser that performs
q
with the modified state.
- Since
4.5.0
- def setDuring[B](x: A)(p: Parsley[B]): Parsley[B]
This combinator changed the value stored in this reference for the duration of a given parser, resetting it afterwards.
This combinator changed the value stored in this reference for the duration of a given parser, resetting it afterwards.
First get the current value in this reference
xold
, then placex
into this reference without any further effect. Then, parsep
, producing resulty
on success. Finally, putxold
back into this reference and returny
. Ifp
fails, the whole combinator fails and the state is not restored.- x
the value to place into this reference.
- p
the parser to execute with the adjusted state.
- returns
the parser that performs
p
with the modified statex
.
Set-Set Law:
r.set(x) *> r.setDuring(y)(p) == r.set(y) *> p <* r.set(x)
- Since
4.5.0
Example: - def sets[B](p: Parsley[B], f: (B) => A): Parsley[Unit]
This combinator stores a new value into this reference.
This combinator stores a new value into this reference.
First, parse
p
to obtain its resultx
. Then storef(x)
into this reference without any further effect. Ifp
fails this combinator fails.Equivalent to
this.set(p.map(f))
- p
the parser that produces the value to store in the reference.
- f
a function which adapts the result of
p
so that it can fit into this reference.
- Since
4.5.0
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def update(pf: Parsley[(A) => A]): Parsley[Unit]
This combinator modifies the value stored in this reference with a function.
This combinator modifies the value stored in this reference with a function.
First, parse
pf
to obtain its resultf
. Then get the value stored in this reference,x
, and put backf(x)
. Ifp
fails this combinator fails.Equivalent to
this.set(this.gets(pf))
- pf
the parser that produces the function used to transform the value in this reference.
- Since
4.5.0
- def update(f: (A) => A): Parsley[Unit]
This combinator modifies the value stored in this reference with a function.
This combinator modifies the value stored in this reference with a function.
Without any other effect, get the value stored in this reference,
x
, and put backf(x)
.Equivalent to
this.set(this.gets(f))
- f
the function used to modify this reference's value.
- Since
4.5.0
- def updateDuring[B](f: (A) => A)(p: Parsley[B]): Parsley[B]
This combinator changed the value stored in this reference for the duration of a given parser, resetting it afterwards.
This combinator changed the value stored in this reference for the duration of a given parser, resetting it afterwards.
First get the current value in this reference
xold
, then placef(xold)
into this reference without any further effect. Then, parsep
, producing resulty
on success. Finally, putxold
back into this reference and returny
. Ifp
fails, the whole combinator fails and the state is not restored.- f
the function used to modify the value in this reference.
- p
the parser to execute with the adjusted state.
- returns
the parser that performs
p
with the modified state.
Set-Set Law and Set-Get Law:
r.set(x) *> r.updateDuring(f)(p) == r.set(f(x)) *> p <* r.set(x)
- Since
4.5.0
Example: - final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Getters
These combinators allow for the retrieval of the stateful value of a reference, and injecting it into the parsing context. Does not modify the contents of the reference itself.
Setters
These combinators directly update the value contained within a reference. This new value can be provided directly or sourced from a parser.
Modification
These combinators modify the value stored within a reference by using a function. The function used can be provided directly or sourced from a parser.
Local Modification
These combinators allow for some form of local stateful modification. This means that any changes to the reference may be reverted after the execution of the parser: this may be on the parsers success, but it could also involve the parsers failure.
This is the documentation for Parsley.
Package structure
The parsley package contains the
Parsley
class, as well as theResult
,Success
, andFailure
types. In addition to these, it also contains the following packages and "modules" (a module is defined as being an object which mocks a package):parsley.Parsley
contains the bulk of the core "function-style" combinators.parsley.combinator
contains many helpful combinators that simplify some common parser patterns.parsley.character
contains the combinators needed to read characters and strings, as well as combinators to match specific sub-sets of characters.parsley.debug
contains debugging combinators, helpful for identifying faults in parsers.parsley.expr
contains the following sub modules:parsley.expr.chain
contains combinators used in expression parsingparsley.expr.precedence
is a builder for expression parsers built on a precedence table.parsley.expr.infix
contains combinators used in expression parsing, but with more permissive types than their equivalents inchain
.parsley.expr.mixed
contains combinators that can be used for expression parsing, but where different fixities may be mixed on the same level: this is rare in practice.parsley.syntax
contains several implicits to add syntactic sugar to the combinators. These are sub-categorised into the following sub modules:parsley.syntax.character
contains implicits to allow you to use character and string literals as parsers.parsley.syntax.lift
enables postfix application of the lift combinator onto a function (or value).parsley.syntax.zipped
enables boths a reversed form of lift where the function appears on the right and is applied on a tuple (useful when type inference has failed) as well as a.zipped
method for building tuples out of several combinators.parsley.syntax.extension
contains syntactic sugar combinators exposed as implicit classes.parsley.errors
contains modules to deal with error messages, their refinement and generation.parsley.errors.combinator
provides combinators that can be used to either produce more detailed errors as well as refine existing errors.parsley.errors.tokenextractors
provides mixins for common token extraction strategies during error message generation: these can be used to avoid implementingunexpectedToken
in theErrorBuilder
.parsley.lift
contains functions which lift functions that work on regular types to those which now combine the results of parsers returning those same types. these are ubiquitous.parsley.ap
contains functions which allow for the application of a parser returning a function to several parsers returning each of the argument types.parsley.state
contains combinators that interact with the context-sensitive functionality in the form of state.parsley.token
contains theLexer
class that provides a host of helpful lexing combinators when provided with the description of a language.parsley.position
contains parsers for extracting position information.parsley.generic
contains some basic implementations of the Parser Bridge pattern (see Design Patterns for Parser Combinators in Scala, or the parsley wiki): these can be used before more specialised generic bridge traits can be constructed.