quick

parsley.quick
object quick

This serves as a quick way of importing everything from Parsley, character, position, lift, and ap. Other packages are not included in this, but this should be a good baseline for any non-lexing/expression parsing work.

Attributes

Since

5.0.0

Source
quick.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
quick.type

Members list

Grouped members

Primitive Combinators

These combinators are specific to parser combinators. In one way or another, they influence how a parser consumes input, or under what conditions a parser does or does not fail. These are really important for most practical parsing considerations, although lookAhead is much less well used.

final def atomic[A](p: Parsley[A]): Parsley[A]

This combinator parses its argument p, but rolls back any consumed input on failure.

This combinator parses its argument p, but rolls back any consumed input on failure.

If the parser p succeeds, then atomic(p) has no effect. However, if p failed, then any input that it consumed is rolled back. This ensures that the parser p is all-or-nothing when consuming input. While there are many legimate uses for all-or-nothing behaviour, one notable, if discouraged, use is to allow the | combinator to backtrack -- recall it can only parse its alternative if the first failed without consuming input. This is discouraged, however, as it can affect the complexity of the parser and harm error messages.

Value parameters

p

the parser to execute, if it fails, it will not have consumed input.

Attributes

Returns

a parser that tries p, but never consumes input if it fails.

Since

4.4.0

Example

scala> import parsley.character.string, parsley.Parsley.atomic
scala> (string("abc") | string("abd")).parse("abd")
val res0 = Failure(..) // first parser consumed a, so no backtrack
scala> (atomic(string("abc")) | string("abd")).parse("abd")
val res1 = Success("abd") // first parser does not consume input on failure now
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final def lookAhead[A](p: Parsley[A]): Parsley[A]

This combinator parses its argument p, but does not consume input if it succeeds.

This combinator parses its argument p, but does not consume input if it succeeds.

If the parser p succeeds, then lookAhead(p) will roll back any input consumed whilst parsing p. If p fails, however, then the whole combinator fails and any input consumed remains consumed. If this behaviour is not desirable, consider pairing lookAhead with atomic.

Value parameters

p

the parser to execute, if it succeeds, it will not have consumed input.

Attributes

Returns

a parser that parses p and never consumes input if it succeeds.

Example

scala> import parsley.Parsley.lookAhead, parsley.character.string
scala> (lookAhead(string("aaa")) ~> string("aaa")).parse("aaa")
val res0 = Success("aaa")
scala> (lookAhead(string("abc")) | string("abd")).parse("abd")
val res1 = Failure(..) // lookAhead does not roll back input consumed on failure
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final def notFollowedBy(p: Parsley[_]): Parsley[Unit]

This combinator parses its argument p, and succeeds when p fails and vice-versa, never consuming input.

This combinator parses its argument p, and succeeds when p fails and vice-versa, never consuming input.

If the parser p succeeds, then notFollowedBy(p) will fail, consuming no input. Otherwise, should p fail, then notFollowedBy(p) will succeed, consuming no input and returning ().

Value parameters

p

the parser to execute, it should fail in order for this combinator to succeed.

Attributes

Returns

a parser which fails when p succeeds and succeeds otherwise, never consuming input.

Example

one use for this combinator is to allow for "longest-match" behaviour. For instance, keywords are normally only considered keywords if they are not part of some larger valid identifier (i.e. the keyword "if" should not parse successfully given "ifp"). This can be accomplished as follows:

import parsley.character.{string, letterOrDigit}
import parsley.Parsley.notFollowedBy
def keyword(kw: String): Parsley[Unit] = atomic {
   string(kw) ~> notFollowedBy(letterOrDigit)
}
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala

Core Combinators and Parsers

These are the most primitive combinators for consuming input capable of any input reading tasks.

final def char(c: Char): Parsley[Char]

This combinator tries to parse a single specific character c from the input.

This combinator tries to parse a single specific character c from the input.

Attempts to read the given character c from the input stream at the current position. If this character can be found, it is consumed and returned. Otherwise, no input is consumed and this combinator will fail.

Value parameters

c

the character to parse

Attributes

Returns

a parser that tries to read a single c, or fails.

Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using string or unicode.char.

Example

scala> import parsley.character.char
scala> char('a').parse("")
val res0 = Failure(..)
scala> char('a').parse("a")
val res1 = Success('a')
scala> char('a').parse("ba")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala
final val item: Parsley[Char]

This parser will parse any single character from the input, failing if there is no input remaining.

This parser will parse any single character from the input, failing if there is no input remaining.

Attributes

Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.item.

Inherited from:
character (hidden)
Source
character.scala
final def satisfy(pred: Char => Boolean): Parsley[Char]

This combinator tries to parse a single character from the input that matches the given predicate.

This combinator tries to parse a single character from the input that matches the given predicate.

Attempts to read a character from the input and tests it against the predicate pred. If a character c can be read and pred(c) is true, then c is consumed and returned. Otherwise, no input is consumed and this combinator will fail.

Value parameters

pred

the predicate to test the next character against, should one exist.

Attributes

Returns

a parser that tries to read a single character c, such that pred(c) is true, or fails.

Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.satisfy.

Example

scala> import parsley.character.satisfy
scala> satisfy(_.isDigit).parse("")
val res0 = Failure(..)
scala> satisfy(_.isDigit).parse("7")
val res1 = Success('7')
scala> satisfy(_.isDigit).parse("a5")
val res2 = Failure(..)
scala> def char(c: Char): Parsley[Char] = satisfy(_ == c)
Inherited from:
character (hidden)
Source
character.scala
final def satisfyMap[A](f: PartialFunction[Char, A]): Parsley[A]

This combinator tries to parse and process a character from the input if it is defined for the given function.

This combinator tries to parse and process a character from the input if it is defined for the given function.

Attempts to read a character from the input and tests to see if it is in the domain of f. If a character c can be read and f(c) is defined, then c is consumed and f(c) is returned. Otherwise, no input is consumed and this combinator will fail.

Value parameters

f

the function to test the next character against and transform it with, should one exist.

Attributes

Returns

a parser that tries to read a single character c, such that f(c) is defined, and returns f(c) if so, or fails.

Since

4.4.0

Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.satisfyMap.

Example

scala> import parsley.character.satisfyMap
scala> val digit = satisfyMap {
 case c if c.isDigit => c.asDigit
}
scala> digit.parse("")
val res0 = Failure(..)
scala> digit.parse("7")
val res1 = Success(7)
scala> digit.parse("a5")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

Consumptionless Parsers

These combinators and parsers do not consume input: they are the most primitive ways of producing successes and failures with the minimal possible effect on the parse. They are, however, reasonably useful; in particular, pure and unit can be put to good use in injecting results into a parser without needing to consume anything, or mapping another parser.

final def empty(caretWidth: Int): Parsley[Nothing]

This combinator fails immediately, with a caret of the given width and no other information.

This combinator fails immediately, with a caret of the given width and no other information.

By producing basically no information, this combinator is principally for adjusting the caret-width of another error, rather than the value empty, which is used to fail with no effect on error content.

Value parameters

caretWidth

the width of the caret for the error produced by this combinator.

Attributes

Returns

a parser that fails.

Since

4.4.0

Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final val empty: Parsley[Nothing]

This parser fails immediately, with an unknown parse error.

This parser fails immediately, with an unknown parse error.

Attributes

Returns

a parser that fails.

Note

equivalent to empty(0)

Example

scala> import parsley.Parsley.empty
scala> empty.parse("")
val res0 = Failure(..)
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final def fresh[A](x: => A): Parsley[A]

This combinator produces a new value everytime it is parsed without having any other effect.

This combinator produces a new value everytime it is parsed without having any other effect.

When this combinator is ran, no input is required, nor consumed, and a new instance of the given value will always be successfully returned. It has no other effect on the state of the parser.

This is useful primarily if mutable data is being threaded around a parser: this should not be needed for the vast majority of parsers.

Value parameters

x

the value to be returned.

Attributes

Returns

a parser which consumes no input and produces a value x.

Since

4.0.0

Example

scala> import parsley.Parsley.{pure, fresh}
scala> val p = pure(new Object)
scala> p.parse("")
val res0 = Success(java.lang.Object@44a3ec6b)
scala> p.parse("")
val res1 = Success(java.lang.Object@44a3ec6b)
scala> val q = fresh(new Object)
scala> q.parse("")
val res2 = Success(java.lang.Object@71623278)
scala> q.parse("")
val res3 = Success(java.lang.Object@768b970c)
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final def pure[A](x: A): Parsley[A]

