Show / Hide Table of Contents

Class Parser<TToken, T>

Represents a parser which consumes a stream of values of type TToken and returns a value of type T. A parser can either succeed, and return a value of type T, or fail and return a ParseError<TToken>.

Inheritance
Object
Parser<TToken, T>
Namespace: Pidgin
Assembly: Pidgin.dll
Syntax
public abstract class Parser<TToken, T> : object
Type Parameters
Name Description
TToken

The type of the tokens in the parser's input stream

T

The type of the value returned by the parser

Remarks

This type is not intended to be subclassed by users of the library

Methods

| Improve this Doc View Source

Assert(Func<T, Boolean>)

Creates a parser that fails if the value returned by the current parser fails to satisfy a predicate.

Declaration
public Parser<TToken, T> Assert(Func<T, bool> predicate)
Parameters
Type Name Description
Func<T, Boolean> predicate

The predicate to apply to the value returned by the current parser

Returns
Type Description
Parser<TToken, T>

A parser that fails if the value returned by the current parser fails to satisfy predicate

| Improve this Doc View Source

Assert(Func<T, Boolean>, Func<T, String>)

Creates a parser that fails if the value returned by the current parser fails to satisfy a predicate.

Declaration
public Parser<TToken, T> Assert(Func<T, bool> predicate, Func<T, string> message)
Parameters
Type Name Description
Func<T, Boolean> predicate

The predicate to apply to the value returned by the current parser

Func<T, String> message

A function to produce a custom error message to return when the value returned by the current parser fails to satisfy the predicate

Returns
Type Description
Parser<TToken, T>

A parser that fails if the value returned by the current parser fails to satisfy predicate

| Improve this Doc View Source

Assert(Func<T, Boolean>, String)

Creates a parser that fails if the value returned by the current parser fails to satisfy a predicate.

Declaration
public Parser<TToken, T> Assert(Func<T, bool> predicate, string message)
Parameters
Type Name Description
Func<T, Boolean> predicate

The predicate to apply to the value returned by the current parser

String message

A custom error message to return when the value returned by the current parser fails to satisfy the predicate

Returns
Type Description
Parser<TToken, T>

A parser that fails if the value returned by the current parser fails to satisfy predicate

| Improve this Doc View Source

AtLeastOnce()

Creates a parser that applies the current parser one or more times. The resulting parser fails if the current parser fails the first time it is applied, or if the current parser fails after consuming input

Declaration
public Parser<TToken, IEnumerable<T>> AtLeastOnce()
Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser that applies the current parser one or more times

| Improve this Doc View Source

AtLeastOnceUntil<U>(Parser<TToken, U>)

Creates a parser which applies this parser one or more times until terminator succeeds. Fails if this parser fails or if terminator fails after consuming input. The return value of terminator is ignored.

Declaration
public Parser<TToken, IEnumerable<T>> AtLeastOnceUntil<U>(Parser<TToken, U> terminator)
Parameters
Type Name Description
Parser<TToken, U> terminator

A parser to parse a terminator

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies this parser repeatedly until terminator succeeds

Type Parameters
Name Description
U
| Improve this Doc View Source

Before<U>(Parser<TToken, U>)

Creates a parser that applies the current parser followed by the specified parser. The resulting parser returns the result of the current parser, ignoring the result of the second parser.

Declaration
public Parser<TToken, T> Before<U>(Parser<TToken, U> parser)
Parameters
Type Name Description
Parser<TToken, U> parser

The parser to apply after applying the current parser.

Returns
Type Description
Parser<TToken, T>

A parser that applies the current parser followed by the specified parser

Type Parameters
Name Description
U

The type of the value returned by the second parser

| Improve this Doc View Source

Between<U>(Parser<TToken, U>)

Creates a parser that applies the specified parser both before and after applying the current parser. The resulting parser returns the result of the current parser, ignoring the return value of the bracketing parser.

