← ZIO Parser docs

Parser

zio.parser.Parser
See theParser companion object
sealed trait Parser[+Err, -In, +Result] extends VersionSpecificParser[Err, In, Result]

A Parser consumes a stream of 'In's and either fails with a ParserError possibly holding a custom error of type 'Err' or succeeds with a result of type Result

Parsers can be combined with Printers to get Syntax, or a Parser and a Printer can be built simultaneously by using the combinators of Syntax.

Recursive parsers can be expressed directly by recursing in one of the zipping or or-else combinators.

By default a parser backtracks automatically. This behavior can be changed with the 'manualBacktracking' operator.

Parsers trees get optimized automatically before running the parser. This optimized tree can be examined by the 'optimized' field. For the full list of transformations performed in the optimization phase check each parser node's 'optimizeNode' method.

Type parameters

Err

Custom error type

In

Element type of the input stream of parsing

Result

The type of the parsed result value

Attributes

Companion
object
Source
Parser.scala
Graph
Supertypes
trait VersionSpecificParser[Err, In, Result]
class Object
trait Matchable
class Any
Known subtypes
class Backtrack[Err, In, Result]
class CaptureString[Err, Err2]
object End
class Fail[Err]
class Failed[Err]
class FlatMap[Err, Err2, In, In2, Result, Result2]
class Ignore[Err, Err2, In, Result, Result2]
object Index
class Lazy[Err, In, Result]
class MapError[Err, Err2, In, Result]
class Named[Err, In, Result]
class Not[Err, In]
class Optional[Err, In, Result]
class OrElse[Err, Err2, In, In2, Result, Result2]
class OrElseEither[Err, Err2, In, In2, Result, Result2]
class ParseRegex[Err]
class ParseRegexLastChar[Err]
class Passthrough[D1, D2]
class Repeat[Err, In, Result]
class SetAutoBacktrack[Err, In, Result]
class SkipRegex[Err]
class Succeed[Result]
class Transform[Err, Err2, In, Result, Result2]
class TransformEither[Err, Err2, In, Result, Result2]
class Zip[Err, Err2, In, In2, Result, Result2, ZippedResult]
class ZipLeft[Err, Err2, In, In2, Result]
class ZipRight[Err, Err2, In, In2, Result, Result2]
Show all
Self type
Parser[Err, In, Result]

Members list

Value members

Concrete methods

final def *: Parser[Err, In, Chunk[Result]]

Symbolic alias for repeat0

Symbolic alias for repeat0

Attributes

Source
Parser.scala
final def +: Parser[Err, In, Chunk[Result]]

Symbolic alias for repeat

Symbolic alias for repeat

Attributes

Source
Parser.scala
final def <+>[Err2 >: Err, In2 <: In, Result2](that: => Parser[Err2, In2, Result2]): Parser[Err2, In2, Either[Result, Result2]]

Symbolic alias for orElseEither

Symbolic alias for orElseEither

Attributes

Source
Parser.scala
def <=>[Out](that: Printer[Err, Out, Value]): Syntax[Err, In, Out, Value]
Implicitly added by ParserOps

Combines this parser with that printer to get a syntax.

Combines this parser with that printer to get a syntax.

This operation enables the use of parser or printer-specific operators to build up fragments of a syntax. The resulting syntax can be used as a building block to create bigger syntaxes.

Attributes

Source
package.scala
final def <>[Err2 >: Err, In2 <: In, Result2 >: Result](that: => Parser[Err2, In2, Result2]): Parser[Err2, In2, Result2]

Symbolic alias for orElse

Symbolic alias for orElse

Attributes

Source
Parser.scala
final def <~[Err2 >: Err, In2 <: In, Result2](that: => Parser[Err2, In2, Unit]): Parser[Err2, In2, Result]

Symbolic alias for zipLeft

Symbolic alias for zipLeft

Attributes

Source
Parser.scala
final def ?: Parser[Err, In, Option[Result]]

Symbolic alias for optional

Symbolic alias for optional

Attributes

Source
Parser.scala
final def ??(name: String): Parser[Err, In, Result]

Symbolic alias for named

Symbolic alias for named

Attributes

Source
Parser.scala
final def as[Result2](result: Result2): Parser[Err, In, Result2]

Ignores the parser's successful result and result in 'result' instead

Ignores the parser's successful result and result in 'result' instead

Attributes

Source
Parser.scala
final def atLeast(min: Int): Parser[Err, In, Chunk[Result]]