This combinator produces a value without having any other effect.

This combinator produces a value without having any other effect.

When this combinator is ran, no input is required, nor consumed, and the given value will always be successfully returned. It has no other effect on the state of the parser.

Value parameters

x

the value to be returned.

Attributes

Returns

a parser which consumes no input and produces a value x.

Example

scala> import parsley.Parsley.pure
scala> pure(7).parse("")
val res0 = Success(7)
scala> pure("hello!").parse("a")
val res1 = Success("hello!")
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final val unit: Parsley[Unit]

This parser produces () without having any other effect.

This parser produces () without having any other effect.

When this parser is ran, no input is required, nor consumed, and the given value will always be successfully returned. It has no other effect on the state of the parser.

Value parameters

x

the value to be returned.

Attributes

Returns

a parser which consumes no input and produces ().

Note

defined as pure(()) as a simple convenience.

Example

scala> import parsley.Parsley.unit
scala> unit.parse("")
val res0 = Success(())
scala> unit.parse("a")
val res0 = Success(())
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala

Iterative Combinators

These combinators all execute a given parser an unbounded number of times, until either it fails, or another parser succeeds, depending on the combinator. All of the results produced by the repeated execution of the parser are returned in a List. These are almost essential for any practical parsing task.

final def countMany(p: Parsley[_]): Parsley[Int]

This combinator repeatedly parses a given parser zero or more times, returning how many times it succeeded.

This combinator repeatedly parses a given parser zero or more times, returning how many times it succeeded.

Parses a given parser, p, repeatedly until it fails. If p failed having consumed input, this combinator fails. Otherwise when p fails without consuming input, this combinator will succeed. The number of times p succeeded is returned as the result.

Value parameters

p

the parser to execute multiple times.

Attributes

Returns

the number of times p successfully parses

Since

4.5.0

Example

scala> import parsley.character.string
scala> import parsley.combinator.countMany
scala> val p = countMany(string("ab"))
scala> p.parse("")
val res0 = Success(0)
scala> p.parse("ab")
val res1 = Success(1)
scala> p.parse("abababab")
val res2 = Success(4)
scala> p.parse("aba")
val res3 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def countSome(p: Parsley[_]): Parsley[Int]

This combinator repeatedly parses a given parser one or more times, returning how many times it succeeded.

This combinator repeatedly parses a given parser one or more times, returning how many times it succeeded.

Parses a given parser, p, repeatedly until it fails. If p failed having consumed input, this combinator fails. Otherwise when p fails without consuming input, this combinator will succeed. The parser p must succeed at least once. The number of times p succeeded is returned as the result.

Value parameters

p

the parser to execute multiple times.

Attributes

Returns

the number of times p successfully parses

Since

4.5.0

Example

scala> import parsley.character.string
scala> import parsley.combinator.countSome
scala> val p = countSome(string("ab"))
scala> p.parse("")
val res0 = Failure(..)
scala> p.parse("ab")
val res1 = Success(1)
scala> p.parse("abababab")
val res2 = Success(4)
scala> p.parse("aba")
val res3 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def many[A](p: Parsley[A]): Parsley[List[A]]

This combinator repeatedly parses a given parser zero or more times, collecting the results into a list.

This combinator repeatedly parses a given parser zero or more times, collecting the results into a list.

Parses a given parser, p, repeatedly until it fails. If p failed having consumed input, this combinator fails. Otherwise when p fails without consuming input, this combinator will return all of the results, x1 through xn (with n >= 0), in a list: List(x1, .., xn). If p was never successful, the empty list is returned.

Value parameters

p

the parser to execute multiple times.

Attributes

Returns

a parser that parses p until it fails, returning the list of all the successful results.

Since

4.5.0

Example

scala> import parsley.character.string
scala> import parsley.Parsley.many
scala> val p = many(string("ab"))
scala> p.parse("")
val res0 = Success(Nil)
scala> p.parse("ab")
val res1 = Success(List("ab"))
scala> p.parse("abababab")
val res2 = Success(List("ab", "ab", "ab", "ab"))
scala> p.parse("aba")
val res3 = Failure(..)
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final def manyN[A](n: Int, p: Parsley[A]): Parsley[List[A]]

This combinator repeatedly parses a given parser n or more times, collecting the results into a list.

This combinator repeatedly parses a given parser n or more times, collecting the results into a list.

Parses a given parser, p, repeatedly until it fails. If p failed having consumed input, this combinator fails. Otherwise when p fails without consuming input, this combinator will return all of the results, x1 through xm (with m >= n), in a list: List(x1, .., xm). If p was not successful at least n times, this combinator fails.

Value parameters

n

the minimum number of ps required.

p

the parser to execute multiple times.

Attributes

Returns

a parser that parses p until it fails, returning the list of all the successful results.

Note

many(p) == many(0, p) and some(p) == many(1, p).

Example

scala> import parsley.character.string
scala> import parsley.combinator.manyN
scala> val p = manyN(2, string("ab"))
scala> p.parse("")
val res0 = Failure(..)
scala> p.parse("ab")
val res1 = Failure(..)
scala> p.parse("abababab")
val res2 = Success(List("ab", "ab", "ab", "ab"))
scala> p.parse("aba")
val res3 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def manyTill[A](p: Parsley[A], end: Parsley[_]): Parsley[List[A]]

This combinator repeatedly parses a given parser zero or more times, until the end parser succeeds, collecting the results into a list.

This combinator repeatedly parses a given parser zero or more times, until the end parser succeeds, collecting the results into a list.

First tries to parse end, if it fails without consuming input, then parses p, which must succeed. This repeats until end succeeds. When end does succeed, this combinator will return all of the results generated by p, x1 through xn (with n >= 0), in a list: List(x1, .., xn). If end could be parsed immediately, the empty list is returned.

Value parameters

end

the parser that stops the parsing of p.

p

the parser to execute multiple times.

Attributes

Returns

a parser that parses p until end succeeds, returning the list of all the successful results.

Since

4.5.0

Example

This can be useful for scanning comments:

scala> import parsley.character.{string, item, endOfLine}
scala> import parsley.combinator.manyTill
scala> val comment = string("//") ~> manyTill(item, endOfLine)
scala> p.parse("//hello world")
val res0 = Failure(..)
scala> p.parse("//hello world\n")
val res1 = Success(List('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'))
scala> p.parse("//\n")
val res2 = Success(Nil)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def some[A](p: Parsley[A]): Parsley[List[A]]

This combinator repeatedly parses a given parser one or more times, collecting the results into a list.

This combinator repeatedly parses a given parser one or more times, collecting the results into a list.

Parses a given parser, p, repeatedly until it fails. If p failed having consumed input, this combinator fails. Otherwise when p fails without consuming input, this combinator will return all of the results, x1 through xn (with n >= 1), in a list: List(x1, .., xn). If p was not successful at least one time, this combinator fails.

Value parameters

p

the parser to execute multiple times.

Attributes

Returns

a parser that parses p until it fails, returning the list of all the successful results.

Since

4.5.0

Example

scala> import parsley.character.string
scala> import parsley.Parsley.some
scala> val p = some(string("ab"))
scala> p.parse("")
val res0 = Failure(..)
scala> p.parse("ab")
val res1 = Success(List("ab"))
scala> p.parse("abababab")
val res2 = Success(List("ab", "ab", "ab", "ab"))
scala> p.parse("aba")
val res3 = Failure(..)
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final def someTill[A](p: Parsley[A], end: Parsley[_]): Parsley[List[A]]

This combinator repeatedly parses a given parser one or more times, until the end parser succeeds, collecting the results into a list.

This combinator repeatedly parses a given parser one or more times, until the end parser succeeds, collecting the results into a list.

First ensures that trying to parse end fails, then tries to parse p. If it succeed then it will repeatedly: try to parse end, if it fails without consuming input, then parses p, which must succeed. When end does succeed, this combinator will return all of the results generated by p, x1 through xn (with n >= 1), in a list: List(x1, .., xn). The parser p must succeed at least once before end succeeds.

Value parameters

end

the parser that stops the parsing of p.

p

the parser to execute multiple times.

Attributes

Returns

a parser that parses p until end succeeds, returning the list of all the successful results.

Since

4.5.0

Example

This can be useful for scanning comments:

