Class ParserExtensions
Extension methods for running parsers
Namespace: Pidgin
Assembly: Pidgin.dll
Syntax
public static class ParserExtensions : object
Methods
| Improve this Doc View SourceParse<T>(Parser<Byte, T>, Stream, Nullable<Func<Byte, SourcePos, SourcePos>>)
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, Func<byte, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<Byte, T> | parser | A parser |
Stream | input | An input stream |
Nullable<Func<Byte, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<Byte, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
T |
Parse<T>(Parser<Char, T>, String, Nullable<Func<Char, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<char, T> Parse<T>(this Parser<char, T> parser, string input, Func<char, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<Char, T> | parser | A parser |
String | input | An input string |
Nullable<Func<Char, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<Char, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
T |
Parse<T>(Parser<Char, T>, TextReader, Nullable<Func<Char, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<char, T> Parse<T>(this Parser<char, T> parser, TextReader input, Func<char, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<Char, T> | parser | A parser |
TextReader | input | An input reader |
Nullable<Func<Char, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<Char, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
T |
Parse<TToken, T>(Parser<TToken, T>, TToken[], Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, TToken[] input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
TToken[] | input | An input array |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<TToken, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Parse<TToken, T>(Parser<TToken, T>, IEnumerable<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, IEnumerable<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IEnumerable<TToken> | input | An input enumerable |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<TToken, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Parse<TToken, T>(Parser<TToken, T>, IEnumerator<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, IEnumerator<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IEnumerator<TToken> | input | An input enumerator |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<TToken, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Parse<TToken, T>(Parser<TToken, T>, IList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, IList<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IList<TToken> | input | An input list |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<TToken, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Parse<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<TToken, T> Parse<TToken, T>(this Parser<TToken, T> parser, ReadOnlySpan<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
ReadOnlySpan<TToken> | input | An input span |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<TToken, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
ParseOrThrow<T>(Parser<Byte, T>, Stream, Nullable<Func<Byte, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<T>(this Parser<byte, T> parser, Stream input, Func<byte, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<Byte, T> | parser | A parser |
Stream | input | An input stream |
Nullable<Func<Byte, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseOrThrow<T>(Parser<Char, T>, String, Nullable<Func<Char, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<T>(this Parser<char, T> parser, string input, Func<char, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<Char, T> | parser | A parser |
String | input | An input string |
Nullable<Func<Char, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseOrThrow<T>(Parser<Char, T>, TextReader, Nullable<Func<Char, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<T>(this Parser<char, T> parser, TextReader input, Func<char, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<Char, T> | parser | A parser |
TextReader | input | An input reader |
Nullable<Func<Char, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseOrThrow<TToken, T>(Parser<TToken, T>, TToken[], Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, TToken[] input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
TToken[] | input | An input array |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseOrThrow<TToken, T>(Parser<TToken, T>, IEnumerable<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, IEnumerable<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IEnumerable<TToken> | input | An input enumerable |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseOrThrow<TToken, T>(Parser<TToken, T>, IEnumerator<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, IEnumerator<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IEnumerator<TToken> | input | An input enumerator |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseOrThrow<TToken, T>(Parser<TToken, T>, IList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, IList<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IList<TToken> | input | An input list |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseOrThrow<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseOrThrow<TToken, T>(this Parser<TToken, T> parser, ReadOnlySpan<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
ReadOnlySpan<TToken> | input | An input span |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |
ParseReadOnlyList<TToken, T>(Parser<TToken, T>, IReadOnlyList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static Result<TToken, T> ParseReadOnlyList<TToken, T>(this Parser<TToken, T> parser, IReadOnlyList<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IReadOnlyList<TToken> | input | An input list |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
Result<TToken, T> | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
ParseReadOnlyListOrThrow<TToken, T>(Parser<TToken, T>, IReadOnlyList<TToken>, Nullable<Func<TToken, SourcePos, SourcePos>>)
Applies parser
to input
Declaration
public static T ParseReadOnlyListOrThrow<TToken, T>(this Parser<TToken, T> parser, IReadOnlyList<TToken> input, Func<TToken, SourcePos, SourcePos>? calculatePos = null)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T> | parser | A parser |
IReadOnlyList<TToken> | input | An input list |
Nullable<Func<TToken, SourcePos, SourcePos>> | calculatePos | A function to calculate the new position after consuming a token, or null to use the default |
Returns
Type | Description |
---|---|
T | The result of parsing |
Type Parameters
Name | Description |
---|---|
TToken | |
T |
Exceptions
Type | Condition |
---|---|
ParseException | Thrown when an error occurs during parsing |