Repeats this parser at least 'min' times.

Repeats this parser at least 'min' times.

The result is all the parsed elements until the first failure. The failure that stops the repetition gets swallowed and in case auto-backtracking is on, the parser backtracks to the end of the last successful item.

Attributes

Source
Parser.scala
final def autoBacktracking: Parser[Err, In, Result]

Enables auto-backtracking for this parser

Enables auto-backtracking for this parser

Attributes

Source
Parser.scala
final def backtrack: Parser[Err, In, Result]

Parser that resets the parsing position in case it fails.

Parser that resets the parsing position in case it fails.

By default backtracking points are automatically inserted. This behavior can be changed with the autoBacktracking, manualBacktracking and setAutoBacktracking combinators.

Attributes

Source
Parser.scala
final def between[Err2 >: Err, In2 <: In](left: Parser[Err2, In2, Any], right: Parser[Err2, In2, Any]): Parser[Err2, In2, Result]

Concatenates the parsers 'left', then this, then 'right'.

Concatenates the parsers 'left', then this, then 'right'.

All three must succeed. The result is this parser's result.

Attributes

Source
Parser.scala
final def exactly(n: Int): Parser[Err, In, Chunk[Result]]

Repeats this parser exactly N times

Repeats this parser exactly N times

Attributes

Source
Parser.scala
final def filter[Result2, Err2 >: Err](condition: Result2 => Boolean, failure: Err2)(implicit ev: Result <:< Result2): Parser[Err2, In, Result2]

Checks the result of this parser with the given function. If the 'condition' is false, fails with the given failure 'failure', otherwise results in the this parser's result.

Checks the result of this parser with the given function. If the 'condition' is false, fails with the given failure 'failure', otherwise results in the this parser's result.

Attributes

Source
Parser.scala
final def flatMap[Err2 >: Err, In2 <: In, Result2](that: Result => Parser[Err2, In2, Result2]): Parser[Err2, In2, Result2]

Determines the continuation of the parser by the result of this parser, expressed by the function 'that'

Determines the continuation of the parser by the result of this parser, expressed by the function 'that'

Attributes

Source
Parser.scala
final def flatten(implicit ev2: Result <:< Chunk[String]): Parser[Err, In, String]

Flattens a result of parsed strings to a single string

Flattens a result of parsed strings to a single string

Attributes

Source
Parser.scala
final def manualBacktracking: Parser[Err, In, Result]

Turns off auto-backtracking for this parser

Turns off auto-backtracking for this parser

Attributes

Source
Parser.scala
final def map[Result2](to: Result => Result2): Parser[Err, In, Result2]

Maps the parser's successful result with the given function 'to'

Maps the parser's successful result with the given function 'to'

Attributes

Source
Parser.scala
final def mapError[Err2](f: Err => Err2): Parser[Err2, In, Result]

Maps the error with the given function 'f'

Maps the error with the given function 'f'

Attributes

Source
Parser.scala
final def named(name: String): Parser[Err, In, Result]

Associates a name with this parser. The chain of named parsers are reported in case of failure to help debugging parser issues.

Associates a name with this parser. The chain of named parsers are reported in case of failure to help debugging parser issues.

Attributes

Source
Parser.scala
final def not[Err2 >: Err](failure: => Err2): Parser[Err2, In, Unit]

Parser that fails with the given 'failure' if this parser succeeds

Parser that fails with the given 'failure' if this parser succeeds

Attributes

Source
Parser.scala
final def optional: Parser[Err, In, Option[Result]]

Make this parser optional.

Make this parser optional.

Failure of this parser will be ignored. In case auto-backtracking is enabled, backtracking is performed on it.

Attributes

Source
Parser.scala
final def orElse[Err2 >: Err, In2 <: In, Result2 >: Result](that: => Parser[Err2, In2, Result2]): Parser[Err2, In2, Result2]

Assigns 'that' parser as a fallback of this. First this parser gets evaluated. In case it succeeds, the result is this parser's result. In case it fails, the result is 'that' parser's result.

Assigns 'that' parser as a fallback of this. First this parser gets evaluated. In case it succeeds, the result is this parser's result. In case it fails, the result is 'that' parser's result.

If auto-backtracking is on, this parser will backtrack before trying 'that' parser.

Attributes

Source
Parser.scala
final def orElseEither[Err2 >: Err, In2 <: In, Result2](that: => Parser[Err2, In2, Result2]): Parser[Err2, In2, Either[Result, Result2]]