scala> import parsley.character.{string, item, endOfLine}
scala> import parsley.combinator.someUntil
scala> val comment = string("//") ~> someUntil(item, endOfLine)
scala> p.parse("//hello world")
val res0 = Failure(..)
scala> p.parse("//hello world\n")
val res1 = Success(List('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'))
scala> p.parse("//\n")
val res2 = Failure(..)
scala> p.parse("//a\n")
val res3 = Success(List('a'))
Inherited from:
combinator (hidden)
Source
combinator.scala

Input Query Combinators

These combinators do not consume input, but they allow for querying of the input stream - specifically checking whether or not there is more input that can be consumed or not. In particular, most parsers should be making use of eof to ensure that the parser consumes all the input available at the end of the parse.

final val eof: Parsley[Unit]

This parser only succeeds at the end of the input.

This parser only succeeds at the end of the input.

Equivalent to notFollowedBy(item).

Attributes

Since

4.5.0

Example

scala> import parsley.combinator.eof
scala> eof.parse("a")
val res0 = Failure(..)
scala> eof.parse("")
val res1 = Success(())
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala

Optional Parsing Combinators

These combinators allow for the possible parsing of some parser. If the parser succeeds, that is ok so long as it did not consume input. Be aware that the result of the success may be replaced with these combinators, with the exception of option, which still preserves the result.

final def option[A](p: Parsley[A]): Parsley[Option[A]]

This combinator tries to parse p, wrapping its result in a Some if it succeeds, or returns None if it fails.

This combinator tries to parse p, wrapping its result in a Some if it succeeds, or returns None if it fails.

Tries to parse p. If p succeeded, producing x, then Some(x) is returned. Otherwise, if p failed without consuming input, then None is returned instead.

Value parameters

p

the parser to try to parse.

Attributes

Returns

a parser that tries to parse p, but can still succeed with None if that was not possible.

Example

scala> import parsley.combinator.option
scala> import parsley.character.string
scala> val p = option(string("abc"))
scala> p.parse("")
val res0 = Success(None)
scala> p.parse("abc")
val res1 = Success(Some("abc"))
scala> p.parse("ab")
val res2 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def optional(p: Parsley[_]): Parsley[Unit]

This combinator will parse p if possible, otherwise will do nothing.

This combinator will parse p if possible, otherwise will do nothing.

Tries to parse p. If p succeeds, or fails without consuming input then this combinator is successful. Otherwise, if p failed having consumed input, this combinator fails.

Value parameters

p

the parser to try to parse.

Attributes

Returns

a parser that tries to parse p.

Note

equivalent to optionalAs(p, ()).

Example

scala> import parsley.combinator.optional
scala> import parsley.character.string
scala> val p = optional(string("abc"))
scala> p.parse("")
val res0 = Success(())
scala> p.parse("abc")
val res1 = Success(())
scala> p.parse("ab")
val res2 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def optionalAs[A](p: Parsley[_], x: A): Parsley[A]

This combinator will parse p if possible, otherwise will do nothing.

This combinator will parse p if possible, otherwise will do nothing.

Tries to parse p. If p succeeds, or fails without consuming input then this combinator is successful and returns x. Otherwise, if p failed having consumed input, this combinator fails.

Value parameters

p

the parser to try to parse.

x

the value to return regardless of how p performs.

Attributes

Returns

a parser that tries to parse p, returning x regardless of success or failure.

Example

scala> import parsley.combinator.optionalAs
scala> import parsley.character.string
scala> val p = optionalAs(string("abc"), 7)
scala> p.parse("")
val res0 = Success(7)
scala> p.parse("abc")
val res1 = Success(7)
scala> p.parse("ab")
val res2 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala

Character Class Combinators

These combinators allow for working with character classes. This means that a set, or range, of characters can be specified, and the combinator will return a parser that matches one of those characters (or conversely, any character that is not in that set). The parsed character is always returned.

$noneOf

$noneOf

If the next character in the input is outside of the range of characters cs, it is consumed and returned. Otherwise, no input is consumed and the combinator fails.

Value parameters

cs

the range of characters to check.

Attributes

Returns

a parser that parses a character outside the range cs.

See also
Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.noneOf.

Example

scala> import parsley.character.noneOf
scala> val p = noneOf('a' to 'c')
scala> p.parse("a")
val res0 = Failure(..)
scala> p.parse("b")
val res1 = Failure(..)
scala> p.parse("c")
val res1 = Failure(..)
scala> p.parse("xb")
val res2 = Success('x')
scala> p.parse("")
val res3 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala
final def noneOf(cs: Char*): Parsley[Char]

$noneOf

$noneOf

If the next character in the input is not an element of the list of characters cs, it is consumed and returned. Otherwise, no input is consumed and the combinator fails.

Value parameters

cs

the set of characters to check.

Attributes

Returns

a parser that parses one character that is not an element of cs.

See also
Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.noneOf.

Example

scala> import parsley.character.noneOf
scala> val p = noneOf('a', 'b', 'c')
scala> p.parse("a")
val res0 = Failure(..)
scala> p.parse("c")
val res1 = Failure(..)
scala> p.parse("xb")
val res2 = Success('x')
scala> p.parse("")
val res3 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala
final def noneOf(cs: Set[Char]): Parsley[Char]

$noneOf

$noneOf

If the next character in the input is not a member of the set cs, it is consumed and returned. Otherwise, no input is consumed and the combinator fails.

Value parameters

cs

the set of characters to check.

Attributes

Returns

a parser that parses one character that is not a member of the set cs.

See also
Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.noneOf.

Example

scala> import parsley.character.noneOf
scala> val p = noneOf(Set('a', 'b', 'c'))
scala> p.parse("a")
val res0 = Failure(..)
scala> p.parse("c")
val res1 = Failure(..)
scala> p.parse("xb")
val res2 = Success('x')
scala> p.parse("")
val res3 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

$oneOf

$oneOf

If the next character in the input is within the range of characters cs, it is consumed and returned. Otherwise, no input is consumed and the combinator fails.

Value parameters

cs

the range of characters to check.

Attributes

Returns

a parser that parses a character within the range cs.

See also
Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.oneOf.

Example

scala> import parsley.character.oneOf
scala> val p = oneOf('a' to 'c')
scala> p.parse("a")
val res0 = Success('a')
scala> p.parse("b")
val res1 = Success('b')
scala> p.parse("c")
val res1 = Success('c')
scala> p.parse("xb")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala
final def oneOf(cs: Char*): Parsley[Char]

$oneOf

$oneOf

If the next character in the input is an element of the list of characters cs, it is consumed and returned. Otherwise, no input is consumed and the combinator fails.

Value parameters

cs

the characters to check.

Attributes

Returns

a parser that parses one of the elements of cs.

See also
Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.oneOf.

Example

scala> import parsley.character.oneOf
scala> val p = oneOf('a', 'b', 'c')
scala> p.parse("a")
val res0 = Success('a')
scala> p.parse("c")
val res1 = Success('c')
scala> p.parse("xb")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala
final def oneOf(cs: Set[Char]): Parsley[Char]

$oneOf

$oneOf

If the next character in the input is a member of the set cs, it is consumed and returned. Otherwise, no input is consumed and the combinator fails.

Value parameters

cs

the set of characters to check.

Attributes

Returns

a parser that parses one of the member of the set cs.

See also
Note

this combinator can only handle 16-bit characters: for larger codepoints, consider using unicode.oneOf.

Example

scala> import parsley.character.oneOf
scala> val p = oneOf(Set('a', 'b', 'c'))
scala> p.parse("a")
val res0 = Success('a')
scala> p.parse("c")
val res1 = Success('c')
scala> p.parse("xb")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

String Combinators

These combinators allow for working with, or building, strings. This means that they can parse specific strings, specific sets of strings, or can read characters repeatedly to generate strings. They are united in all returning String as their result.

final def string(s: String): Parsley[String]

This combinator attempts to parse a given string from the input, and fails otherwise.

This combinator attempts to parse a given string from the input, and fails otherwise.

Attempts to read the given string completely from the input at the current position. If the string is present, then the parser succeeds, and the entire string is consumed from the input. Otherwise, if the input has too few characters remaining, or not all the characters matched, the parser fails. On failure, all the characters that were matched are consumed from the input.

Value parameters

s

the string to be parsed from the input

Attributes

Returns

a parser that either parses the string s or fails at the first mismatched character.

Note

the error messages generated by string do not reflect how far into the input it managed to get: this is because the error being positioned at the start of the string is more natural. However, input will still be consumed for purposes of backtracking.