Declaration
public Parser<TToken, T> Between<U>(Parser<TToken, U> parser)
Parameters
Type Name Description
Parser<TToken, U> parser

The parser to apply before and after applying the current parser

Returns
Type Description
Parser<TToken, T>

A parser that applies the specified parser before and after applying the current parser

Type Parameters
Name Description
U

The type of the value returned by the bracketing parser

| Improve this Doc View Source

Between<U, V>(Parser<TToken, U>, Parser<TToken, V>)

Creates a parser that applies the specified parsers before and after applying the current parser. The resulting parser returns the result of the current parser, ignoring the return values of the bracketing parsers.

Declaration
public Parser<TToken, T> Between<U, V>(Parser<TToken, U> parser1, Parser<TToken, V> parser2)
Parameters
Type Name Description
Parser<TToken, U> parser1

The parser to apply before applying the current parser

Parser<TToken, V> parser2

The parser to apply after applying the current parser

Returns
Type Description
Parser<TToken, T>

A parser that applies the specified parsers before and after applying the current parser

Type Parameters
Name Description
U

The type of the value returned by the first parser

V

The type of the value returned by the second parser

| Improve this Doc View Source

Bind<U>(Func<T, Parser<TToken, U>>)

Creates a parser that applies a transformation function to the return value of the current parser. The transformation function dynamically chooses a second parser, which is applied after applying the current parser.

Declaration
public Parser<TToken, U> Bind<U>(Func<T, Parser<TToken, U>> selector)
Parameters
Type Name Description
Func<T, Parser<TToken, U>> selector

A transformation function which returns a parser to apply after applying the current parser

Returns
Type Description
Parser<TToken, U>

A parser which applies the current parser before applying the result of the selector function.

Type Parameters
Name Description
U

The type of the return value of the second parser

| Improve this Doc View Source

Bind<U, R>(Func<T, Parser<TToken, U>>, Func<T, U, R>)

Creates a parser that applies a transformation function to the return value of the current parser. The transformation function dynamically chooses a second parser, which is applied after applying the current parser.

Declaration
public Parser<TToken, R> Bind<U, R>(Func<T, Parser<TToken, U>> selector, Func<T, U, R> result)
Parameters
Type Name Description
Func<T, Parser<TToken, U>> selector

A transformation function which returns a parser to apply after applying the current parser

Func<T, U, R> result

A function to apply to the return values of the two parsers

Returns
Type Description
Parser<TToken, R>

A parser which applies the current parser before applying the result of the selector function

Type Parameters
Name Description
U

The type of the return value of the second parser

R

The type of the return value of the resulting parser

| Improve this Doc View Source

Cast<U>()

Cast the return value of the current parser to the specified result type

Declaration
public Parser<TToken, U> Cast<U>()
Returns
Type Description
Parser<TToken, U>

A parser which returns this parser's return value casted to U

Type Parameters
Name Description
U

The type to cast the return value to

| Improve this Doc View Source

IgnoreResult()

Creates a parser which behaves like the current parser but returns Value. Equivalent to p.WithResult(Unit.Value).

Declaration
public Parser<TToken, Unit> IgnoreResult()
Returns
Type Description
Parser<TToken, Unit>

A parser which behaves like the current parser but returns Value.

| Improve this Doc View Source

Labelled(String)

Creates a parser equivalent to the current parser, with a custom label. The label will be reported in an error message if the parser fails, instead of the default error message. Expected Label

Declaration
public Parser<TToken, T> Labelled(string label)
Parameters
Type Name Description
String label

The custom label to apply to the current parser

Returns
Type Description
Parser<TToken, T>

A parser equivalent to the current parser, with a custom label

| Improve this Doc View Source

Many()

Creates a parser which applies the current parser zero or more times. The resulting parser fails if the current parser fails after consuming input.

Declaration
public Parser<TToken, IEnumerable<T>> Many()
Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser zero or more times

| Improve this Doc View Source

Map<U>(Func<T, U>)