Assigns 'that' parser as a fallback of this. First this parser gets evaluated. In case it succeeds, the result is this parser's result wrapped in 'Left'. In case it fails, the result is 'that' parser's result, wrapped in 'Right'.

Assigns 'that' parser as a fallback of this. First this parser gets evaluated. In case it succeeds, the result is this parser's result wrapped in 'Left'. In case it fails, the result is 'that' parser's result, wrapped in 'Right'.

Compared to orElse, this version allows the two parsers to have different result types.

If auto-backtracking is on, this parser will backtrack before trying 'that' parser.

Attributes

Source
Parser.scala
final def parseChars(input: Chunk[Char])(implicit ev: Char <:< In): Either[StringParserError[Err], Result]

Run this parser on the given 'input' chunk of characters

Run this parser on the given 'input' chunk of characters

Attributes

Source
Parser.scala
final def parseChars(input: Chunk[Char], parserImplementation: ParserImplementation)(implicit ev: Char <:< In): Either[StringParserError[Err], Result]

Run this parser on the given 'input' chunk of characters using a specific parser implementation

Run this parser on the given 'input' chunk of characters using a specific parser implementation

Attributes

Source
Parser.scala
final def parseChunk[In0 <: In](input: Chunk[In0])(implicit stateSelector: StateSelector[In0]): Either[ParserError[Err], Result]

Run this parser on the given 'input' chunk

Run this parser on the given 'input' chunk

Attributes

Source
Parser.scala
final def parseString(input: String)(implicit ev: Char <:< In): Either[StringParserError[Err], Result]

Run this parser on the given 'input' string

Run this parser on the given 'input' string

Attributes

Source
Parser.scala
final def parseString(input: String, parserImplementation: ParserImplementation)(implicit ev: Char <:< In): Either[StringParserError[Err], Result]

Run this parser on the given 'input' string using a specific parser implementation

Run this parser on the given 'input' string using a specific parser implementation

Attributes

Source
Parser.scala
final def repeat: Parser[Err, In, Chunk[Result]]

Repeats this parser at least once.

Repeats this parser at least once.

The result is all the parsed elements until the first failure. The failure that stops the repetition gets swallowed and in case auto-backtracking is on, the parser backtracks to the end of the last successful item.

Attributes

Source
Parser.scala
final def repeat0: Parser[Err, In, Chunk[Result]]

Repeats this parser zero or more times.

Repeats this parser zero or more times.

The result is all the parsed elements until the first failure. The failure that stops the repetition gets swallowed and in case auto-backtracking is on, the parser backtracks to the end of the last successful item.

Attributes

Source
Parser.scala
final def repeatUntil[Err2 >: Err, In2 <: In](stopCondition: Parser[Err2, In2, Any]): Parser[Err2, In2, Chunk[Result]]

Repeats this parser until the given stopCondition parser succeeds.

Repeats this parser until the given stopCondition parser succeeds.

Attributes

Source
Parser.scala
final def repeatWithSep[Err2 >: Err, In2 <: In](sep: Parser[Err2, In2, Unit]): Parser[Err2, In2, Chunk[Result]]

Repeats this parser at least once and requires that between each element, the 'sep' parser succeeds

Repeats this parser at least once and requires that between each element, the 'sep' parser succeeds

Attributes

Source
Parser.scala
final def repeatWithSep0[Err2 >: Err, In2 <: In](sep: Parser[Err2, In2, Unit]): Parser[Err2, In2, Chunk[Result]]

Repeats this parser zero or more times and requires that between each element, the 'sep' parser succeeds

Repeats this parser zero or more times and requires that between each element, the 'sep' parser succeeds

Attributes

Source
Parser.scala
final def setAutoBacktracking(enabled: Boolean): Parser[Err, In, Result]

Enables or disables auto-backtracking for this parser

Enables or disables auto-backtracking for this parser

Attributes

Source
Parser.scala
final def string(implicit ev: Char <:< In): Parser[Err, Char, String]

Ignores this parser's result and instead capture the parsed string fragment

Ignores this parser's result and instead capture the parsed string fragment

Attributes

Source
Parser.scala
def strip: Parser[Err, In, Result]

Strips all the name information from this parser to improve performance but reduces the failure message's verbosity.

Strips all the name information from this parser to improve performance but reduces the failure message's verbosity.

Attributes

Source
Parser.scala
final def surroundedBy[Err2 >: Err, In2 <: In](other: Parser[Err2, In2, Any]): Parser[Err2, In2, Result]