Example

scala> import parsley.character.string
scala> string("abc").parse("")
val res0 = Failure(..)
scala> string("abc").parse("abcd")
val res1 = Success("abc")
scala> string("abc").parse("xabc")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

This combinator parses characters matching the given predicate zero or more times, collecting the results into a string.

This combinator parses characters matching the given predicate zero or more times, collecting the results into a string.

Repeatly reads characters that satisfy the given predicate pred. When no more characters can be successfully read, the results are stitched together into a String and returned. This combinator can never fail, since satisfy can never fail having consumed input.

Value parameters

pred

the predicate to test characters against.

Attributes

Returns

a parser that returns the span of characters satisfying pred

Since

4.4.0

Note

this acts exactly like stringOfMany(satisfy(pred)), but may be more efficient.

analogous to the megaparsec takeWhileP combinator.

Example

scala> import parsley.character.{letter, stringOfMany}
scala> import parsley.syntax.zipped._
scala> val ident = (letter, stringOfMany(_.isLetterOrDigit)).zipped((c, s) => s"$c$s")
scala> ident.parse("abdc9d")
val res0 = Success("abdc9d")
scala> ident.parse("a")
val res1 = Success("a")
scala> ident.parse("9")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

This combinator parses pc zero or more times, collecting its results into a string.

This combinator parses pc zero or more times, collecting its results into a string.

Parses pc repeatedly until it fails. The resulting characters are placed into a string, which is then returned. This is morally equivalent to many(pc).map(_.mkString), but it uses StringBuilder, which makes it much more efficient.

Value parameters

pc

the parser whose results make up the string

Attributes

Returns

a parser that parses a string whose letters consist of results from pc.

Since

4.0.0

Example

scala> import parsley.character.{letter, letterOrDigit, stringOfMany}
scala> import parsley.syntax.zipped._
scala> val ident = (letter, stringOfMany(letterOrDigit)).zipped((c, s) => s"$c$s")
scala> ident.parse("abdc9d")
val res0 = Success("abdc9d")
scala> ident.parse("a")
val res1 = Success("a")
scala> ident.parse("9")
val res2 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

This combinator parses characters matching the given predicate one or more times, collecting the results into a string.

This combinator parses characters matching the given predicate one or more times, collecting the results into a string.

Repeatly reads characters that satisfy the given predicate pred. When no more characters can be successfully read, the results are stitched together into a String and returned. This combinator can never fail having consumed input, since satisfy can never fail having consumed input.

Value parameters

pred

the predicate to test characters against.

Attributes

Returns

a parser that returns the span of characters satisfying pred

Since

4.4.0

Note

this acts exactly like stringOfSome(satisfy(pred)), but may be more efficient.

analogous to the megaparsec takeWhile1P combinator.

Example

scala> import parsley.character.{stringOfSome}
scala> val ident = stringOfSome(_.isLetter)
scala> ident.parse("abdc9d")
val res0 = Success("abdc")
scala> ident.parse("")
val res1 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

This combinator parses pc one or more times, collecting its results into a string.

This combinator parses pc one or more times, collecting its results into a string.

Parses pc repeatedly until it fails. The resulting characters are placed into a string, which is then returned. This is morally equivalent to many(pc).map(_.mkString), but it uses StringBuilder, which makes it much more efficient. The result string must have at least one character in it.

Value parameters

pc

the parser whose results make up the string

Attributes

Returns

a parser that parses a string whose letters consist of results from pc.

Since

4.0.0

Example

scala> import parsley.character.{letter, stringOfSome}
scala> val ident = stringOfSome(letter)
scala> ident.parse("abdc9d")
val res0 = Success("abdc")
scala> ident.parse("")
val res1 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala
final def strings[A](kv0: (String, Parsley[A]), kvs: (String, Parsley[A])*): Parsley[A]

This combinator tries to parse each of the key-value pairs kvs (and kv0), until one of them succeeds.

This combinator tries to parse each of the key-value pairs kvs (and kv0), until one of them succeeds.

Each argument to this combinator is a pair of a string and a parser to perform if that string can be parsed. strings(s0 -> p0, ...) can be thought of as atomicChoice(string(s0) ~> p0, ...), however, the given ordering of key-value pairs does not dictate the order in which the parses are tried. In particular, it will avoid keys that are the prefix of another key first, so that it has Longest Match semantics. It will try to minimise backtracking too, making it a much more efficient option than atomicChoice.

Value parameters

kv0

the first key-value pair to try to parse.

kvs

the remaining key-value pairs to try to parse.

Attributes

Returns

a parser that tries to parse all the given key-value pairs, returning the (possibly failing) result of the value that corresponds to the longest matching key.

Since

4.0.0

Note

the scope of any backtracking performed is isolated to the key itself, as it is assumed that once a key parses correctly, the branch has been committed to. Putting an atomic around the values will not affect this behaviour.

Example

scala> import parsley.character.strings
scala> val p = strings("hell" -> pure(4), "hello" -> pure(5), "goodbye" -> pure(7), "g" -> pure(1), "abc" -> pure(3))
scala> p.parse("hell")
val res0 = Success(4)
scala> p.parse("hello")
val res1 = Success(5)
scala> p.parse("good")
val res2 = Success(1)
scala> p.parse("goodbye")
val res3 = Success(7)
scala> p.parse("a")
val res4 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

This combinator tries to parse each of the strings strs (and str0), until one of them succeeds.

This combinator tries to parse each of the strings strs (and str0), until one of them succeeds.

Unlike choice, or more accurately atomicChoice, this combinator will not necessarily parse the strings in the order provided. It will avoid strings that have another string as a prefix first, so that it has Longest Match semantics. It will try to minimise backtracking too, making it a much more efficient option than atomicChoice.

The longest succeeding string will be returned. If no strings match then the combinator fails.

Value parameters

str0

the first string to try to parse.

strs

the remaining strings to try to parse.

Attributes

Returns

a parser that tries to parse all the given strings returning the longest one that matches.

Since

4.0.0

Example

scala> import parsley.character.strings
scala> val p = strings("hell", "hello", "goodbye", "g", "abc")
scala> p.parse("hell")
val res0 = Success("hell")
scala> p.parse("hello")
val res1 = Success("hello")
scala> p.parse("good")
val res2 = Success("g")
scala> p.parse("goodbye")
val res3 = Success("goodbye")
scala> p.parse("a")
val res4 = Failure(..)
Inherited from:
character (hidden)
Source
character.scala

Separated Values Combinators

These combinators are concerned with delimited parsing, where one parser is repeated but delimited by another one. In each of these cases p is the parser of interest and sep is the delimeter. These combinators mainly differ in either the number of ps they require, or exactly where the delimeters are allowed (only between, always trailing, or either). In all cases, they return the list of results generated by the repeated parses of p.