Creates a parser which applies the specified transformation function to the result of the current parser. This is an infix synonym for Map<TToken, T1, R>(Func<T1, R>, Parser<TToken, T1>).

Declaration
public Parser<TToken, U> Map<U>(Func<T, U> selector)
Parameters
Type Name Description
Func<T, U> selector

A transformation function

Returns
Type Description
Parser<TToken, U>

A parser which applies selector to the result of the current parser

Type Parameters
Name Description
U

The return type of the transformation function

| Improve this Doc View Source

MapWithInput<U>(ReadOnlySpanFunc<TToken, T, U>)

Returns a parser which runs the current parser and applies a selector function. The selector function receives a as its first argument, and the result of the current parser as its second argument. The represents the sequence of input tokens which were consumed by the parser.

This allows you to write "pattern"-style parsers which match a sequence of tokens and return a view of the part of the input stream which they matched.

This function is an alternative name for Slice<U>(ReadOnlySpanFunc<TToken, T, U>).

Declaration
public Parser<TToken, U> MapWithInput<U>(ReadOnlySpanFunc<TToken, T, U> selector)
Parameters
Type Name Description
ReadOnlySpanFunc<TToken, T, U> selector

A selector function which computes a result of type U. The arguments of the selector function are a containing the sequence of input tokens which were consumed by this parser, and the result of this parser.

Returns
Type Description
Parser<TToken, U>

A parser which runs the current parser and applies a selector function.

Type Parameters
Name Description
U

The result type

| Improve this Doc View Source

OfType<U>()

Creates a parser which casts the return value of the current parser to the specified result type, or fails if the return value is not an instance of U.

Declaration
public Parser<TToken, U> OfType<U>()
Returns
Type Description
Parser<TToken, U>

A parser which returns the current parser's return value casted to U, if the value is an instance of U

Type Parameters
Name Description
U

The type to cast the return value of the current parser to

| Improve this Doc View Source

Optional()

Creates a parser which applies the current parser and returns Nothing<T>() if the current parser fails without consuming any input. The resulting parser fails if the current parser fails after consuming input.

Declaration
public Parser<TToken, Maybe<T>> Optional()
Returns
Type Description
Parser<TToken, Maybe<T>>

A parser which applies the current parser and returns Nothing<T>() if the current parser fails without consuming any input

| Improve this Doc View Source

Or(Parser<TToken, T>)

Creates a parser which tries to apply the current parser, applying the specified parser if the current parser fails without consuming any input. The resulting parser fails if both the current parser and the alternative parser fail, or if the current parser fails after consuming input.

Declaration
public Parser<TToken, T> Or(Parser<TToken, T> parser)
Parameters
Type Name Description
Parser<TToken, T> parser

The alternative parser to apply if the current parser fails without consuming any input

Returns
Type Description
Parser<TToken, T>

A parser which tries to apply the current parser, and applies parser if the current parser fails without consuming any input.

| Improve this Doc View Source

RecoverWith(Func<ParseError<TToken>, Parser<TToken, T>>)

Creates a parser which runs the current parser, running errorHandler on failure.

Declaration
public Parser<TToken, T> RecoverWith(Func<ParseError<TToken>, Parser<TToken, T>> errorHandler)
Parameters
Type Name Description
Func<ParseError<TToken>, Parser<TToken, T>> errorHandler

A function which returns a parser to apply when the current parser fails.

Returns
Type Description
Parser<TToken, T>

A parser which runs the current parser, running errorHandler on failure.

| Improve this Doc View Source

Repeat(Int32)

Creates a parser which applies the current parser count times.

Declaration
public Parser<TToken, IEnumerable<T>> Repeat(int count)
Parameters
Type Name Description
Int32 count

The number of times to apply the current parser

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser count times.

| Improve this Doc View Source

Select<U>(Func<T, U>)

Creates a parser which applies the specified transformation function to the result of the current parser. This is an infix synonym for Map<TToken, T1, R>(Func<T1, R>, Parser<TToken, T1>).

