Syntax

zio.parser.Syntax
See theSyntax companion object
class Syntax[+Err, -In, +Out, Value] extends VersionSpecificSyntax[Err, In, Out, Value]

Syntax defines a parser and a printer together and provides combinators to simultaneously build them up from smaller syntax fragments.

Type parameters

Err

Custom error type

In

Element type of the input stream of parsing

Out

Element type of the output stream of printing

Value

The type of the value to be parsed or printed

Attributes

Companion
object
Graph
Supertypes
trait VersionSpecificSyntax[Err, In, Out, Value]
class Object
trait Matchable
class Any
Self type
Syntax[Err, In, Out, Value]

Members list

Value members

Concrete methods

final def *: Syntax[Err, In, Out, Chunk[Value]]

Symbolic alias for repeat0

Symbolic alias for repeat0

Attributes

final def +: Syntax[Err, In, Out, Chunk[Value]]

Symbolic alias for repeat

Symbolic alias for repeat

Attributes

final def <+>[Err2 >: Err, In2 <: In, Out2 >: Out, Value2](that: => Syntax[Err2, In2, Out2, Value2]): Syntax[Err2, In2, Out2, Either[Value, Value2]]

Symbolic alias for orElseEither

Symbolic alias for orElseEither

Attributes

final def <>[Err2 >: Err, In2 <: In, Out2 >: Out](that: => Syntax[Err2, In2, Out2, Value]): Syntax[Err2, In2, Out2, Value]

Symbolic alias for orElse

Symbolic alias for orElse

Attributes

final def <~[Err2 >: Err, In2 <: In, Out2 >: Out](that: => Syntax[Err2, In2, Out2, Unit]): Syntax[Err2, In2, Out2, Value]

Symbolic alias for zipLeft

Symbolic alias for zipLeft

Attributes

final def ?: Syntax[Err, In, Out, Option[Value]]

Symbolic alias for optional

Symbolic alias for optional

Attributes

final def ??(name: String): Syntax[Err, In, Out, Value]

Symbolic alias for named

Symbolic alias for named

Attributes

def as[Value2](value: => Value2): Syntax[Err, In, Out, Value2]
Implicitly added by AnySyntaxOps

Ignores the result of the syntax and result in 'value' instead

Ignores the result of the syntax and result in 'value' instead

Attributes

final def asPrinted[Value2](result: Value2, value: Value): Syntax[Err, In, Out, Value2]

Sets the result to 'result' and the value to be printed to 'value'

Sets the result to 'result' and the value to be printed to 'value'

Attributes

final def atLeast(min: Int): Syntax[Err, In, Out, Chunk[Value]]

This syntax repeated at least 'min' times.

This syntax repeated 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.

When printing, the input is a chunk of values and each element gets printed.

Attributes

final def autoBacktracking: Syntax[Err, In, Out, Value]

Enables auto-backtracking for this syntax

Enables auto-backtracking for this syntax

Attributes

def backtrack: Syntax[Err, In, Out, Value]

Syntax that resets the parsing position in case it fails.

Syntax 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.

Does not affect printing.

Attributes

final def between[Err2 >: Err, In2 <: In, Out2 >: Out](left: Syntax[Err2, In2, Out2, Unit], right: Syntax[Err2, In2, Out2, Unit]): Syntax[Err2, In2, Out2, Value]

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

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

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

Note that the 'left' and 'right' syntaxes must have a 'Value' type of Unit. Otherwise the printer could not produce an arbitrary input value for them as their result is discarded.

Attributes

def debug(msg: String): Syntax[Err, In, Out, Value]

Prints a debug message when this syntax parses a value

Prints a debug message when this syntax parses a value

Attributes

final def filter[Err2 >: Err, Value2 <: Value](condition: Value2 => Boolean, failure: Err2)(implicit ev: Value <:< Value2): Syntax[Err2, In, Out, Value2]

Specifies a filter condition 'condition' that gets checked in both parser and printer mode and in case it evaluates to false, fails with 'failure'.

