parsley
package parsley
- Alphabetic
- Public
- All
Type Members
-
case class
Failure extends Result[Nothing] with Product with Serializable
Returned on parsing failure
-
final
class
Parsley[+A] extends AnyVal
This is the class that encapsulates the act of parsing and running an object of this class with
runParser
will parse the string given as input torunParser
.This is the class that encapsulates the act of parsing and running an object of this class with
runParser
will parse the string given as input torunParser
.Note: In order to construct an object of this class you must use the combinators; the class itself is abstract
- Version
1
-
sealed abstract
class
Result[+A] extends AnyRef
Result of a parser.
Result of a parser. Either a
Success[A]
or aFailure
- A
The type of expected success result
-
case class
Success[A] extends Result[A] with Product with Serializable
Returned when a parser succeeded.
Returned when a parser succeeded.
- A
The type of expected success result
-
final
class
ExpressionParser[-A, +B] extends AnyRef
This class is used to generate efficient expression parsers given a table of operators in operator of operator precedence and an atomic value that represents the smallest part of the expression.
This class is used to generate efficient expression parsers given a table of operators in operator of operator precedence and an atomic value that represents the smallest part of the expression. Caters to unary and binary operators of different associativities.
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.expr.precedence
instead
-
sealed
trait
Impl extends AnyRef
The Impl trait is used to provide implementation of the parser requirements from
LanguageDef
The Impl trait is used to provide implementation of the parser requirements from
LanguageDef
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This trait will be removed in Parsley 3.0, use
parsley.token.Impl
instead
-
final
case class
LanguageDef(commentStart: String, commentEnd: String, commentLine: String, nestedComments: Boolean, identStart: Impl, identLetter: Impl, opStart: Impl, opLetter: Impl, keywords: Set[String], operators: Set[String], caseSensitive: Boolean, space: Impl) extends Product with Serializable
This class is required to construct a TokenParser.
This class is required to construct a TokenParser. It defines the various characteristics of the language to be tokenised. Where a parameter can be either a
Set[Char]
or aParsley
object, prefer theSet
where possible. It will unlock a variety of faster intrinsic versions of the parsers, which will greatly improve tokenisation performance! In addition, the Sets are one time converted to heavily optimised BitSets, though that has up to 8KB memory usage associated but at least doubles the execution speed for that instruction. Seeparsley.Impl
.- commentStart
For multi-line comments; how does the comment start? (If this or
commentEnd
is the empty string, multi-line comments are disabled)- commentEnd
For multi-line comments; how does the comment end? (If this or
commentEnd
is the empty string, multi-line comments are disabled)- commentLine
For single-line comments; how does the comment start? (This this is the empty string, single-line comments are disabled)
- nestedComments
Are multi-line comments allowed to be nested inside each other? E.g. If
{-
and-}
are opening and closing comments, is the following valid syntax:{-{-hello -}-}
? Note in C this is not the case.- identStart
What characters can an identifier in the language start with?
- identLetter
What characters can an identifier in the language consist of after the starting character?
- opStart
What characters can an operator in the language start with?
- opLetter
What characters can an operator in the language consist of after the starting character?
- keywords
What keywords does the language contain?
- operators
What operators does the language contain?
- caseSensitive
Is the language case-sensitive. I.e. is IF equivalent to if?
- space
What characters count as whitespace in the language?
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.token.LanguageDef
instead
-
case class
Parser(p: Parsley[_]) extends Impl with Product with Serializable
The implementation provided is a parser which parses the required token.
The implementation provided is a parser which parses the required token.
- p
The parser which will parse the token
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.token.Parser
instead
-
case class
Predicate(f: (Char) ⇒ Boolean) extends Impl with Product with Serializable
The implementation provided is a function which matches on the input streams characters
The implementation provided is a function which matches on the input streams characters
- f
The predicate that input tokens are tested against
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.token.Predicate
instead
-
final
class
Reg[A] extends parsley.registers.Reg[A]
This class is used to index registers within the mutable state.
This class is used to index registers within the mutable state. Currently, there are only 4 available registers, so use them wisely!
If you need more than four registers but know that they will be used at different times you can rename your register, as long as they point to the same reference. You may find the Parsley[A].cast[B: ClassTag]: Parsley[B] combinator useful to change the type of a
Reg[Any]
.- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.registers.Reg
instead- Since
2.0.0
- Note
It is undefined behaviour to use a register in multiple different independent parsers. You should be careful to parameterise the registers in shared parsers and allocate fresh ones for each "top-level" parser you will run.
-
final
class
TokenParser extends Lexer
When provided with a
LanguageDef
, this class will produce a large variety of parsers that can be used for tokenisation of a language.When provided with a
LanguageDef
, this class will produce a large variety of parsers that can be used for tokenisation of a language. This includes parsing numbers and strings in their various formats and ensuring that all operations consume whitespace after them (so-called lexeme parsers). These are very useful in parsing programming languages. This class also has a large number of hand-optimised intrinsic parsers to improve performance!- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.token.Lexer
instead
Value Members
-
object
Parsley
This object contains the core "function-style" combinators as well as the implicit classes which provide the "method-style" combinators.
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!
-
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.
- 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.
- Since
2.2.0
-
object
debug
This module contains the very useful debugging combinator, as well as breakpoints.
-
object
implicits
Provides implicit conversions and lifts for different values and parsers.
Provides implicit conversions and lifts for different values and parsers.
- Since
2.2.0
-
object
lift
This module contains
lift1
throughlift22
, which allow for the application of aFunctionN
toN
parsers for example:This module contains
lift1
throughlift22
, which allow for the application of aFunctionN
toN
parsers for example:lift2[Int, Int, Int](_+_, px, py): Parsley[Int]
, lift3((x: Int, y: Int, z: Int) => x + y + z, px, py, pz): Parsley[Int]
- Since
2.2.0
Examples: -
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.
- Since
2.2.0
-
object
unsafe
This module contains various things that shouldn't be used without care and caution
This module contains various things that shouldn't be used without care and caution
- Since
1.6.0
Deprecated Value Members
-
object
BitGen
This implementation uses a predicate to generate a BitSet.
This implementation uses a predicate to generate a BitSet. This should be preferred over
Predicate
when the function in question is expensive to execute and the parser itself is expected to be used many times. If the predicate is cheap, this is unlikely to provide any performance improvements, but will instead incur heavy space costs- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.token.BitGen
instead
-
object
Char
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This object will be removed in Parsley 3.0, use
parsley.character
instead
-
object
CharSet
This implementation uses a set of valid tokens.
This implementation uses a set of valid tokens. It is converted to a high-performance BitSet.
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This object will be removed in Parsley 3.0, use
parsley.token.CharSet
instead
-
object
Combinator
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This object will be removed in Parsley 3.0, use
parsley.combinator
instead
-
object
ExpressionParser
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This object will be removed in Parsley 3.0, use
parsley.expr.precedence
instead
-
object
Implicits
Provides implicit conversions and lifts for different values and parsers.
Provides implicit conversions and lifts for different values and parsers.
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This object will be removed in Parsley 3.0, use
parsley.implicits
instead
-
object
LanguageDef extends Serializable
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This object will be removed in Parsley 3.0, use
parsley.token.LanguageDef
instead
-
object
NotRequired extends Impl with Product with Serializable
This implementation states that the required functionality is not required.
This implementation states that the required functionality is not required. If it is used it will raise an error at parse-time
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This class will be removed in Parsley 3.0, use
parsley.token.NotRequired
instead
-
object
Reg
- Annotations
- @deprecated
- Deprecated
(Since version v2.2.0) This object will be removed in Parsley 3.0, use
parsley.registers.Reg
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