Declaration
public Parser<TToken, U> Select<U>(Func<T, U> selector)
Parameters
Type Name Description
Func<T, U> selector

A transformation function

Returns
Type Description
Parser<TToken, U>

A parser which applies selector to the result of the current parser

Type Parameters
Name Description
U

The return type of the transformation function

| Improve this Doc View Source

SelectMany<U, R>(Func<T, Parser<TToken, U>>, Func<T, U, R>)

Creates a parser that applies a transformation function to the return value of the current parser. The transformation function dynamically chooses a second parser, which is applied after applying the current parser.

Declaration
public Parser<TToken, R> SelectMany<U, R>(Func<T, Parser<TToken, U>> selector, Func<T, U, R> result)
Parameters
Type Name Description
Func<T, Parser<TToken, U>> selector

A transformation function which returns a parser to apply after applying the current parser

Func<T, U, R> result

A function to apply to the return values of the two parsers

Returns
Type Description
Parser<TToken, R>

A parser which applies the current parser before applying the result of the selector function

Type Parameters
Name Description
U

The type of the return value of the second parser

R

The type of the return value of the resulting parser

| Improve this Doc View Source

Separated<U>(Parser<TToken, U>)

Creates a parser which applies the current parser repeatedly, interleaved with a specified parser. The resulting parser ignores the return value of the separator parser.

Declaration
public Parser<TToken, IEnumerable<T>> Separated<U>(Parser<TToken, U> separator)
Parameters
Type Name Description
Parser<TToken, U> separator

A parser which parses a separator to be interleaved with the current parser

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser repeatedly, interleaved by separator

Type Parameters
Name Description
U

The return type of the separator parser

| Improve this Doc View Source

SeparatedAndOptionallyTerminated<U>(Parser<TToken, U>)

Creates a parser which applies the current parser repeatedly, interleaved and optionally terminated with a specified parser. The resulting parser ignores the return value of the separator parser.

Declaration
public Parser<TToken, IEnumerable<T>> SeparatedAndOptionallyTerminated<U>(Parser<TToken, U> separator)
Parameters
Type Name Description
Parser<TToken, U> separator

A parser which parses a separator to be interleaved with the current parser

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser repeatedly, interleaved and optionally terminated by separator

Type Parameters
Name Description
U

The return type of the separator parser

| Improve this Doc View Source

SeparatedAndOptionallyTerminatedAtLeastOnce<U>(Parser<TToken, U>)

Creates a parser which applies the current parser at least once, interleaved and optionally terminated with a specified parser. The resulting parser ignores the return value of the separator parser.

Declaration
public Parser<TToken, IEnumerable<T>> SeparatedAndOptionallyTerminatedAtLeastOnce<U>(Parser<TToken, U> separator)
Parameters
Type Name Description
Parser<TToken, U> separator

A parser which parses a separator to be interleaved with the current parser

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser at least once, interleaved and optionally terminated by separator

Type Parameters
Name Description
U

The return type of the separator parser

| Improve this Doc View Source

SeparatedAndTerminated<U>(Parser<TToken, U>)

Creates a parser which applies the current parser repeatedly, interleaved and terminated with a specified parser. The resulting parser ignores the return value of the separator parser.

Declaration
public Parser<TToken, IEnumerable<T>> SeparatedAndTerminated<U>(Parser<TToken, U> separator)
Parameters
Type Name Description
Parser<TToken, U> separator

A parser which parses a separator to be interleaved with the current parser

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser repeatedly, interleaved and terminated by separator

Type Parameters
Name Description
U

The return type of the separator parser

| Improve this Doc View Source

SeparatedAndTerminatedAtLeastOnce<U>(Parser<TToken, U>)

Creates a parser which applies the current parser at least once, interleaved and terminated with a specified parser. The resulting parser ignores the return value of the separator parser.