final def endBy[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

This combinator parses zero or more occurrences of p, separated and ended by sep.

This combinator parses zero or more occurrences of p, separated and ended by sep.

Behaves just like endBy1, except does not require an initial p and sep, returning the empty list instead.

Value parameters

p

the parser whose results are collected into a list.

sep

the delimiter that must be parsed between every p.

Attributes

Returns

a parser that parses p delimited by sep, returning the list of p's results.

Example

scala> ...
scala> val args = endBy(int, string(";\n"))
scala> args.parse("7;\n3;\n2")
val res0 = Failure(..)
scala> args.parse("")
val res1 = Success(Nil)
scala> args.parse("1;\n")
val res2 = Success(List(1))
scala> args.parse("1;\n2;\n")
val res3 = Success(List(1, 2))
Inherited from:
combinator (hidden)
Source
combinator.scala
final def endBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

This combinator parses one or more occurrences of p, separated and ended by sep.

This combinator parses one or more occurrences of p, separated and ended by sep.

Parses p followed by sep one or more times. The results of the p's, x1 through xn, are returned as List(x1, .., xn). If p or sep fails having consumed input, the whole parser fails.

Value parameters

p

the parser whose results are collected into a list.

sep

the delimiter that must be parsed between every p.

Attributes

Returns

a parser that parses p delimited by sep, returning the list of p's results.

Example

scala> ...
scala> val args = endBy1(int, string(";\n"))
scala> args.parse("7;\n3;\n2")
val res0 = Failure(..)
scala> args.parse("")
val res1 = Failure(..)
scala> args.parse("1;\n")
val res2 = Success(List(1))
scala> args.parse("1;\n2;\n")
val res3 = Success(List(1, 2))
Inherited from:
combinator (hidden)
Source
combinator.scala
final def sepBy[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

This combinator parses zero or more occurrences of p, separated by sep.

This combinator parses zero or more occurrences of p, separated by sep.

Behaves just like sepBy1, except does not require an initial p, returning the empty list instead.

Value parameters

p

the parser whose results are collected into a list.

sep

the delimiter that must be parsed between every p.

Attributes

Returns

a parser that parses p delimited by sep, returning the list of p's results.

Example

scala> ...
scala> val args = sepBy(int, string(", "))
scala> args.parse("7, 3, 2")
val res0 = Success(List(7, 3, 2))
scala> args.parse("")
val res1 = Success(Nil)
scala> args.parse("1")
val res2 = Success(List(1))
scala> args.parse("1, 2, ")
val res3 = Failure(..) // no trailing comma allowed
Inherited from:
combinator (hidden)
Source
combinator.scala
final def sepBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

This combinator parses one or more occurrences of p, separated by sep.

This combinator parses one or more occurrences of p, separated by sep.

First parses a p. Then parses sep followed by p until there are no more seps. The results of the p's, x1 through xn, are returned as List(x1, .., xn). If p or sep fails having consumed input, the whole parser fails. Requires at least one p to have been parsed.

Value parameters

p

the parser whose results are collected into a list.

sep

the delimiter that must be parsed between every p.

Attributes

Returns

a parser that parses p delimited by sep, returning the list of p's results.

Example

scala> ...
scala> val args = sepBy1(int, string(", "))
scala> args.parse("7, 3, 2")
val res0 = Success(List(7, 3, 2))
scala> args.parse("")
val res1 = Failure(..)
scala> args.parse("1")
val res2 = Success(List(1))
scala> args.parse("1, 2, ")
val res3 = Failure(..) // no trailing comma allowed
Inherited from:
combinator (hidden)
Source
combinator.scala
final def sepEndBy[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

This combinator parses zero or more occurrences of p, separated and optionally ended by sep.

This combinator parses zero or more occurrences of p, separated and optionally ended by sep.

Behaves just like sepEndBy1, except does not require an initial p, returning the empty list instead.

Value parameters

p

the parser whose results are collected into a list.

sep

the delimiter that must be parsed between every p.

Attributes

Returns

a parser that parses p delimited by sep, returning the list of p's results.

Example

scala> ...
scala> val args = sepEndBy(int, string(";\n"))
scala> args.parse("7;\n3;\n2")
val res0 = Success(List(7, 3, 2))
scala> args.parse("")
val res1 = Success(Nil)
scala> args.parse("1")
val res2 = Success(List(1))
scala> args.parse("1;\n2;\n")
val res3 = Success(List(1, 2))
Inherited from:
combinator (hidden)
Source
combinator.scala
final def sepEndBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

This combinator parses one or more occurrences of p, separated and optionally ended by sep.

This combinator parses one or more occurrences of p, separated and optionally ended by sep.

First parses a p. Then parses sep followed by p until there are no more: if a final sep exists, this is parsed. The results of the p's, x1 through xn, are returned as List(x1, .., xn). If p or sep fails having consumed input, the whole parser fails. Requires at least one p to have been parsed.

Value parameters

p

the parser whose results are collected into a list.

sep

the delimiter that must be parsed between every p.

Attributes

Returns

a parser that parses p delimited by sep, returning the list of p's results.

Example

scala> ...
scala> val args = sepEndBy1(int, string(";\n"))
scala> args.parse("7;\n3;\n2")
val res0 = Success(List(7, 3, 2))
scala> args.parse("")
val res1 = Failure(..)
scala> args.parse("1")
val res2 = Success(List(1))
scala> args.parse("1;\n2;\n")
val res3 = Success(List(1, 2))
Inherited from:
combinator (hidden)
Source
combinator.scala

Specific Character Parsers

These parsers are special cases of satisfy or char. They are worth using, as they are given special error labelling, producing nicer error messages than their primitive counterparts. This documentation assumes JDK 17. JDK 17 is compliant with Unicode® Specification 13.0. As such, the descriptions of the parsers in this section are accurate with respect to Unicode® Specification 13.0: using a different JDK may affect the precise definitions of the parsers below. If in doubt, check the documentation for java.lang.Character to see which Unicode version is supported by your JVM. A table of the Unicode versions up to JDK 17 can be found here. These parsers are only able to parse unicode characters in the range '\u0000' to '\uffff', known as the Basic Multilingual Plane (BMP). Unicode characters wider than a single 16-bit character should be parsed using multi-character combinators such as string, or, alternatively, combinators found in unicode.

final val bit: Parsley[Char]

This parser tries to parse a binary digit (bit) and returns it if successful.

This parser tries to parse a binary digit (bit) and returns it if successful.

A bit is either '0' or '1'.

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val crlf: Parsley[Char]

This parser tries to parse a CRLF newline character pair, returning '\n' if successful.

This parser tries to parse a CRLF newline character pair, returning '\n' if successful.

A CRLF character is the pair of carriage return ('\r') and line feed ('\n'). These two characters will be parsed together or not at all. The parser is made atomic using atomic.

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val digit: Parsley[Char]

This parser tries to parse a digit, and returns it if successful.

This parser tries to parse a digit, and returns it if successful.

A digit is any character c <= '\uffff' whose Unicode Category Type is Decimal Number (Nd). Examples of (inclusive) ranges within this category include:

  • the Latin digits '0' through '9'

  • the Arabic-Indic digits '\u0660' through '\u0669'

  • the Extended Arabic-Indic digits '\u06f0' through '\u06f9'

  • the Devangari digits '\u0966' through '\u096f'

  • the Fullwidth digits '\uff10' through '\uff19'

$categories

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val endOfLine: Parsley[Char]

This parser will parse either a line feed (LF) or a CRLF newline, returning '\n' if successful.

This parser will parse either a line feed (LF) or a CRLF newline, returning '\n' if successful.

Attributes

See also
Inherited from:
character (hidden)
Source
character.scala
final val hexDigit: Parsley[Char]

This parser tries to parse a hexadecimal digit, and returns it if successful.

This parser tries to parse a hexadecimal digit, and returns it if successful.

A hexadecimal digit is one of (all inclusive ranges):

  1. the digits '0' through '9'

  2. the letters 'a' through 'f'

  3. the letters 'A' through 'Z'

Attributes

See also
Inherited from:
character (hidden)
Source
character.scala
final val letter: Parsley[Char]

This parser tries to parse a letter, and returns it if successful.

This parser tries to parse a letter, and returns it if successful.

A letter is any character c <= '\uffff' whose Unicode Category Type is any of the following:

  1. Uppercase Letter (Lu)

  2. Lowercase Letter (Ll)

  3. Titlecase Letter (Lt)

  4. Modifier Letter (Lm)

  5. Other Letter (Lo)

$categories

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val letterOrDigit: Parsley[Char]

This parser tries to parse either a letter or a digit, and returns it if successful.

This parser tries to parse either a letter or a digit, and returns it if successful.

A letter or digit is anything that would parse in either letter or digit.

Attributes

See also

documentation for letter.

documentation for digit.

Inherited from:
character (hidden)
Source
character.scala
final val lower: Parsley[Char]

This parser tries to parse a lowercase letter, and returns it if successful.

This parser tries to parse a lowercase letter, and returns it if successful.

A lowercase letter is any character c <= '\uffff' whose Unicode Category Type is Lowercase Letter (Ll). Examples of characters within this category include:

  • the Latin letters 'a' through 'z'

  • Latin special character such as 'é', 'ß', 'ð'

  • Cryillic letters

  • Greek letters

  • Coptic letters

$categories

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val newline: Parsley[Char]

This parser tries to parse a line feed newline ('\n') character, and returns it if successful.

This parser tries to parse a line feed newline ('\n') character, and returns it if successful.

This parser will not accept a carriage return (CR) character or CRLF.

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val octDigit: Parsley[Char]

This parser tries to parse an octal digit, and returns it if successful.

This parser tries to parse an octal digit, and returns it if successful.

An octal digit is one of '0' to '7' (inclusive).

Attributes

See also
Inherited from:
character (hidden)
Source
character.scala
final val space: Parsley[Char]

This parser tries to parse a space or tab character, and returns it if successful.

This parser tries to parse a space or tab character, and returns it if successful.

Attributes

See also
Inherited from:
character (hidden)
Source
character.scala
final val tab: Parsley[Char]

This parser tries to parse a tab ('\t') character, and returns it if successful.

This parser tries to parse a tab ('\t') character, and returns it if successful.

This parser does not recognise vertical tabs, only horizontal ones.

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val upper: Parsley[Char]

This parser tries to parse an uppercase letter, and returns it if successful.

This parser tries to parse an uppercase letter, and returns it if successful.

An uppercase letter is any character c <= '\uffff' whose Unicode Category Type is Uppercase Letter (Lu). Examples of characters within this category include:

  • the Latin letters 'A' through 'Z'

  • Latin special character such as 'Ã…', 'Ç', 'Õ'

  • Cryillic letters

  • Greek letters

  • Coptic letters

$categories

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val whitespace: Parsley[Char]

This parser tries to parse a whitespace character, and returns it if successful.

This parser tries to parse a whitespace character, and returns it if successful.

A whitespace character is one of:

  1. a space (' ')

  2. a tab ('\t')

  3. a line feed ('\n')

  4. a carriage return ('\r')

  5. a form feed ('\f')

  6. a vertical tab ('\u000B')

Attributes

Inherited from:
character (hidden)
Source
character.scala

Conditional Combinators

These combinators will decide which branch to take next based on the result of another parser. This differs from combinators like | which make decisions based on the success/failure of a parser: here the result of a successful parse will direct which option is done. These are sometimes known as "selective" combinators.

final def branch[A, B, C](either: Parsley[Either[A, B]], left: => Parsley[A => C], right: => Parsley[B => C]): Parsley[C]

This combinator parses its first argument either, and then parses either left or right depending on its result.

This combinator parses its first argument either, and then parses either left or right depending on its result.

First, branch(either, left, right) parses either, which, if successful, will produce either a Left(x) or a Right(y). If a Left(x) is produced, the parser left is executed to produce a function f, and f(x) is returned. Otherwise, if a Right(y) is produced, the parser right is executed to produce a function g, and g(y) is returned. If either of the two executed parsers fail, the entire combinator fails.

First introduced in Selective Applicative Functors (Mokhov et al. 2019).

Value parameters

either

the first parser to execute, its result decides which parser to execute next.

left

a parser to execute if either returns a Left.

right

a parser to execute if either returns a Right.

Attributes

Returns

a parser that will parse one of left or right depending on either's result.

Example

def ifP[A](b: Parsley[Boolean], t: =>Parsley[A], e: =>Parsley[A]): Parsley[A] = {
   val cond = b.map {
       case true => Left(())
       case false => Right(())
   }
   branch(cond, t.map[Unit => A](x => _ => x), e.map[Unit => A](x => _ => x))
}
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala
final def select[A, B](p: Parsley[Either[A, B]], q: => Parsley[A => B]): Parsley[B]

This combinator parses its first argument p, then parses q only if p returns a Left.

This combinator parses its first argument p, then parses q only if p returns a Left.

First, select(p, q) parses p, which, if successful, will produce either a Left(x) or a Right(y). If a Left(x) is produced, then the parser q is executed to produce a function f, and f(x) is returned. Otherwise, if a Right(y) is produced, y is returned unmodified and q is not parsed. If either p or q fails, the entire combinator fails. This is a special case of branch where the right branch is pure(identity[B]).

First introduced in Selective Applicative Functors (Mokhov et al. 2019).

Value parameters

p

the first parser to execute, its result decides whether q is executed or not.

q

a parser to execute when p returns a Left.

Attributes

Returns

a parser that will parse p then possibly parse q to transform p's result into a B.

Example

def filter(pred: A => Boolean): Parsley[A] = {
   val p = this.map(x => if (pred(x)) Right(x) else Left(()))
   select(p, empty)
}
Inherited from:
ParsleyImpl (hidden)
Source
Parsley.scala

Multiple Branching/Sequencing Combinators

These combinators allow for testing or sequencing a large number of parsers in one go. Be careful, however, these are variadic combinators and are necessarily (for compatibility with Scala 2) not lazy. In such a case where laziness is desired without resorting to the other lazier combinators, there is a neat trick: unroll the first iteration of the combinator, and use the corresponding regular combinator to do that (i.e. <::> or *>): since these will have a lazy right-hand side, the remaining variadic arguments will be kept lazily suspended until later. Alternatively, it is possible to use the prefix ~ combinator to make any individual arguments lazy as required, for example skip(p, ~q, r).

final def choice[A](ps: Parsley[A]*): Parsley[A]

This combinator tries to parse each of the parsers ps in order, until one of them succeeds.

This combinator tries to parse each of the parsers ps in order, until one of them succeeds.

Finds the first parser in ps which succeeds, returning its result. If none of the parsers succeed, then this combinator fails. If a parser fails having consumed input, this combinator fails immediately.

Value parameters

ps

the parsers to try, in order.

Attributes

Returns

a parser that tries to parse one of ps.

See also

|

Example

scala> import parsley.combinator.choice
scala> import parsley.character.string
scala> val p = choice(string("abc"), string("ab"), string("bc"), string("d"))
scala> p.parse("abc")
val res0 = Success("abc")
scala> p.parse("ab")
val res1 = Failure(..)
scala> p.parse("bc")
val res2 = Success("bc")
scala> p.parse("x")
val res3 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def sequence[A](p0: Parsley[A], ps: Parsley[A]*): Parsley[List[A]]

This combinator will parse each of ps in order, collecting the results.

This combinator will parse each of ps in order, collecting the results.

Given the parsers ps, consisting of p1 through pn, parses each in order. If they all succeed, producing the results x1 through xn, then List(x1, .., xn) is returned. If any of the parsers fail, then the whole combinator fails.

Value parameters

p0

the first parser to be sequenced

ps

parsers to be sequenced.

Attributes

Returns

a parser that parses each of ps, returning the results in a list

See also
Since

4.0.0

Note

$strict

Example

scala> import parsley.combinator.sequence
scala> import parsley.character.{char, item}
scala> val p = sequence(char('a'), item, char('c'))
scala> p.parse("abc")
val res0 = Success(List('a', 'b', 'c'))
scala> p.parse("ab")
val res1 = Failure(..)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def traverse[A, B](x0: A, xs: A*)(f: A => Parsley[B]): Parsley[List[B]]

This combinator will parse each of the parsers generated by applying f to xs, in order, collecting the results.

This combinator will parse each of the parsers generated by applying f to xs, in order, collecting the results.

Given the values xs, consisting of x1 through xn, first creates the parses f(x1) through f(xn) and then called sequence on them.

Value parameters

f

the function used to generate parsers for each values

x0

the first value to turn into a parser and sequence.

xs

the values to turn into parsers and sequence.

Attributes

Returns

a parser that sequences the parsers generated from applying f to each of xs.

See also
Since

4.0.0

Note

$strict

Example

// this is an OK implementation for `string`, which is common in Haskell.
def string(str: String) = {
   traverse(str:  _*)(char).span
}
Inherited from:
combinator (hidden)
Source
combinator.scala

Range Combinators

These combinators allow for the parsing of a specific parser either a specific number of times, or between a certain amount of times.

final def count(min: Int, max: Int)(p: Parsley[_]): Parsley[Int]

This combinator parses between min and max occurrences of p, returning the number of successes.

This combinator parses between min and max occurrences of p, returning the number of successes.

Parses p repeatedly a minimum of min times and up to max times both inclusive. If p fails before min is reached, then this combinator fails. It is not required for p to fail after the maxth parse. The results are discarded and the number of successful parses of p, n, is returned instead, such that min <= n <= max.

Value parameters

max

the maximum number of times to repeat p, inclusive.

min

the minimum number of times to repeat p, inclusive.

p

the parser to repeat.

Attributes

Returns

the number of times p parsed successfully.

Since

4.4.0

Example

scala> import parsley.character.item
scala> import parsley.combinator.count
scala> val p = count(min=3, max=5)(item)
scala> p.parse("ab")
val res0 = Failure(..)
scala> p.parse("abc")
val res1 = Success(3)
scala> p.parse("abcd")
val res2 = Success(4)
scala> p.parse("abcde")
val res2 = Success(5)
scala> p.parse("abcdef")
val res2 = Success(5)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def exactly[A](n: Int, p: Parsley[A]): Parsley[List[A]]

This combinator parses exactly n occurrences of p, returning these n results in a list.

This combinator parses exactly n occurrences of p, returning these n results in a list.

Parses p repeatedly up to n times. If p fails before n is reached, then this combinator fails. It is not required for p to fail after the nth parse. The results produced by p, x1 through xn, are returned as List(x1, .., xn).

Value parameters

n

the number of times to repeat p.

p

the parser to repeat.

Attributes

Returns

a parser that parses p exactly n times, returning a list of the results.

Since

4.0.0

Example

scala> import parsley.character.item
scala> import parsley.combinator.exactly
scala> val p = exactly(3, item)
scala> p.parse("ab")
val res0 = Failure(..)
scala> p.parse("abc")
val res1 = Success(List('a', 'b', 'c'))
scala> p.parse("abcd")
val res2 = Success(List('a', 'b', 'c'))
Inherited from:
combinator (hidden)
Source
combinator.scala
final def range[A](min: Int, max: Int)(p: Parsley[A]): Parsley[List[A]]

This combinator parses between min and max occurrences of p, returning these n results in a list.

This combinator parses between min and max occurrences of p, returning these n results in a list.

Parses p repeatedly a minimum of min times and up to max times both inclusive. If p fails before min is reached, then this combinator fails. It is not required for p to fail after the maxth parse. The results produced by p, xmin through xmax, are returned as List(xmin, .., xmax).

Value parameters

max

the maximum number of times to repeat p, inclusive.

min

the minimum number of times to repeat p, inclusive.

p

the parser to repeat.

Attributes

Returns

the results of the successful parses of p.

Since

4.4.0

Example

scala> import parsley.character.item
scala> import parsley.combinator.range
scala> val p = range(min=3, max=5)(item)
scala> p.parse("ab")
val res0 = Failure(..)
scala> p.parse("abc")
val res1 = Success(List('a', 'b', 'c'))
scala> p.parse("abcd")
val res2 = Success(List('a', 'b', 'c', 'd'))
scala> p.parse("abcde")
val res2 = Success(List('a', 'b', 'c', 'd', 'e'))
scala> p.parse("abcdef")
val res2 = Success(List('a', 'b', 'c', 'd', 'e'))
Inherited from:
combinator (hidden)
Source
combinator.scala

Whitespace Skipping Parsers

These parsers are designed to skip chunks of whitespace, for very rudimentary lexing tasks. It is probably better to use the functionality of parsley.token.

final val spaces: Parsley[Unit]

This parser skips zero or more space characters using space.

This parser skips zero or more space characters using space.

Attributes

Inherited from:
character (hidden)
Source
character.scala
final val whitespaces: Parsley[Unit]

This parser skips zero or more space characters using whitespace.

This parser skips zero or more space characters using whitespace.

Attributes

Inherited from:
character (hidden)
Source
character.scala

Character Predicates

These are useful for providing to the sub-descriptions of a token.descriptions.LexicalDesc to specify behaviour for the lexer. Other than that, they aren't particularly useful.

final def isHexDigit(c: Char): Boolean

This function returns true if a character is a hexadecimal digit.

This function returns true if a character is a hexadecimal digit.

A hexadecimal digit is one of (all inclusive ranges):

  1. the digits '0' through '9'

  2. the letters 'a' through 'f'

  3. the letters 'A' through 'Z'

  4. an equivalent from another charset

Attributes

See also
Inherited from:
character (hidden)
Source
character.scala
final def isOctDigit(c: Char): Boolean

This function returns true if a character is an octal digit.

This function returns true if a character is an octal digit.

An octal digit is one of '0' to '7' (inclusive).

Attributes

See also
Inherited from:
character (hidden)
Source
character.scala
final def isSpace(c: Char): Boolean

This function returns true if a character is either a space or a tab character.

This function returns true if a character is either a space or a tab character.

Attributes

See also
Inherited from:
character (hidden)
Source
character.scala

condComp

final def decide[A](p: Parsley[Option[A]], q: => Parsley[A]): Parsley[A]

This combinator parses q depending only if p returns a None.

This combinator parses q depending only if p returns a None.

First parses p. If p returned Some(x), then x is returned. Otherwise, if p returned None then q is parsed, producing y, and y is returned. If p or q fails, the combinator fails.

Value parameters

p

the first parser, which returns an Option to eliminate.

q

a parser to execute when p returns None, to provide a value of type A.

Attributes

Returns

a parser that either just parses p or both p and q in order to return an A.

Example

decide(option(p), q) = p | q
Inherited from:
combinator (hidden)
Source
combinator.scala
final def decide[A](p: Parsley[Option[A]]): Parsley[A]

This combinator can eliminate an Option from the result of the parser p.

This combinator can eliminate an Option from the result of the parser p.

First parse p, if it succeeds returning Some(x), then return x. However, if p fails, or returned None, then this combinator fails.

Value parameters

p

the parser to parse and extract the result from.

Attributes

Returns

a parser that tries to extract the result from p.

Example

decide(option(p)) = p
Inherited from:
combinator (hidden)
Source
combinator.scala
final def guardS(p: Parsley[Boolean]): Parsley[Unit]

This combinator verfies that the given parser returns true, or else fails.

This combinator verfies that the given parser returns true, or else fails.

First, parse p; if it succeeds then, so long at returns true, this guard(p) succeeds. Otherwise, if p either fails, or returns false, guard(p) will fail.

Value parameters

p

the parser that yields the condition value.

Attributes

Example

guard(pure(true)) == unit
guard(pure(false)) == empty
when(p.map(!_), empty) == guardS(p)
Inherited from:
combinator (hidden)
Source
combinator.scala
final def ifS[A](condP: Parsley[Boolean], thenP: => Parsley[A], elseP: => Parsley[A]): Parsley[A]

This combinator parses one of thenP or elseP depending on the result of parsing condP.

This combinator parses one of thenP or elseP depending on the result of parsing condP.

This is a lifted if-statement. First, parse condP: if it is successful and returns true, then parse thenP; else, if it returned false, parse elseP; or, if condP failed then fail. If either of thenP or elseP fail, then this combinator also fails.

Most useful in conjunction with Registers, as this allows for decisions to be made based on state.

Value parameters

condP

the parser that yields the condition value.

elseP

the parser to execute if the condition is false.

thenP

the parser to execute if the condition is true.

Attributes

Returns

a parser that conditionally parses thenP or elseP after condP.

Since

4.5.0

Example

ifS(pure(true), p, _) == p
ifS(pure(false), _, p) == p
Inherited from:
combinator (hidden)
Source
combinator.scala

This combinator conditionally parses thenP depending on the result of parsing condP.

This combinator conditionally parses thenP depending on the result of parsing condP.

This is a lifted if-statement. First, parse condP: if it is successful and returns true, then parse thenP; else, if it returned false do nothing; or, if condP failed then fail. If thenP fails, then this combinator also fails.

Most useful in conjunction with Registers, as this allows for decisions to be made based on state.

Value parameters

condP

the parser that yields the condition value.

thenP

the parser to execute if the condition is true.

Attributes

Returns

a parser that conditionally parses thenP after condP.

Example

whenS(pure(true), p) == p
whenS(pure(false), _) == unit
Inherited from:
combinator (hidden)
Source
combinator.scala
final def whileS(p: Parsley[Boolean]): Parsley[Unit]

This combinator repeatedly parses p so long as it returns true.

This combinator repeatedly parses p so long as it returns true.

This is a lifted while-loop. First, parse p: if it is successful and returns true, then repeat; else if it returned false stop; or, if it failed then this combinator fails.

Most useful in conjunction with Registers, as this allows for decisions to be made based on state. In particular, this can be used to define the forP combinator.

Value parameters

p

the parser to repeatedly parse.

Attributes

Returns

a parser that continues to parse p until it returns false.

Example

def forP[A](init: Parsley[A], cond: =>Parsley[A => Boolean], step: =>Parsley[A => A])(body: =>Parsley[_]): Parsley[Unit] = {
   val reg = Reg.make[A]
   lazy val _cond = reg.gets(cond)
   lazy val _step = reg.modify(step)
   reg.put(init) ~> whenS(_cond, whileS(body ~> _step ~> _cond))
}
Inherited from:
combinator (hidden)
Source
combinator.scala

Type members

Types

type Parsley[+A] = Parsley[A]

Attributes

Source
quick.scala

Value members

Inherited methods

final def ap1[T1, R](pf: Parsley[T1 => R], p1: => Parsley[T1]): Parsley[R]

This combinator allows the function that results from one parser to be applied to the result of another parser.

This combinator allows the function that results from one parser to be applied to the result of another parser.

Effectively alias for <*>, to be consistent with the other ap variants.

Value parameters

pf

the parser whose result is a function to map across the result of p1.

px

the second parser to perform.

Attributes

Returns

a parser that applies the function f resulting from pf to the result x of the parser p1.

Inherited from:
ap (hidden)
Source
ap.scala
final def ap10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp ten.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp eleven.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp twelve.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp thirteen.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp fourteen.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp fifteen.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp sixteen.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp seventeen.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp eighteen.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp nineteen.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap2[T1, T2, R](pf: Parsley[(T1, T2) => R], p1: => Parsley[T1], p2: => Parsley[T2]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp two.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19], p20: => Parsley[T20]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp twenty.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19], p20: => Parsley[T20], p21: => Parsley[T21]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp twenty-one.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19], p20: => Parsley[T20], p21: => Parsley[T21], p22: => Parsley[T22]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp twenty-two.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap3[T1, T2, T3, R](pf: Parsley[(T1, T2, T3) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp three.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap4[T1, T2, T3, T4, R](pf: Parsley[(T1, T2, T3, T4) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp four.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap5[T1, T2, T3, T4, T5, R](pf: Parsley[(T1, T2, T3, T4, T5) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp five.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap6[T1, T2, T3, T4, T5, T6, R](pf: Parsley[(T1, T2, T3, T4, T5, T6) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp six.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap7[T1, T2, T3, T4, T5, T6, T7, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp seven.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap8[T1, T2, T3, T4, T5, T6, T7, T8, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp eight.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def ap9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](pf: Parsley[(T1, T2, T3, T4, T5, T6, T7, T8, T9) => R], p1: => Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9]): Parsley[R]

$bodyAp

$bodyAp

Value parameters

pf

$paramAp nine.

Attributes

Returns

$returnAp

Inherited from:
ap (hidden)
Source
ap.scala
final def lift1[T1, R](f: T1 => R, p1: Parsley[T1]): Parsley[R]

This combinator allows the result of a given parser to be changed using a given function.

This combinator allows the result of a given parser to be changed using a given function.

Effectively alias for map, to be consistent with the other lift variants.

Value parameters

f

the function to map across the given parser

Attributes

Returns

a parser that applies the function f to the result of the given parser.

Inherited from:
lift (hidden)
Source
lift.scala
final def lift10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift ten.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift eleven.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift twelve.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift thirteen.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift fourteen.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift fifteen.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift sixteen.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift seventeen.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift eighteen.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift nineteen.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift2[T1, T2, R](f: (T1, T2) => R, p1: Parsley[T1], p2: => Parsley[T2]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift two.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19], p20: => Parsley[T20]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift twenty.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19], p20: => Parsley[T20], p21: => Parsley[T21]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift twenty-one.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9], p10: => Parsley[T10], p11: => Parsley[T11], p12: => Parsley[T12], p13: => Parsley[T13], p14: => Parsley[T14], p15: => Parsley[T15], p16: => Parsley[T16], p17: => Parsley[T17], p18: => Parsley[T18], p19: => Parsley[T19], p20: => Parsley[T20], p21: => Parsley[T21], p22: => Parsley[T22]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift twenty-two.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift3[T1, T2, T3, R](f: (T1, T2, T3) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift three.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift4[T1, T2, T3, T4, R](f: (T1, T2, T3, T4) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift four.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift5[T1, T2, T3, T4, T5, R](f: (T1, T2, T3, T4, T5) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift five.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift6[T1, T2, T3, T4, T5, T6, R](f: (T1, T2, T3, T4, T5, T6) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift six.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift7[T1, T2, T3, T4, T5, T6, T7, R](f: (T1, T2, T3, T4, T5, T6, T7) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift seven.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift8[T1, T2, T3, T4, T5, T6, T7, T8, R](f: (T1, T2, T3, T4, T5, T6, T7, T8) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift eight.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def lift9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => R, p1: Parsley[T1], p2: => Parsley[T2], p3: => Parsley[T3], p4: => Parsley[T4], p5: => Parsley[T5], p6: => Parsley[T6], p7: => Parsley[T7], p8: => Parsley[T8], p9: => Parsley[T9]): Parsley[R]

$bodyLift

$bodyLift

Value parameters

f

$paramLift nine.

Attributes

Returns

$returnLift

Inherited from:
lift (hidden)
Source
lift.scala
final def withWidth[A](p: Parsley[A]): Parsley[(A, Int)]

This combinator returns the result of a given parser and the number of characters it consumed.

This combinator returns the result of a given parser and the number of characters it consumed.

First records the initial offset on entry to given parser p, then executes p. If p succeeds, then the offset is taken again, and the two values are subtracted to give width w. The result of p, x is returned along with w as (x, w). If p fails, this combinator will also fail.

Value parameters

p

the parser to compute the width for

Attributes

Returns

a parser that pairs the result of the parser p with the number of characters it consumed

Since

4.4.0

Note

the value returned is the number of 16-bit characters consumed, not unicode codepoints.

Example

scala> import parsley.position.withWidth, parsley.character.string
scala> withWidth(string("abc")).parse("abc")
val res0 = Success(("abc", 3))
Inherited from:
position (hidden)
Source
position.scala

Inherited fields

final val col: Parsley[Int]

This parser returns the current column number (starting at 1) of the input without having any other effect.

This parser returns the current column number (starting at 1) of the input without having any other effect.

When this combinator is ran, no input is required, nor consumed, and the current column number will always be successfully returned. It has no other effect on the state of the parser.

Attributes

Returns

a parser that returns the column number the parser is currently at.

Note

in the presence of wide unicode characters, the value returned may be inaccurate.

Example

scala> import parsley.position.col, parsley.character.char
scala> col.parse("")
val res0 = Success(1)
scala> (char('a') ~> col).parse("a")
val res0 = Success(2)
scala> (char('\n') ~> col).parse("\n")
val res0 = Success(1)
Inherited from:
position (hidden)
Source
position.scala
final val line: Parsley[Int]

This parser returns the current line number (starting at 1) of the input without having any other effect.

This parser returns the current line number (starting at 1) of the input without having any other effect.

When this combinator is ran, no input is required, nor consumed, and the current line number will always be successfully returned. It has no other effect on the state of the parser.

Attributes

Returns

a parser that returns the line number the parser is currently at.

Example

scala> import parsley.position.line, parsley.character.char
scala> line.parse("")
val res0 = Success(1)
scala> (char('a') ~> line).parse("a")
val res0 = Success(1)
scala> (char('\n') ~> line).parse("\n")
val res0 = Success(2)
Inherited from:
position (hidden)
Source
position.scala
final val offset: Parsley[Int]

This parser returns the current offset into the input (starting at 0) without having any other effect.

This parser returns the current offset into the input (starting at 0) without having any other effect.

When this combinator is ran, no input is required, nor consumed, and the current offset into the input will always be successfully returned. It has no other effect on the state of the parser.

Attributes

Returns

a parser that returns the offset the parser is currently at.

Note

offset does not take wide unicode codepoints into account.

Example

scala> import parsley.position.offset, parsley.character.char
scala> offset.parse("")
val res0 = Success(0)
scala> (char('a') ~> offset).parse("a")
val res0 = Success(1)
scala> (char('\n') ~> offset).parse("\n")
val res0 = Success(1)
Inherited from:
position (hidden)
Source
position.scala
final val pos: Parsley[(Int, Int)]

This parser returns the current line and column numbers (starting at 1) of the input without having any other effect.

This parser returns the current line and column numbers (starting at 1) of the input without having any other effect.

When this combinator is ran, no input is required, nor consumed, and the current line and column number will always be successfully returned. It has no other effect on the state of the parser.

Attributes

Returns

a parser that returns the line and column number the parser is currently at.

Note

in the presence of wide unicode characters, the column value returned may be inaccurate.

Example

scala> import parsley.position.pos, parsley.character.char
scala> pos.parse("")
val res0 = Success((1, 1))
scala> (char('a') ~> pos).parse("a")
val res0 = Success((1, 2))
scala> (char('\n') ~> pos).parse("\n")
val res0 = Success((2, 1))
Inherited from:
position (hidden)
Source
position.scala