Specifies a filter condition 'condition' that gets checked in both parser and printer mode and in case it evaluates to false, fails with 'failure'.

Attributes

final def flatten(implicit ev1: Chunk[String] <:< Value, ev2: Value <:< Chunk[String]): Syntax[Err, In, Out, String]

Flattens a result of parsed strings to a single string

Flattens a result of parsed strings to a single string

Attributes

final def manualBacktracking: Syntax[Err, In, Out, Value]

Disables auto-backtracking for this syntax

Disables auto-backtracking for this syntax

Attributes

final def mapError[Err2](f: Err => Err2): Syntax[Err2, In, Out, Value]

Maps the error with the given function 'f'

Maps the error with the given function 'f'

Attributes

final def named(name: String): Syntax[Err, In, Out, Value]

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

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

Attributes

final def not[Err2 >: Err](failure: Err2): Syntax[Err2, In, Out, Unit]

Syntax that succeeds only if this syntax fails

Syntax that succeeds only if this syntax fails

Attributes

def of[Value2 <: Product](implicit conversion: TupleConversion[Value2, Value], ev: Value =:= Value): Syntax[Err, In, Out, Value2]
Implicitly added by SyntaxOps

Transforms the syntax of a tuple to a syntax of a given case class

Transforms the syntax of a tuple to a syntax of a given case class

Attributes

final def optional: Syntax[Err, In, Out, Option[Value]]

Make this syntax optional.

Make this syntax optional.

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

Attributes

final def orElse[Err2 >: Err, In2 <: In, Out2 >: Out](that: => Syntax[Err2, In2, Out2, Value]): Syntax[Err2, In2, Out2, Value]

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

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

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

Attributes

final def orElseEither[Err2 >: Err, In2 <: In, Out2 >: Out, Value2](that: => Syntax[Err2, In2, Out2, Value2]): Syntax[Err2, In2, Out2, Either[Value, Value2]]

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

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

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

Attributes

final def parseChars(input: Chunk[Char])(implicit ev: Char <:< In): Either[StringParserError[Err], Value]

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

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

Attributes

final def parseChars(input: Chunk[Char], parserImplementation: ParserImplementation)(implicit ev: Char <:< In): Either[StringParserError[Err], Value]

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

final def parseChunk[In0 <: In](input: Chunk[In0])(implicit stateSelector: StateSelector[In0]): Either[ParserError[Err], Value]

Run this parser on the given 'input' chunk

Run this parser on the given 'input' chunk

Attributes

final def parseString(input: String)(implicit ev: Char <:< In): Either[StringParserError[Err], Value]

Run this parser on the given 'input' string

Run this parser on the given 'input' string

Attributes

final def parseString(input: String, parserImplementation: ParserImplementation)(implicit ev: Char <:< In): Either[StringParserError[Err], Value]

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

final def printString(value: Value)(implicit ev: Out <:< Char): Either[Err, String]

Prints a value 'value' to a string

Prints a value 'value' to a string

Attributes

final def repeat: Syntax[Err, In, Out, Chunk[Value]]

This syntax repeated at least once.

This syntax repeated 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.

When printing, the input is a chunk of values and each element gets printed.

Attributes

final def repeat0: Syntax[Err, In, Out, Chunk[Value]]

This syntax repeated zero or more times.

This syntax repeated 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.

When printing, the input is a chunk of values and each element gets printed.

Attributes

final def repeatUntil[Err2 >: Err, In2 <: In, Out2 >: Out](stopCondition: Syntax[Err2, In2, Out2, Unit]): Syntax[Err2, In2, Out2, Chunk[Value]]

Repeats this syntax until 'stopCondition', performed after each element, results in success.

Repeats this syntax until 'stopCondition', performed after each element, results in success.

Attributes

final def repeatWithSep[Err2 >: Err, In2 <: In, Out2 >: Out](sep: Syntax[Err2, In2, Out2, Unit]): Syntax[Err2, In2, Out2, Chunk[Value]]