Declaration
public Parser<TToken, IEnumerable<T>> SeparatedAndTerminatedAtLeastOnce<U>(Parser<TToken, U> separator)
Parameters
Type Name Description
Parser<TToken, U> separator

A parser which parses a separator to be interleaved with the current parser

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser at least once, interleaved and terminated by separator

Type Parameters
Name Description
U

The return type of the separator parser

| Improve this Doc View Source

SeparatedAtLeastOnce<U>(Parser<TToken, U>)

Creates a parser which applies the current parser at least once, interleaved with a specified parser. The resulting parser ignores the return value of the separator parser.

Declaration
public Parser<TToken, IEnumerable<T>> SeparatedAtLeastOnce<U>(Parser<TToken, U> separator)
Parameters
Type Name Description
Parser<TToken, U> separator

A parser which parses a separator to be interleaved with the current parser

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies the current parser at least once, interleaved by separator

Type Parameters
Name Description
U

The return type of the separator parser

| Improve this Doc View Source

SkipAtLeastOnce()

Creates a parser that applies the current parser one or more times, discarding the results. This is more efficient than AtLeastOnce(), if you don't need the results. The resulting parser fails if the current parser fails the first time it is applied, or if the current parser fails after consuming input

Declaration
public Parser<TToken, Unit> SkipAtLeastOnce()
Returns
Type Description
Parser<TToken, Unit>

A parser that applies the current parser one or more times, discarding the results

| Improve this Doc View Source

SkipAtLeastOnceUntil<U>(Parser<TToken, U>)

Creates a parser which applies this parser one or more times until terminator succeeds, discarding the results. This is more efficient than AtLeastOnceUntil<U>(Parser<TToken, U>) if you don't need the results. Fails if this parser fails or if terminator fails after consuming input. The return value of terminator is ignored.

Declaration
public Parser<TToken, Unit> SkipAtLeastOnceUntil<U>(Parser<TToken, U> terminator)
Parameters
Type Name Description
Parser<TToken, U> terminator

A parser to parse a terminator

Returns
Type Description
Parser<TToken, Unit>

A parser which applies this parser repeatedly until terminator succeeds, discarding the results

Type Parameters
Name Description
U
| Improve this Doc View Source

SkipMany()

Creates a parser which applies the current parser zero or more times, discarding the results. This is more efficient than Many(), if you don't need the results. The resulting parser fails if the current parser fails after consuming input.

Declaration
public Parser<TToken, Unit> SkipMany()
Returns
Type Description
Parser<TToken, Unit>

A parser which applies the current parser zero or more times

| Improve this Doc View Source

SkipUntil<U>(Parser<TToken, U>)

Creates a parser which applies this parser zero or more times until terminator succeeds, discarding the results. This is more efficient than Until<U>(Parser<TToken, U>) if you don't need the results. Fails if this parser fails or if terminator fails after consuming input. The return value of terminator is ignored.

Declaration
public Parser<TToken, Unit> SkipUntil<U>(Parser<TToken, U> terminator)
Parameters
Type Name Description
Parser<TToken, U> terminator

A parser to parse a terminator

Returns
Type Description
Parser<TToken, Unit>

A parser which applies this parser repeatedly until terminator succeeds, discarding the results

Type Parameters
Name Description
U

The return type of terminator

| Improve this Doc View Source

Slice<U>(ReadOnlySpanFunc<TToken, T, U>)

Returns a parser which runs the current parser and applies a selector function. The selector function receives a as its first argument, and the result of the current parser as its second argument. The represents the sequence of input tokens which were consumed by the parser.

This allows you to write "pattern"-style parsers which match a sequence of tokens and return a view of the part of the input stream which they matched.

This function is an alternative name for MapWithInput<U>(ReadOnlySpanFunc<TToken, T, U>).

Declaration
public Parser<TToken, U> Slice<U>(ReadOnlySpanFunc<TToken, T, U> selector)
Parameters
Type Name Description
ReadOnlySpanFunc<TToken, T, U> selector

