Pidgin

Class ParserExtensions

Extension methods for running parsers.

Inheritance
Inherited Members
Declaration
public static class ParserExtensions

Methods

ParseOrThrow<T>(Parser<byte, T>, Stream, IConfiguration<byte>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<T>(this Parser<byte, T> parser, Stream input, IConfiguration<byte>? configuration = null)
Parameters
Type Name Description

Parser<byte, T>

parser

A parser.

Stream

input

An input stream.

IConfiguration<byte>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

Type Parameters
Name Description

T

The type of the value returned by the parser.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<T>(Parser<char, T>, TextReader, IConfiguration<char>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<T>(this Parser<char, T> parser, TextReader input, IConfiguration<char>? configuration = null)
Parameters
Type Name Description

Parser<char, T>

parser

A parser.

TextReader

input

An input reader.

IConfiguration<char>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

Type Parameters
Name Description

T

The type of the value returned by the parser.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<T>(Parser<char, T>, string, IConfiguration<char>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<T>(this Parser<char, T> parser, string input, IConfiguration<char>? configuration = null)
Parameters
Type Name Description

Parser<char, T>

parser

A parser.

string

input

An input string.

IConfiguration<char>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

Type Parameters
Name Description

T

The type of the value returned by the parser.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<TToken, T>(Parser<TToken, T>, ITokenStream<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, ITokenStream<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

ITokenStream<TToken>

input

An input ITokenStream<TToken>.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

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.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<TToken, T>(Parser<TToken, T>, IEnumerable<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, IEnumerable<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IEnumerable<TToken>

input

An input enumerable.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

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.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<TToken, T>(Parser<TToken, T>, IEnumerator<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, IEnumerator<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IEnumerator<TToken>

input

An input enumerator.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

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.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<TToken, T>(Parser<TToken, T>, IList<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, IList<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IList<TToken>

input

An input list.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

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.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, ReadOnlySpan<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

ReadOnlySpan<TToken>

input

An input span.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

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.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseOrThrow<TToken, T>(Parser<TToken, T>, TToken[], IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, TToken[] input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

TToken[]

input

An input array.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

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.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseReadOnlyListOrThrow<TToken, T>(Parser<TToken, T>, IReadOnlyList<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static T ParseReadOnlyListOrThrow<TToken, T>(this Parser<TToken, T> parser, IReadOnlyList<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IReadOnlyList<TToken>

input

An input list.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

T

The result of parsing.

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.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseReadOnlyList<TToken, T>(Parser<TToken, T>, IReadOnlyList<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static Result<TToken, T> ParseReadOnlyList<TToken, T>(this Parser<TToken, T> parser, IReadOnlyList<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IReadOnlyList<TToken>

input

An input list.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

Parse<T>(Parser<byte, T>, Stream, IConfiguration<byte>?)

Applies parser to input. Note that more characters may be consumed from input than were required for parsing. You may need to manually rewind input.

Declaration
public static Result<byte, T> Parse<T>(this Parser<byte, T> parser, Stream input, IConfiguration<byte>? configuration = null)
Parameters
Type Name Description

Parser<byte, T>

parser

A parser.

Stream

input

An input stream.

IConfiguration<byte>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<byte, T>

The result of parsing.

Type Parameters
Name Description

T

The type of the value returned by the parser.

Parse<T>(Parser<char, T>, TextReader, IConfiguration<char>?)

Applies parser to input.

Declaration
public static Result<char, T> Parse<T>(this Parser<char, T> parser, TextReader input, IConfiguration<char>? configuration = null)
Parameters
Type Name Description

Parser<char, T>

parser

A parser.

TextReader

input

An input reader.

IConfiguration<char>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<char, T>

The result of parsing.

Type Parameters
Name Description

T

The type of the value returned by the parser.

Parse<T>(Parser<char, T>, string, IConfiguration<char>?)

Applies parser to input.

Declaration
public static Result<char, T> Parse<T>(this Parser<char, T> parser, string input, IConfiguration<char>? configuration = null)
Parameters
Type Name Description

Parser<char, T>

parser

A parser.

string

input

An input string.

IConfiguration<char>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<char, T>

The result of parsing.

Type Parameters
Name Description

T

The type of the value returned by the parser.

Parse<TToken, T>(Parser<TToken, T>, ITokenStream<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, ITokenStream<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

ITokenStream<TToken>

input

An input ITokenStream<TToken>.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

Parse<TToken, T>(Parser<TToken, T>, ref ParseState<TToken>)

Run the parser on the input state.

WARNING: This API is unstable and subject to change in future versions of the library.

Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, ref ParseState<TToken> state)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

ParseState<TToken>

state

An input ParseState<TToken>.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

Parse<TToken, T>(Parser<TToken, T>, IEnumerable<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, IEnumerable<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IEnumerable<TToken>

input

An input enumerable.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

Parse<TToken, T>(Parser<TToken, T>, IEnumerator<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, IEnumerator<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IEnumerator<TToken>

input

An input enumerator.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

Parse<TToken, T>(Parser<TToken, T>, IList<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, IList<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

IList<TToken>

input

An input list.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

Parse<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, ReadOnlySpan<TToken> input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

ReadOnlySpan<TToken>

input

An input span.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

Parse<TToken, T>(Parser<TToken, T>, TToken[], IConfiguration<TToken>?)

Applies parser to input.

Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, TToken[] input, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

A parser.

TToken[]

input

An input array.

IConfiguration<TToken>

configuration

The configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, T>

The result of parsing.

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.

In This Article