Repeats this syntax at least once and with 'sep' injected between each element

Repeats this syntax at least once and with 'sep' injected between each element

Attributes

final def repeatWithSep0[Err2 >: Err, In2 <: In, Out2 >: Out](sep: Syntax[Err2, In2, Out2, Unit]): Syntax[Err2, In2, Out2, Chunk[Value]]

Repeats this syntax zero or more times and with 'sep' injected between each element

Repeats this syntax zero or more times and with 'sep' injected between each element

Attributes

final def setAutoBacktracking(enabled: Boolean): Syntax[Err, In, Out, Value]

Enables or disables auto-backtracking for this syntax

Enables or disables auto-backtracking for this syntax

Attributes

final def string(implicit ev1: Char <:< In): Syntax[Err, Char, Char, String]

Ignores this syntax's result and instead captures the parsed string fragment / directly print the input string

Ignores this syntax's result and instead captures the parsed string fragment / directly print the input string

Attributes

def strip: Syntax[Err, In, Out, Value]

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

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

Attributes

final def surroundedBy[Err2 >: Err, In2 <: In, Out2 >: Out](other: Syntax[Err2, In2, Out2, Unit]): Syntax[Err2, In2, Out2, Value]

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

final def toList[Item](implicit ev1: Chunk[Item] <:< Value, ev2: Value <:< Chunk[Item]): Syntax[Err, In, Out, List[Item]]

Converts a Chunk syntax to a List syntax

Converts a Chunk syntax to a List syntax

Attributes

final def transform[Value2](to: Value => Value2, from: Value2 => Value): Syntax[Err, In, Out, Value2]

Maps the parser's successful result with the given function 'to', and maps the value to be printed with the given function 'from'

Maps the parser's successful result with the given function 'to', and maps the value to be printed with the given function 'from'

Attributes

final def transformEither[Err2, Value2](to: Value => Either[Err2, Value2], from: Value2 => Either[Err2, Value]): Syntax[Err2, In, Out, Value2]

Maps the parser's successful result with the given function 'to', and maps the value to be printed with the given function 'from'. Both of the mapping functions can fail the parser/printer.

Maps the parser's successful result with the given function 'to', and maps the value to be printed with the given function 'from'. Both of the mapping functions can fail the parser/printer.

Attributes

final def transformOption[Value2](to: Value => Option[Value2], from: Value2 => Option[Value]): Syntax[Option[Err], In, Out, Value2]

Maps the parser's successful result with the given function 'to', and maps the value to be printed with the given function 'from'. Both of the mapping functions can fail the parser/printer. The failure is indicated in the error channel by the value None.

Maps the parser's successful result with the given function 'to', and maps the value to be printed with the given function 'from'. Both of the mapping functions can fail the parser/printer. The failure is indicated in the error channel by the value None.

Attributes

final def transformTo[Err2 >: Err, Value2, Result2](to: Value => Value2, from: PartialFunction[Value2, Value], failure: Err2): Syntax[Err2, In, Out, Value2]

Maps the parsed value with the function 'to', and the value to be printed with the partial function 'from'. It the partial function is not defined on the value, the printer fails with 'failure'.

Maps the parsed value with the function 'to', and the value to be printed with the partial function 'from'. It the partial function is not defined on the value, the printer fails with 'failure'.

This can be used to define separate syntaxes for subtypes, that can be later combined.

Attributes

final def unit(printed: Value): Syntax[Err, In, Out, Unit]

Syntax that does not consume any input but prints 'printed' and results in unit

Syntax that does not consume any input but prints 'printed' and results in unit

Attributes

def widen[D](implicit ev: Value <:< D, tag: ClassTag[Value]): Syntax[String, In, Out, D]
Implicitly added by StringErrSyntaxOps

Widens the parser to a supertype of its result

Widens the parser to a supertype of its result

This is useful in combination with the orElse (<>) operator. For example a JSON parser can be expressed by a combination of parsers for the individual json type widened to Json:

nul.widen[Json] <>
bool.widen[Json] <>
str.widen[Json] <>
num.widen[Json] <>
list.widen[Json] <>
obj.widen[Json]

Attributes

def widenWith[D](err: Err)(implicit ev: Value <:< D, tag: ClassTag[Value]): Syntax[Err, In, Out, D]
Implicitly added by SyntaxOps
final def widenWith[Err2 >: Err, Value2](narrow: PartialFunction[Value2, Value], failure: Err2)(implicit ev: Value <:< Value2): Syntax[Err2, In, Out, Value2]

Widen this syntax's printed value type by specifying a partial function to narrow it back to the set of supported subtypes.

Widen this syntax's printed value type by specifying a partial function to narrow it back to the set of supported subtypes.

Attributes

final def zip[Err2 >: Err, In2 <: In, Out2 >: Out, Value2, ZippedValue](that: => Syntax[Err2, In2, Out2, Value2])(implicit unzippableValue: In[Value, Value2, ZippedValue], zippableResult: Out[Value, Value2, ZippedValue]): Syntax[Err2, In2, Out2, ZippedValue]
Implicitly added by SyntaxOps

Concatenates this syntax with 'that' syntax. In case both parser succeeds, the result is a pair of the results. The printer destructures a pair and prints the left value with this, the right value with 'that'.

Concatenates this syntax with 'that' syntax. In case both parser succeeds, the result is a pair of the results. The printer destructures a pair and prints the left value with this, the right value with 'that'.

Attributes

final def zipLeft[Err2 >: Err, In2 <: In, Out2 >: Out](that: => Syntax[Err2, In2, Out2, Unit]): Syntax[Err2, In2, Out2, Value]

Concatenates this parser with 'that' parser. In case both parser succeeds, the result is the result of this parser. Otherwise the parser fails. The printer passes the value to be printed to this printer, and also executes 'that' printer with unit as the input value.

Concatenates this parser with 'that' parser. In case both parser succeeds, the result is the result of this parser. Otherwise the parser fails. The printer passes the value to be printed to this printer, and also executes 'that' printer with unit as the input value.

Note that the right syntax must have 'Value' defined as Unit, because there is no way for the printer to reconstruct an arbitrary input for the right printer.

Attributes

def zipRight[Err2 >: Err, In2 <: In, Out2 >: Out, Value2](that: => Syntax[Err2, In2, Out2, Value2]): Syntax[Err2, In2, Out2, Value2]
Implicitly added by AnySyntaxOps

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

final def |[Err2 >: Err, In2 <: In, Out2 >: Out](that: => Syntax[Err2, In2, Out2, Value]): Syntax[Err2, In2, Out2, Value]

Symbolic alias for orElse

Symbolic alias for orElse

Attributes

final def ~[Err2 >: Err, In2 <: In, Out2 >: Out, Value2, ZippedValue](that: => Syntax[Err2, In2, Out2, Value2])(implicit unzippableValue: In[Value, Value2, ZippedValue], zippableResult: Out[Value, Value2, ZippedValue]): Syntax[Err2, In2, Out2, ZippedValue]
Implicitly added by SyntaxOps

Symbolic alias for zip

Symbolic alias for zip

Attributes

def ~>[Err2 >: Err, In2 <: In, Out2 >: Out, Value2](that: => Syntax[Err2, In2, Out2, Value2]): Syntax[Err2, In2, Out2, Value2]
Implicitly added by AnySyntaxOps

Symbolic alias for zipRight

Symbolic alias for zipRight

Attributes

Inherited methods

final def orElseU[Err2 >: Err, In2 <: In, Out2 >: Out, Value2 : ClassTag](that: => Syntax[Err2, In2, Out2, Value2])(implicit evidence$1: ClassTag[Value2], vtag: ClassTag[Value]): Syntax[Err2, In2, Out2, Value | Value2]

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

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

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

Attributes

Inherited from:
VersionSpecificSyntax

Concrete fields

val asParser: Parser[Err, In, Value]
val asPrinter: Printer[Err, Out, Value]