A selector function which computes a result of type U. The arguments of the selector function are a containing the sequence of input tokens which were consumed by this parser, and the result of this parser.

Returns
Type Description
Parser<TToken, U>

A parser which runs the current parser and applies a selector function.

Type Parameters
Name Description
U

The result type

| Improve this Doc View Source

Then<U>(Func<T, Parser<TToken, U>>)

Creates a parser that applies a transformation function to the return value of the current parser. The transformation function dynamically chooses a second parser, which is applied after applying the current parser.

Declaration
public Parser<TToken, U> Then<U>(Func<T, Parser<TToken, U>> selector)
Parameters
Type Name Description
Func<T, Parser<TToken, U>> selector

A transformation function which returns a parser to apply after applying the current parser

Returns
Type Description
Parser<TToken, U>

A parser which applies the current parser before applying the result of the selector function.

Type Parameters
Name Description
U

The type of the return value of the second parser

Remarks

This function is a synonym for Bind<U>(Func<T, Parser<TToken, U>>)

| Improve this Doc View Source

Then<U>(Parser<TToken, U>)

Creates a parser which applies the current parser followed by a specified parser. The resulting parser returns the result of the second parser, ignoring the result of the current parser.

Declaration
public Parser<TToken, U> Then<U>(Parser<TToken, U> parser)
Parameters
Type Name Description
Parser<TToken, U> parser

A parser to apply after applying the current parser

Returns
Type Description
Parser<TToken, U>

A parser which applies the current parser followed by parser

Type Parameters
Name Description
U

The return type of the second parser

| Improve this Doc View Source

Then<U, R>(Func<T, Parser<TToken, U>>, Func<T, U, R>)

Creates a parser that applies a transformation function to the return value of the current parser. The transformation function dynamically chooses a second parser, which is applied after applying the current parser.

Declaration
public Parser<TToken, R> Then<U, R>(Func<T, Parser<TToken, U>> selector, Func<T, U, R> result)
Parameters
Type Name Description
Func<T, Parser<TToken, U>> selector

A transformation function which returns a parser to apply after applying the current parser

Func<T, U, R> result

A function to apply to the return values of the two parsers

Returns
Type Description
Parser<TToken, R>

A parser which applies the current parser before applying the result of the selector function

Type Parameters
Name Description
U

The type of the return value of the second parser

R

The type of the return value of the resulting parser

Remarks

This function is a synonym for Bind<U, R>(Func<T, Parser<TToken, U>>, Func<T, U, R>)

| Improve this Doc View Source

Then<U, R>(Parser<TToken, U>, Func<T, U, R>)

Creates a parser which applies the current parser followed by a specified parser, applying a function to the two results.

Declaration
public Parser<TToken, R> Then<U, R>(Parser<TToken, U> parser, Func<T, U, R> result)
Parameters
Type Name Description
Parser<TToken, U> parser

A parser to apply after applying the current parser

Func<T, U, R> result

A function to apply to the two parsed values

Returns
Type Description
Parser<TToken, R>

A parser which applies the current parser followed by parser

Type Parameters
Name Description
U

The return type of the second parser

R

The return type of the composed parser

Remarks

This is a synonym for Map<TToken, T1, T2, R>(Func<T1, T2, R>, Parser<TToken, T1>, Parser<TToken, T2>) with the arguments rearranged.

| Improve this Doc View Source

ThenReturn<U>(U)

Creates a parser which behaves like the current parser but returns result after a successful parse. This is a synonym for WithResult<U>(U).

Declaration
public Parser<TToken, U> ThenReturn<U>(U result)
Parameters
Type Name Description
U result

The result

Returns
Type Description
Parser<TToken, U>

A parser which behaves like the current parser but returns result.

Type Parameters
Name Description
U
Examples

Equivalent to using Select<U>(Func<T, U>) with a function that returns a fixed value, or Then<U>(Parser<TToken, U>) with Return<T>(T).

