implicit final class LazyParsley[P, +A] extends AnyRef
- Alphabetic
- By Inheritance
- LazyParsley
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- def !(msggen: (A) => String): Parsley[Nothing]
Same as
fail
, except allows for a message generated from the result of the failed parser.Same as
fail
, except allows for a message generated from the result of the failed parser. In essence, this is equivalent top >>= (x => fail(msggen(x))
but requires no expensive computations from the use of>>=
.- msggen
The generator function for error message, creating a message based on the result of invokee
- returns
A parser that fails if it succeeds, with the given generator used to produce the error message
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def #>[B](x: B): Parsley[B]
This is the parser that corresponds to
p *> pure(x)
or a more optimal version ofp.map(_ => x)
.This is the parser that corresponds to
p *> pure(x)
or a more optimal version ofp.map(_ => x)
. It performs the parse action of the invokee but discards its result and then results the valuex
instead- x
The value to be returned after the execution of the invokee
- returns
A new parser which first parses the invokee, then results
x
- def *>[A_ >: A, B](q: => Parsley[B]): Parsley[B]
This is the parser that corresponds to a more optimal version of
p.map(_ => x => x) <*> q
.This is the parser that corresponds to a more optimal version of
p.map(_ => x => x) <*> q
. It performs the parse action of both parsers, in order, but discards the result of the invokee.- q
The parser whose result should be returned
- returns
A new parser which first parses
p
, thenq
and returns the result ofq
- def <#>[B](f: (A) => B): Parsley[B]
This combinator is an alias for
map
- def <*[B](q: => Parsley[B]): Parsley[A]
This is the parser that corresponds to a more optimal version of
p.map(x => _ => x) <*> q
.This is the parser that corresponds to a more optimal version of
p.map(x => _ => x) <*> q
. It performs the parse action of both parsers, in order, but discards the result of the second parser.- q
The parser who should be executed but then discarded
- returns
A new parser which first parses
p
, thenq
and returns the result of thep
- def <**>[B](pf: => Parsley[(A) => B]): Parsley[B]
This combinator is defined as
lift2((x, f) => f(x), p, f)
.This combinator is defined as
lift2((x, f) => f(x), p, f)
. It is pure syntactic sugar. - def <*>[B, C](px: => Parsley[B])(implicit ev: <:<[P, Parsley[(B) => C]]): Parsley[C]
This is the Applicative application parser.
This is the Applicative application parser. The type of
pf
isParsley[A => B]
. Then, given aParsley[A]
, we can produce aParsley[B]
by parsingpf
to retrievef: A => B
, then parsepx
to receivex: A
then returnf(x): B
.- px
A parser of type A, where the invokee is A => B
- returns
A new parser which parses
pf
, thenpx
then applies the value returned bypx
to the function returned bypf
- Note
pure(f) <*> p
is subject to the same aggressive optimisations asmap
. When using impure functions the optimiser may decide to cache the result of the function execution, be sure to useunsafe
in order to prevent these optimisations.
- def <+:>[B >: A](ps: => Parsley[Seq[B]]): Parsley[Seq[B]]
This parser corresponds to
lift2(_+:_, p, ps)
. - def </>[B >: A](x: B): Parsley[B]
This combinator is defined as
p <|> pure(x)
.This combinator is defined as
p <|> pure(x)
. It is pure syntactic sugar. - def <::>[B >: A](ps: => Parsley[List[B]]): Parsley[List[B]]
This parser corresponds to
lift2(_::_, p, ps)
. - def <\>[B >: A](q: Parsley[B]): Parsley[B]
This combinator is defined as
attempt(p) <|> q
.This combinator is defined as
attempt(p) <|> q
. It is pure syntactic sugar. - def <|>[B >: A](q: => Parsley[B]): Parsley[B]
This is the traditional Alternative choice operator for parsers.
This is the traditional Alternative choice operator for parsers. Following the parsec semantics precisely, this combinator first tries to parse the invokee. If this is successful, no further action is taken. If the invokee failed *without* consuming input, then
q
is parsed instead. If the invokee did parse input then the whole parser fails. This is done to prevent space leaks and to give good error messages. If this behaviour is not desired, use the<\>
combinator (orattempt(this) <|> q
) to parseq
regardless of how the invokee failed.- q
The parser to run if the invokee failed without consuming input
- returns
The value produced by the invokee if it was successful, or if it failed without consuming input, the possible result of parsing q.
- def <~>[A_ >: A, B](q: => Parsley[B]): Parsley[(A_, B)]
This parser corresponds to
lift2((_, _), p, q)
.This parser corresponds to
lift2((_, _), p, q)
. For now it is sugar, but in future may be more optimal - final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def >>[B](q: Parsley[B]): Parsley[B]
This combinator is an alias for
*>
- def >>=[B](f: (A) => Parsley[B]): Parsley[B]
This combinator is an alias for
flatMap
- def >?>(pred: (A) => Boolean, msggen: (A) => String): Parsley[A]
Alias for guard combinator, taking a dynamic message generator.
- def >?>(pred: (A) => Boolean, msg: String): Parsley[A]
Alias for guard combinator, taking a fixed message.
- def ?(msg: String): Parsley[A]
Sets the expected message for a parser.
Sets the expected message for a parser. If the parser fails then
expected msg
will added to the error - final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def cast[B](implicit arg0: ClassTag[B]): Parsley[B]
This casts the result of the parser into a new type
B
.This casts the result of the parser into a new type
B
. If the value returned by the parser is castable to typeB
, then this cast is performed. Otherwise the parser fails.- B
The type to attempt to cast into
- Since
1.7
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[B](pf: PartialFunction[A, B]): Parsley[B]
Attempts to first filter the parser to ensure that
pf
is defined over it.Attempts to first filter the parser to ensure that
pf
is defined over it. If it is, then the functionpf
is mapped over its result. Roughly the same as afilter
then amap
.- pf
The partial function
- returns
The result of applying
pf
to this parsers value (if possible), or fails
- Since
1.7
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def filter(pred: (A) => Boolean): Parsley[A]
Filter the value of a parser; if the value returned by the parser matches the predicate
pred
then the filter succeeded, otherwise the parser fails with an empty errorFilter the value of a parser; if the value returned by the parser matches the predicate
pred
then the filter succeeded, otherwise the parser fails with an empty error- pred
The predicate that is tested against the parser result
- returns
The result of the invokee if it passes the predicate
- def filterNot(pred: (A) => Boolean): Parsley[A]
Filter the value of a parser; if the value returned by the parser does not match the predicate
pred
then the filter succeeded, otherwise the parser fails with an empty errorFilter the value of a parser; if the value returned by the parser does not match the predicate
pred
then the filter succeeded, otherwise the parser fails with an empty error- pred
The predicate that is tested against the parser result
- returns
The result of the invokee if it passes the predicate
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatMap[B](f: (A) => Parsley[B]): Parsley[B]
This is the traditional Monadic binding operator for parsers.
This is the traditional Monadic binding operator for parsers. When the invokee produces a value, the function
f
is used to produce a new parser that continued the computation.- f
A function that produces the next parser
- returns
The parser produces from the application of
f
on the result of the last parser
- Note
There is significant overhead for using flatMap; if possible try to write parsers in an applicative style otherwise try and use the intrinsic parsers provided to replace the flatMap.
- def flatten[B](implicit ev: <:<[A, Parsley[B]]): Parsley[B]
This combinator is an alias for
flatMap(identity)
. - def foldLeft[B](k: B)(f: (B, A) => B): Parsley[B]
A fold for a parser:
p.foldLeft(k)(f)
will try executingp
many times until it fails, combining the results with left-associative application off
with ak
on the left-most positionA fold for a parser:
p.foldLeft(k)(f)
will try executingp
many times until it fails, combining the results with left-associative application off
with ak
on the left-most position- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
p
withf
andk
val natural: Parsley[Int] = digit.foldLeft(0)((x, d) => x * 10 + d.toInt)
Example: - def foldLeft1[B](k: B)(f: (B, A) => B): Parsley[B]
A fold for a parser:
p.foldLeft1(k)(f)
will try executingp
many times until it fails, combining the results with left-associative application off
with ak
on the left-most position.A fold for a parser:
p.foldLeft1(k)(f)
will try executingp
many times until it fails, combining the results with left-associative application off
with ak
on the left-most position. It must parsep
at least once.- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
p
withf
andk
val natural: Parsley[Int] = digit.foldLeft1(0)((x, d) => x * 10 + d.toInt)
Example: - def foldRight[B](k: B)(f: (A, B) => B): Parsley[B]
A fold for a parser:
p.foldRight(k)(f)
will try executingp
many times until it fails, combining the results with right-associative application off
with ak
at the right-most positionA fold for a parser:
p.foldRight(k)(f)
will try executingp
many times until it fails, combining the results with right-associative application off
with ak
at the right-most position- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
p
withf
andk
p.foldRight(Nil)(_::_) == many(p) //many is more efficient, however
Example: - def foldRight1[B](k: B)(f: (A, B) => B): Parsley[B]
A fold for a parser:
p.foldRight1(k)(f)
will try executingp
many times until it fails, combining the results with right-associative application off
with ak
at the right-most position.A fold for a parser:
p.foldRight1(k)(f)
will try executingp
many times until it fails, combining the results with right-associative application off
with ak
at the right-most position. It must parsep
at least once.- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
p
withf
andk
p.foldRight1(Nil)(_::_) == some(p) //some is more efficient, however
Example: - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def getOrElse[B >: A](x: B): Parsley[B]
This combinator is an alias for
</>
. - def guard(pred: (A) => Boolean, msggen: (A) => String): Parsley[A]
Similar to
filter
, except the error message desired is also provided.Similar to
filter
, except the error message desired is also provided. This allows you to name the message itself. The message is provided as a generator, which allows the user to avoid otherwise expensive computation.- pred
The predicate that is tested against the parser result
- msggen
Generator function for error message, generating a message based on the result of the parser
- returns
The result of the invokee if it passes the predicate
- def guard(pred: (A) => Boolean, msg: String): Parsley[A]
Similar to
filter
, except the error message desired is also provided.Similar to
filter
, except the error message desired is also provided. This allows you to name the message itself.- pred
The predicate that is tested against the parser result
- msg
The message used for the error if the input failed the check
- returns
The result of the invokee if it passes the predicate
- def guardNot(pred: (A) => Boolean, msggen: (A) => String): Parsley[A]
Similar to
filterNot
, except the error message desired is also provided.Similar to
filterNot
, except the error message desired is also provided. This allows you to name the message itself. The message is provided as a generator, which allows the user to avoid otherwise expensive computation.- pred
The predicate that is tested against the parser result
- msggen
Generator function for error message, generating a message based on the result of the parser
- returns
The result of the invokee if it passes the predicate
- def guardNot(pred: (A) => Boolean, msg: String): Parsley[A]
Similar to
filterNot
, except the error message desired is also provided.Similar to
filterNot
, except the error message desired is also provided. This allows you to name the message itself.- pred
The predicate that is tested against the parser result
- msg
The message used for the error if the input failed the check
- returns
The result of the invokee if it passes the predicate
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hide: Parsley[A]
Hides the "expected" error message for a parser.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[B](f: (A) => B): Parsley[B]
This is the functorial map operation for parsers.
This is the functorial map operation for parsers. When the invokee produces a value, this value is fed through the function
f
.- f
The mutator to apply to the result of previous parse
- returns
A new parser which parses the same input as the invokee but mutated by function
f
- Note
This is subject to aggressive optimisations assuming purity; the compiler is permitted to optimise such that the application of
f
actually only happens once at compile time. In order to preserve the behaviour of impure functions, consider using theunsafe
method before map;p.unsafe.map(f)
.
- 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 orElse[B >: A](q: => Parsley[B]): Parsley[B]
This combinator is an alias for
<|>
. - def reduceLeft[B >: A](op: (B, A) => B): Parsley[B]
A reduction for a parser:
p.reduceLeft(op)
will try executingp
many times until it fails, combining the results with left-associative application ofop
.A reduction for a parser:
p.reduceLeft(op)
will try executingp
many times until it fails, combining the results with left-associative application ofop
. It must parsep
at least once.- op
combining function
- returns
the result of reducing the results of
p
withop
- def reduceLeftOption[B >: A](op: (B, A) => B): Parsley[Option[B]]
A reduction for a parser:
p.reduceLeft(op)
will try executingp
many times until it fails, combining the results with left-associative application ofop
.A reduction for a parser:
p.reduceLeft(op)
will try executingp
many times until it fails, combining the results with left-associative application ofop
. If there is nop
, it returnsNone
, otherwise it returnsSome(x)
wherex
is the result of the reduction.- op
combining function
- returns
the result of reducing the results of
p
withop
wrapped inSome
orNone
otherwise
- def reduceRight[B >: A](op: (A, B) => B): Parsley[B]
A reduction for a parser:
p.reduceRight(op)
will try executingp
many times until it fails, combining the results with right-associative application ofop
.A reduction for a parser:
p.reduceRight(op)
will try executingp
many times until it fails, combining the results with right-associative application ofop
. It must parsep
at least once.- op
combining function
- returns
the result of reducing the results of
p
withop
- def reduceRightOption[B >: A](op: (A, B) => B): Parsley[Option[B]]
A reduction for a parser:
p.reduceRight(op)
will try executingp
many times until it fails, combining the results with right-associative application ofop
.A reduction for a parser:
p.reduceRight(op)
will try executingp
many times until it fails, combining the results with right-associative application ofop
. If there is nop
, it returnsNone
, otherwise it returnsSome(x)
wherex
is the result of the reduction.- op
combining function
- returns
the result of reducing the results of
p
withop
wrapped inSome
orNone
otherwise
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unexpected(msggen: (A) => String): Parsley[Nothing]
Same as
unexpected
, except allows for a message generated from the result of the failed parser.Same as
unexpected
, except allows for a message generated from the result of the failed parser. In essence, this is equivalent top >>= (x => unexpected(x))
but requires no expensive computations from the use of>>=
- msggen
The generator function for error message, creating a message based on the result of invokee
- returns
A parser that fails if it succeeds, with the given generator used to produce an unexpected message
- 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()
- def withFilter(pred: (A) => Boolean): Parsley[A]
- def zip[A_ >: A, B](q: => Parsley[B]): Parsley[(A_, B)]
This combinator is an alias for
<~>
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, as well as the implicit classes which enable the "method-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.implicits
contains several implicits to add syntactic sugar to the combinators, such as being able to use character and string literals directly as parsers, as well as enabling lifting of functions to work on parsers.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.registers
contains combinators that interact with the context-sensitive functionality in the form of registers.parsley.token
contains theLexer
class that provides a host of helpful lexing combinators when provided with the description of a language.parsley.unsafe
contains unsafe (and not thread-safe) ways of speeding up the execution of a parser.In addition to the modules and packages outlined above, this version of Parsley (up to version 3.0), also includes the so-called
old-style
API, which is deprecated (see the Parsley wiki for a discussion of these differences). You should use the modules described above, and avoid the following:parsley.BitGen
parsley.Char
parsley.CharSet
parsley.Combinator
parsley.ExpressionParser
parsley.Impl
parsley.Implicits
parsley.LanguageDef
parsley.NotRequired
parsley.Parser
parsley.Predicate
parsley.Reg
parsley.TokenParser