implicit final class LazyParsley[P, +A] extends AnyRef
This class exposes the commonly used combinators in Parsley. For a description of why the library is designed in this way, see: the Parsley wiki
- Version
3.0.0
- Alphabetic
- By Inheritance
- LazyParsley
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
Value Members
- 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 receiver but discards its result and then results the valuexinstead- x
The value to be returned after the execution of the receiver
- returns
A new parser which first parses the receiver, then results
x
- def *>[A_ >: A, B](q: => Parsley[B]): Parsley[B]
This is the parser that corresponds to a more optimal version of
lift2(_ => x => x, p, q).This is the parser that corresponds to a more optimal version of
lift2(_ => x => x, p, q). It performs the parse action of both parsers, in order, but discards the result of the receiver.- q
The parser whose result should be returned
- returns
A new parser which first parses
p, thenqand returns the result ofq
- def <*[B](q: => Parsley[B]): Parsley[A]
This is the parser that corresponds to a more optimal version of
lift2(x => _ => x, p, q).This is the parser that corresponds to a more optimal version of
lift2(x => _ => x, p, 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, thenqand 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
pfisParsley[A => B]. Then, given aParsley[A], we can produce aParsley[B]by parsingpfto retrievef: A => B, then parsepxto receivex: Athen returnf(x): B.- px
A parser of type A, where the receiver is A => B
- returns
A new parser which parses
pf, thenpxthen applies the value returned bypxto the function returned bypf
- Note
pure(f) <*> pis 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 useunsafein order to prevent these optimisations.
- def <+:>[B >: A](ps: => Parsley[Seq[B]]): Parsley[Seq[B]]
This parser corresponds to
lift2(_+:_, p, ps). - def <+>[B](q: Parsley[B]): Parsley[Either[A, B]]
This combinator, pronounced "sum", is similar to
<|>, except it allows the types of either side of the combinator to vary by returning their result as part of anEither.This combinator, pronounced "sum", is similar to
<|>, except it allows the types of either side of the combinator to vary by returning their result as part of anEither.- q
The parser to run if the receiver failed without consuming input
- returns
the result of the parser which succeeded, if any
- 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 is the traditional choice operator for parsers.
This is the traditional choice operator for parsers. Following the parsec semantics precisely, this combinator first tries to parse the receiver. If this is successful, no further action is taken. If the receiver failed *without* consuming input, then
qis parsed instead. If the receiver 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, useattempt(this) <|> qto parseqregardless of how the receiver failed.- q
The parser to run if the receiver failed without consuming input
- returns
The value produced by the receiver if it was successful, or if it failed without consuming input, the possible result of parsing q.
- def <~[B](q: => Parsley[B]): Parsley[A]
This is the parser that corresponds to a more optimal version of
(p <~> q).map(_._1).This is the parser that corresponds to a more optimal version of
(p <~> q).map(_._1). 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, thenqand returns the result of thep
- Since
2.4.0
- 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](f: (A) => Parsley[B]): Parsley[B]
This combinator is an alias for
flatMap - 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
2.0.0
- 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
pfis defined over it.Attempts to first filter the parser to ensure that
pfis defined over it. If it is, then the functionpfis mapped over its result. Roughly the same as afilterthen amap.- pf
The partial function
- returns
The result of applying
pfto this parsers value (if possible), or fails
- Since
2.0.0
- 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
predthen 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
predthen 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 receiver 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
predthen 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
predthen 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 receiver if it fails 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 receiver produces a value, the function
fis used to produce a new parser that continues the computation - this new parser is then executed.- f
A function that produces the next parser
- returns
The parser produces from the application of
fon 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 executingpmany times until it fails, combining the results with left-associative application offwith akon the left-most positionA fold for a parser:
p.foldLeft(k)(f)will try executingpmany times until it fails, combining the results with left-associative application offwith akon the left-most position- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
pwithfandk
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 executingpmany times until it fails, combining the results with left-associative application offwith akon the left-most position.A fold for a parser:
p.foldLeft1(k)(f)will try executingpmany times until it fails, combining the results with left-associative application offwith akon the left-most position. It must parsepat least once.- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
pwithfandk
val natural: Parsley[Int] = digit.foldLeft1(0)((x, d) => x * 10 + d.toInt)
- Since
2.1.0
Example: - def foldRight[B](k: B)(f: (A, B) => B): Parsley[B]
A fold for a parser:
p.foldRight(k)(f)will try executingpmany times until it fails, combining the results with right-associative application offwith akat the right-most positionA fold for a parser:
p.foldRight(k)(f)will try executingpmany times until it fails, combining the results with right-associative application offwith akat the right-most position- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
pwithfandk
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 executingpmany times until it fails, combining the results with right-associative application offwith akat the right-most position.A fold for a parser:
p.foldRight1(k)(f)will try executingpmany times until it fails, combining the results with right-associative application offwith akat the right-most position. It must parsepat least once.- k
base case for iteration
- f
combining function
- returns
the result of folding the results of
pwithfandk
p.foldRight1(Nil)(_::_) == some(p) //some is more efficient, however- Since
2.1.0
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 hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- 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 receiver 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 receiver 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
factually only happens once at compile time. In order to preserve the behaviour of impure functions, consider using theunsafemethod 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 executingpmany times until it fails, combining the results with left-associative application ofop.A reduction for a parser:
p.reduceLeft(op)will try executingpmany times until it fails, combining the results with left-associative application ofop. It must parsepat least once.- op
combining function
- returns
the result of reducing the results of
pwithop
- Since
2.3.0
- def reduceLeftOption[B >: A](op: (B, A) => B): Parsley[Option[B]]
A reduction for a parser:
p.reduceLeftOption(op)will try executingpmany times until it fails, combining the results with left-associative application ofop.A reduction for a parser:
p.reduceLeftOption(op)will try executingpmany times until it fails, combining the results with left-associative application ofop. If there is nop, it returnsNone, otherwise it returnsSome(x)wherexis the result of the reduction.- op
combining function
- returns
the result of reducing the results of
pwithopwrapped inSomeorNoneotherwise
- Since
2.3.0
- def reduceRight[B >: A](op: (A, B) => B): Parsley[B]
A reduction for a parser:
p.reduceRight(op)will try executingpmany times until it fails, combining the results with right-associative application ofop.A reduction for a parser:
p.reduceRight(op)will try executingpmany times until it fails, combining the results with right-associative application ofop. It must parsepat least once.- op
combining function
- returns
the result of reducing the results of
pwithop
- Since
2.3.0
- def reduceRightOption[B >: A](op: (A, B) => B): Parsley[Option[B]]
A reduction for a parser:
p.reduceRightOption(op)will try executingpmany times until it fails, combining the results with right-associative application ofop.A reduction for a parser:
p.reduceRightOption(op)will try executingpmany times until it fails, combining the results with right-associative application ofop. If there is nop, it returnsNone, otherwise it returnsSome(x)wherexis the result of the reduction.- op
combining function
- returns
the result of reducing the results of
pwithopwrapped inSomeorNoneotherwise
- Since
2.3.0
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- 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 zip[A_ >: A, B](q: => Parsley[B]): Parsley[(A_, B)]
This combinator is an alias for
<~>This combinator is an alias for
<~>- Since
2.3.0
- def ~>[B](q: => Parsley[B]): Parsley[B]
This is the parser that corresponds to a more optimal version of
(p <~> q).map(_._2).This is the parser that corresponds to a more optimal version of
(p <~> q).map(_._2). It performs the parse action of both parsers, in order, but discards the result of the receiver.- q
The parser whose result should be returned
- returns
A new parser which first parses
p, thenqand returns the result ofq
- Since
2.4.0
Deprecated Value Members
- 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.- Annotations
- @deprecated
- Deprecated
(Since version 3.0.1) This combinator is unfortunately misleading since it is left-associative. It will be removed in 4.0.0, use
attemptwith<|>instead- Note
This combinator should not be used: operators without trailing colons in Scala are left-associative, but this operator was designed to be right associative. This means that where we might intend for
p <|> q <\> rto meanp <|> attempt(q) <|> r, it in fact meansattempt(p <|> q) <|> r. While this will not break a parser, it hinders optimisation and may damage the quality of generated messages.
This is the documentation for Parsley.
Package structure
The parsley package contains the
Parsleyclass, as well as theResult,Success, andFailuretypes. 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.Parsleycontains the bulk of the core "function-style" combinators, as well as the implicit classes which enable the "method-style" combinators.parsley.combinatorcontains many helpful combinators that simplify some common parser patterns.parsley.charactercontains the combinators needed to read characters and strings, as well as combinators to match specific sub-sets of characters.parsley.debugcontains debugging combinators, helpful for identifying faults in parsers.parsley.iocontains extension methods to run parsers with input sourced from IO sources.parsley.exprcontains the following sub modules:parsley.expr.chaincontains combinators used in expression parsingparsley.expr.precedenceis a builder for expression parsers built on a precedence table.parsley.implicitscontains several implicits to add syntactic sugar to the combinators. These are sub-categorised into the following sub modules:parsley.implicits.charactercontains implicits to allow you to use character and string literals as parsers.parsley.implicits.combinatorcontains implicits related to combinators, such as the ability to make any parser into aParsley[Unit]automatically.parsley.implicits.liftenables postfix application of the lift combinator onto a function (or value).parsley.implicits.zippedenables 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.zippedmethod for building tuples out of several combinators.parsley.errorscontains modules to deal with error messages, their refinement and generation.parsley.errors.combinatorprovides combinators that can be used to either produce more detailed errors as well as refine existing errors.parsley.liftcontains 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.registerscontains combinators that interact with the context-sensitive functionality in the form of registers.parsley.tokencontains theLexerclass that provides a host of helpful lexing combinators when provided with the description of a language.parsley.unsafecontains unsafe (and not thread-safe) ways of speeding up the execution of a parser.