p.ThenReturn(x) == p.Select(_ => x) == p.Then(Return(x));
| Improve this Doc View Source

Trace(Func<T, String>)

For debugging use.

Creates a new parser which runs the current parser and prints the given message to the console.

Declaration
public Parser<TToken, T> Trace(Func<T, string> message)
Parameters
Type Name Description
Func<T, String> message
Returns
Type Description
Parser<TToken, T>

A parser which runs the current parser and prints the given message to the console.

| Improve this Doc View Source

Trace(String)

For debugging use.

Creates a new parser which runs the current parser and prints the given message to the console.

Declaration
public Parser<TToken, T> Trace(string message)
Parameters
Type Name Description
String message
Returns
Type Description
Parser<TToken, T>

A parser which runs the current parser and prints the given message to the console.

| Improve this Doc View Source

TraceResult()

For debugging use.

Creates a new parser which runs the current parser and prints the result to the console.

Declaration
public Parser<TToken, T> TraceResult()
Returns
Type Description
Parser<TToken, T>

A parser which runs the current parser and prints the result to the console.

| Improve this Doc View Source

Until<U>(Parser<TToken, U>)

Creates a parser which applies this parser zero or more times until terminator succeeds. Fails if this parser fails or if terminator fails after consuming input. The return value of terminator is ignored.

Declaration
public Parser<TToken, IEnumerable<T>> Until<U>(Parser<TToken, U> terminator)
Parameters
Type Name Description
Parser<TToken, U> terminator

A parser to parse a terminator

Returns
Type Description
Parser<TToken, IEnumerable<T>>

A parser which applies this parser repeatedly until terminator succeeds

Type Parameters
Name Description
U

The return type of terminator

| Improve this Doc View Source

Where(Func<T, Boolean>)

Creates a parser that fails if the value returned by the current parser fails to satisfy a predicate.

Declaration
public Parser<TToken, T> Where(Func<T, bool> predicate)
Parameters
Type Name Description
Func<T, Boolean> predicate

The predicate to apply to the value returned by the current parser

Returns
Type Description
Parser<TToken, T>

A parser that fails if the value returned by the current parser fails to satisfy predicate

Remarks

This function is a synonym of Assert(Func<T, Boolean>)

| Improve this Doc View Source

WithResult<U>(U)

Creates a parser which behaves like the current parser but returns result after a successful parse. This is a synonym for ThenReturn<U>(U).

Declaration
public Parser<TToken, U> WithResult<U>(U result)
Parameters
Type Name Description
U result

The result

Returns
Type Description
Parser<TToken, U>

A parser which behaves like the current parser but returns result.

Type Parameters
Name Description
U
Examples

Equivalent to using Select<U>(Func<T, U>) with a function that returns a fixed value, or Then<U>(Parser<TToken, U>) with Return<T>(T).

p.WithResult(x) == p.Select(_ => x) == p.Then(Return(x));

Extension Methods

ParserExtensions.Parse<TToken, T>(Parser<TToken, T>, IList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.ParseReadOnlyList<TToken, T>(Parser<TToken, T>, IReadOnlyList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.Parse<TToken, T>(Parser<TToken, T>, IEnumerable<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.Parse<TToken, T>(Parser<TToken, T>, IEnumerator<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.Parse<TToken, T>(Parser<TToken, T>, TToken[], Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.Parse<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.ParseOrThrow<TToken, T>(Parser<TToken, T>, IList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.ParseReadOnlyListOrThrow<TToken, T>(Parser<TToken, T>, IReadOnlyList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.ParseOrThrow<TToken, T>(Parser<TToken, T>, IEnumerable<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.ParseOrThrow<TToken, T>(Parser<TToken, T>, IEnumerator<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.ParseOrThrow<TToken, T>(Parser<TToken, T>, TToken[], Nullable<Func<TToken, SourcePos, SourcePos>>)
ParserExtensions.ParseOrThrow<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX