parsley
package parsley
- Alphabetic
- Public
- All
Type Members
-
class
Failure[Err] extends Result[Err, Nothing] with Product with Serializable
This class is used for a parser failure, and contains the error message.
This class is used for a parser failure, and contains the error message.
- Err
the type of the error message generated by the failing parse.
-
final
class
Parsley[+A] extends AnyVal
This is the class that encapsulates the act of parsing and running an object of this class with
parse
will parse the string given as input toparse
.This is the class that encapsulates the act of parsing and running an object of this class with
parse
will parse the string given as input toparse
.- Version
4.0.0
- Note
In order to construct an object of this class you must use the combinators; the class itself is opaque.
-
sealed abstract
class
Result[+Err, +A] extends AnyRef
This trait represents the result of a parser.
This trait represents the result of a parser.
Either a
Success[A]
or aFailure
.- A
the type of expected success result.
-
case class
Success[A] extends Result[Nothing, A] with Product with Serializable
This class is used for when a parser succeeds, and contains its result.
This class is used for when a parser succeeds, and contains its result.
- A
the type of expected success result.
Value Members
- object Failure extends Serializable
-
object
Parsley
This object contains the core "function-style" combinators: all parsers will likely require something from within!
This object contains the core "function-style" combinators: all parsers will likely require something from within!
In particular, it contains combinators for: controlling how input is consumed; injecting values into the parser, or failing; extracting position information from the parser; conditional execution of parsers; and more.
-
object
ap
This module contains
ap1
throughap22
, which allow for the application of a parser returning a function of arityN
toN
parsers.This module contains
ap1
throughap22
, which allow for the application of a parser returning a function of arityN
toN
parsers.The combinators contained in this module all sequence a number of parsers together, but are capable of combining the results generated by these parsers into a single value with a function of the correct arity produced by the first parser. This is a clean way of putting together multiple parsers and getting a meaningful result out.
scala> import parsley.character.char scala> import parsley.ap.{ap2, ap3} scala> case class Add(x: Int, y: Int) scala> val p = ap2(pure(Add), char('a') #> 4, char('b') #> 5) scala> p.parse("ab") val res0 = Success(Add(4, 5)) scala> val q = ap3(pure((x: Int, y: Int, z: Int) => x * y + z), char('a') #> 3, char('b') #> 2, char('c') #> 5) scala> q.parse("abc") val res1 = Success(11) scala> q.parse("ab") val res2 = Failure(..)
- Since
4.0.0
Example: -
object
character
This module contains many parsers to do with reading one or more characters.
This module contains many parsers to do with reading one or more characters. Almost every parser will need something from this module.
In particular, this module contains: combinators that can read specific characters; combinators that represent character classes and their negations; combinators for reading specific strings; as well as a selection of pre-made parsers to parse specific kinds of character, like digits and letters.
- Since
2.2.0
-
object
combinator
This module contains a huge number of pre-made combinators that are very useful for a variety of purposes.
This module contains a huge number of pre-made combinators that are very useful for a variety of purposes.
In particular, it contains combinators for: performing a parser iteratively, collecting all the results; querying whether or not any input is left; optionally performing parsers; parsing delimited constructions; handling multiple possible alternatives or parsers to sequence; handling more complex conditional execution; and more.
- Since
2.2.0
-
object
debug
This module contains the very useful debugging combinator, as well as breakpoints.
-
object
extension
These implicit classes can be used to extend the core combinator set of Parsley.
These implicit classes can be used to extend the core combinator set of Parsley.
This may mean that importing them enables combinators that can be used on non-
Parsley
types, or might enable some syntactic sugar that is not part of the core combinator "style". -
object
genericbridges
This module contains the definition of 23 basic generic parser bridge traits, which are used to implement the Parser Bridge pattern for types that do not require metadata.
This module contains the definition of 23 basic generic parser bridge traits, which are used to implement the Parser Bridge pattern for types that do not require metadata.
The traits within are designed to be extended by the companion object of some case class that is produced as the result of a parser: by using these traits, it enables a new
apply
method that makes it appear like the constructor is applied to the parsers themselves. This can be very useful for performing extra verification on the produced results, or to incorporate metadata into the result. Specifically, these traits are designed to be the bare-minimum functionaity, and do not interact with any metadata.- Since
4.0.0
-
object
lift
This module contains
lift1
throughlift22
, which allow for the application of a function of arityN
toN
parsers.This module contains
lift1
throughlift22
, which allow for the application of a function of arityN
toN
parsers.The combinators contained in this module all sequence a number of parsers together, but are capable of combining the results generated by these parsers into a single value with a given function of the correct arity. This is a clean way of putting together multiple parsers and getting a meaningful result out.
scala> import parsley.character.char scala> import parsley.lift.{lift2, lift3} scala> case class Add(x: Int, y: Int) scala> val p = lift2(Add, char('a') #> 4, char('b') #> 5) scala> p.parse("ab") val res0 = Success(Add(4, 5)) scala> val q = lift3((x: Int, y: Int, z: Int) => x * y + z, char('a') #> 3, char('b') #> 2, char('c') #> 5) scala> q.parse("abc") val res1 = Success(11) scala> q.parse("ab") val res2 = Failure(..) scala> val q2 = lift3[Int, Int, Int, Int](_ * _ + _, char('a') #> 3, char('b') #> 2, char('c') #> 5)
- Since
2.2.0
Example: -
object
registers
This module contains all the functionality and operations for using and manipulating registers.
This module contains all the functionality and operations for using and manipulating registers.
These often have a role in performing context-sensitive parsing tasks, where a Turing-powerful system is required. While
flatMap
is capable of such parsing, it is much less efficient than the use of registers, though slightly more flexible. In particular, thepersist
combinator enabled byRegisterMethods
can serve as a drop-in replacement forflatMap
in many scenarios.- Since
2.2.0