Surrounds this parser with the 'other' parser. The result is this parser's result.

Surrounds this parser with the 'other' parser. The result is this parser's result.

Attributes

Source
Parser.scala
def to[Result2 <: Product](implicit conversion: TupleConversion[Result2, Result]): Parser[Err, In, Result2]
Implicitly added by TupleParserOps

Maps the parser's successful tuple result to the given case class

Maps the parser's successful tuple result to the given case class

Attributes

Source
package.scala
final def transformEither[Err2, Result2](to: Result => Either[Err2, Result2]): Parser[Err2, In, Result2]

Maps the parser's successful result with the given function 'to' that either fails or produces a new result value.

Maps the parser's successful result with the given function 'to' that either fails or produces a new result value.

Attributes

Source
Parser.scala
final def transformOption[Result2](to: Result => Option[Result2]): Parser[Option[Err], In, Result2]

Maps the parser's successful result with the given function 'to' that either produces a new result value or the failure is indicated in the error channel by the value None.

Maps the parser's successful result with the given function 'to' that either produces a new result value or the failure is indicated in the error channel by the value None.

Attributes

Source
Parser.scala
final def unit: Parser[Err, In, Unit]

Parser that does not consume any input and produces the unit value

Parser that does not consume any input and produces the unit value

Attributes

Source
Parser.scala
final def zip[Err2 >: Err, In2 <: In, Result2, ZippedResult](that: => Parser[Err2, In2, Result2])(implicit zippable: Out[Result, Result2, ZippedResult]): Parser[Err2, In2, ZippedResult]

Concatenates this parser with 'that' parser. In case both parser succeeds, the result is a pair of the results.

Concatenates this parser with 'that' parser. In case both parser succeeds, the result is a pair of the results.

Attributes

Source
Parser.scala
final def zipLeft[Err2 >: Err, In2 <: In, Result2](that: => Parser[Err2, In2, Any]): Parser[Err2, In2, Result]

Concatenates this parser with 'that' parser. In case both parser succeeds, the result is the result of this parser. Otherwise the parser fails.

Concatenates this parser with 'that' parser. In case both parser succeeds, the result is the result of this parser. Otherwise the parser fails.

Attributes

Source
Parser.scala
def zipRight[Err2 >: Err, In2 <: In, Result](that: => Parser[Err2, In2, Result]): Parser[Err2, In2, Result]
Implicitly added by AnyParserOps

Concatenates this parser with that parser, and if both succeeds, discard the first result and use the second.

Concatenates this parser with that parser, and if both succeeds, discard the first result and use the second.

Attributes

Source
package.scala
final def |[Err2 >: Err, In2 <: In, Result2 >: Result](that: => Parser[Err2, In2, Result2]): Parser[Err2, In2, Result2]

Symbolic alias for orElse

Symbolic alias for orElse

Attributes

Source
Parser.scala
final def ~[Err2 >: Err, In2 <: In, Result2, ZippedResult](that: => Parser[Err2, In2, Result2])(implicit zippable: Out[Result, Result2, ZippedResult]): Parser[Err2, In2, ZippedResult]

Symbolic alias for zip

Symbolic alias for zip

Attributes

Source
Parser.scala
def ~>[Err2 >: Err, In2 <: In, Result](that: => Parser[Err2, In2, Result]): Parser[Err2, In2, Result]
Implicitly added by AnyParserOps

Symbolic alias for zipRight

Symbolic alias for zipRight

Attributes

Source
package.scala

Inherited methods

final def orElseU[Err2 >: Err, In2 <: In, Result2](that: => Parser[Err2, In2, Result2]): Parser[Err2, In2, Result | Result2]

Assigns 'that' parser as a fallback of this. First this parser gets evaluated. In case it succeeds, the result is this parser's result. In case it fails, the result is 'that' parser's result.

Assigns 'that' parser as a fallback of this. First this parser gets evaluated. In case it succeeds, the result is this parser's result. In case it fails, the result is 'that' parser's result.

If auto-backtracking is on, this parser will backtrack before trying 'that' parser.

Attributes

Inherited from:
VersionSpecificParser
Source
VersionSpecificParser.scala

Concrete fields

Attributes

Source
Parser.scala
lazy val optimized: Parser[Err, In, Result]

The optimized parser tree used by the parser implementations

The optimized parser tree used by the parser implementations

Attributes

Source
Parser.scala