object Parsley
This object contains the core "function-style" combinators as well as the implicit classes which provide the "method-style" combinators. All parsers will likely require something from within!
- Alphabetic
- By Inheritance
- Parsley
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- implicit final class LazyChooseParsley[P, +A] extends AnyRef
- implicit final class LazyMapParsley[A, +B] extends AnyRef
- implicit final class LazyParsley[P, +A] extends AnyRef
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 attempt[A](p: => Parsley[A]): Parsley[A]
Given a parser
p
, attempts to parsep
.Given a parser
p
, attempts to parsep
. If the parser fails, thenattempt
ensures that no input was consumed. This allows for backtracking capabilities, disabling the implicit cut semantics offered by<|>
.- p
The parser to run
- returns
The result of
p
, or ifp
failed ensures the parser state was as it was on entry.
- def branch[A, B, C](b: => Parsley[Either[A, B]], p: => Parsley[(A) => C], q: => Parsley[(B) => C]): Parsley[C]
This is one of the core operations of a selective functor.
This is one of the core operations of a selective functor. It will conditionally execute one of
p
andq
depending on the result fromb
. This can be used to implement conditional choice within a parser without relying on expensive monadic operations.- b
The first parser to parse
- p
If
b
returnsLeft
then this parser is executed with the result- q
If
b
returnsRight
then this parser is executed with the result- returns
Either the result from
p
orq
depending onb
.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- val col: Parsley[Int]
This parser consumes no input and returns the current column number reached in the input stream
This parser consumes no input and returns the current column number reached in the input stream
- returns
The column number the parser is currently at
- val empty: Parsley[Nothing]
The
empty
parser consumes no input and fails softly (that is to say, no error message) - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def fail(msg: String): Parsley[Nothing]
The
fail(msg)
parser consumes no input and fails withmsg
as the error message - def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def join[A](p: => Parsley[Parsley[A]]): Parsley[A]
This function is an alias for
_.flatten
.This function is an alias for
_.flatten
. Provides namesake to Haskell. - def label[A](p: Parsley[A], msg: String): Parsley[A]
Alias for
p ? msg
. - val line: Parsley[Int]
This parser consumes no input and returns the current line number reached in the input stream
This parser consumes no input and returns the current line number reached in the input stream
- returns
The line number the parser is currently at
- def lookAhead[A](p: => Parsley[A]): Parsley[A]
Parses
p
without consuming any input.Parses
p
without consuming any input. Ifp
fails and consumes input then so doeslookAhead(p)
. Combine withattempt
if this is undesirable.- p
The parser to look ahead at
- returns
The result of the lookahead
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def notFollowedBy(p: Parsley[_]): Parsley[Unit]
notFollowedBy(p)
only succeeds when parserp
fails.notFollowedBy(p)
only succeeds when parserp
fails. This parser does not consume any input. This parser can be used to implement the 'longest match' rule. For example, when recognising keywords, we want to make sure that a keyword is not followed by a legal identifier character, in which case the keyword is actually an identifier. We can program this behaviour as follows:attempt(kw *> notFollowedBy(alphaNum))
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- val pos: Parsley[(Int, Int)]
This parser consumes no input and returns the current position reached in the input stream
This parser consumes no input and returns the current position reached in the input stream
- returns
Tuple of line and column number that the parser has reached
- def pure[A](x: A): Parsley[A]
This is the traditional applicative pure function (or monadic return) for parsers.
This is the traditional applicative pure function (or monadic return) for parsers. It consumes no input and does not influence the state of the parser, but does return the value provided. Useful to inject pure values into the parsing process.
- x
The value to be returned from the parser
- returns
A parser which consumes nothing and returns
x
- def select[A, B](p: => Parsley[Either[A, B]], q: => Parsley[(A) => B]): Parsley[B]
This is one of the core operations of a selective functor.
This is one of the core operations of a selective functor. It will conditionally execute one of
q
depending on whether or notp
returns aLeft
. It can be used to implementbranch
and other selective operations, however it is more efficiently implemented withbranch
itself.- p
The first parser to parse
- q
If
p
returnsLeft
then this parser is executed with the result- returns
Either the result from
p
if it returnedLeft
or the result ofq
applied to theRight
fromp
- def sequence[A](ps: Parsley[A]*): Parsley[List[A]]
Evaluate each of the parsers in
ps
sequentially from left to right, collecting the results.Evaluate each of the parsers in
ps
sequentially from left to right, collecting the results.- ps
Parsers to be sequenced
- returns
The list containing results, one from each parser, in order
- def skip(ps: Parsley[_]*): Parsley[Unit]
Evaluate each of the parsers in
ps
sequentially from left to right, ignoring the results.Evaluate each of the parsers in
ps
sequentially from left to right, ignoring the results.- ps
Parsers to be performed
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def traverse[A, B](f: (A) => Parsley[B], xs: A*): Parsley[List[B]]
Like
sequence
but produces a list of parsers to sequence by applying the functionf
to each element inxs
.Like
sequence
but produces a list of parsers to sequence by applying the functionf
to each element inxs
.- f
The function to map on each element of
xs
to produce parsers- xs
Values to generate parsers from
- returns
The list containing results formed by executing each parser generated from
xs
andf
in sequence
- def unexpected(msg: String): Parsley[Nothing]
The
unexpected(msg)
parser consumes no input and fails withmsg
as an unexpected error - val unit: Parsley[Unit]
Returns
()
.Returns
()
. Defined aspure(())
but aliased for sugar - def void(p: Parsley[_]): Parsley[Unit]
converts a parser's result to ()
- 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()
Deprecated Value Members
- def get[S](r: registers.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.
- S
The type of the value in register
r
(this will result in a runtime type-check)- r
The index of the register to collect from
- returns
The value stored in register
r
of typeS
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.get
instead- Note
There are only 4 registers at present.
- def gets[S, A](r: registers.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.
- S
The type of the value in register
r
(this will result in a runtime type-check)- A
The desired result type
- r
The index of the register to collect from
- pf
The parser which provides the function to transform values
- returns
The value stored in register
r
applied tof
frompf
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.gets
instead- Note
There are only 4 registers at present. The value is fetched before
pf
is executed
- def gets[S, A](r: registers.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.
- S
The type of the value in register
r
(this will result in a runtime type-check)- A
The desired result type
- r
The index of the register to collect from
- f
The function used to transform the value in the register
- returns
The value stored in register
r
applied tof
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.gets
instead- Note
There are only 4 registers at present.
- def lift1[A, B](f: (A) => B, p: => Parsley[A]): Parsley[B]
lift1(f, p)
is an alias forp.map(f)
.lift1(f, p)
is an alias forp.map(f)
. It is provided for symmetry with lift2 and lift3- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.lift.lift1
instead
- def lift2[A, B, C](f: (A, B) => C, p: => Parsley[A], q: => Parsley[B]): Parsley[C]
Traditionally,
lift2
is defined aslift2(f, p, q) = p.map(f) <*> q
.Traditionally,
lift2
is defined aslift2(f, p, q) = p.map(f) <*> q
. However,f
is actually uncurried, so it's actually more exactly defined as; readp
and then readq
then provide their results to functionf
. This is designed to bring higher performance to any curried operations that are not themselves intrinsic.- f
The function to apply to the results of
p
andq
- p
The first parser to parse
- q
The second parser to parse
- returns
f(x, y)
wherex
is the result ofp
andy
is the result ofq
.
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.lift.lift2
instead
- def lift3[A, B, C, D](f: (A, B, C) => D, p: => Parsley[A], q: => Parsley[B], r: => Parsley[C]): Parsley[D]
Traditionally,
lift2
is defined aslift3(f, p, q, r) = p.map(f) <*> q <*> r
.Traditionally,
lift2
is defined aslift3(f, p, q, r) = p.map(f) <*> q <*> r
. However,f
is actually uncurried, so it's actually more exactly defined as; readp
and then readq
and then read 'r' then provide their results to functionf
. This is designed to bring higher performance to any curried operations that are not themselves intrinsic.- f
The function to apply to the results of
p
andq
- p
The first parser to parse
- q
The second parser to parse
- r
The third parser to parse
- returns
f(x, y, z)
wherex
is the result ofp
,y
is the result ofq
andz
is the result ofr
.
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.lift.lift3
instead
- def local[R, A](r: registers.Reg[R], f: (R) => R, p: => Parsley[A]): Parsley[A]
For the duration of parser
p
the state stored in registerr
is instead modified withf
.For the duration of parser
p
the state stored in registerr
is instead modified withf
. The change is undone afterp
has finished.- r
The index of the register to modify
- f
The function used to modify the value in register
r
- p
The parser to execute with the adjusted state
- returns
The parser that performs
p
with the modified state
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.local
instead- Note
There are only 4 registers at present.
- def local[R, A](r: registers.Reg[R], p: => Parsley[R], q: => Parsley[A]): Parsley[A]
For the duration of parser
q
the state stored in registerr
is instead set to the return value ofp
.For the duration of parser
q
the state stored in registerr
is instead set to the return value ofp
. The change is undone afterq
has finished.- r
The index of the register to modify
- p
The parser whose return value is placed in register
r
- q
The parser to execute with the adjusted state
- returns
The parser that performs
q
with the modified state
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.local
instead- Note
There are only 4 registers at present.
- def local[R, A](r: registers.Reg[R], x: R, p: => Parsley[A]): Parsley[A]
For the duration of parser
p
the state stored in registerr
is instead set tox
.For the duration of parser
p
the state stored in registerr
is instead set tox
. The change is undone afterp
has finished.- r
The index of the register to modify
- x
The value to place in the register
r
- p
The parser to execute with the adjusted state
- returns
The parser that performs
p
with the modified state
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.local
instead- Note
There are only 4 registers at present.
- def many[A](p: => Parsley[A]): Parsley[List[A]]
many(p)
executes the parserp
zero or more times.many(p)
executes the parserp
zero or more times. Returns a list of the returned values ofp
.- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.combinator.many
instead
- def modify[S](r: registers.Reg[S], f: (S) => S): Parsley[Unit]
Modifies the value contained in register
r
using functionf
.Modifies the value contained in register
r
using functionf
.- S
The type of value currently assumed to be in the register
- r
The index of the register to modify
- f
The function used to modify the register
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.modify
instead- Note
There are only 4 registers at present.
- def put[S](r: registers.Reg[S], p: => Parsley[S]): Parsley[Unit]
Places the result of running
p
into registerr
.Places the result of running
p
into registerr
.- r
The index of the register to place the value in
- p
The parser to derive the value from
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.put
instead- Note
There are only 4 registers at present.
- def put[S](r: registers.Reg[S], x: S): Parsley[Unit]
Consumes no input and places the value
x
into registerr
.Consumes no input and places the value
x
into registerr
.- r
The index of the register to place the value in
- x
The value to place in the register
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.put
instead- Note
There are only 4 registers at present.
- def rollback[A, B](reg: registers.Reg[A], p: Parsley[B]): Parsley[B]
rollback(reg, p)
will performp
, but if it fails without consuming input, any changes to the registerreg
will be reverted.rollback(reg, p)
will performp
, but if it fails without consuming input, any changes to the registerreg
will be reverted.- reg
The register to rollback on failure of
p
- p
The parser to perform
- returns
The result of the parser
p
, if any
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.registers.rollback
instead- Since
2.0
- def skipMany[A](p: => Parsley[A]): Parsley[Unit]
skipMany(p)
executes the parserp
zero or more times and ignores the results.skipMany(p)
executes the parserp
zero or more times and ignores the results. Returns()
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This method will be removed in Parsley 3.0, use
parsley.combinator.skipMany
instead
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