Class Parser<TToken>
Constructor functions, extension methods and utilities for Parser<TToken, T> This class is intended to be imported statically, with the type parameter set to the type of tokens in your input stream ("using static Pidgin.Parser<char>").
Namespace: Pidgin
Assembly: Pidgin.dll
Syntax
public static class Parser<TToken> : object
Type Parameters
Name | Description |
---|---|
TToken | The type of the tokens in the input stream for parsers created by methods in this class |
Properties
| Improve this Doc View SourceAny
Creates a parser that parses any single character
Declaration
public static Parser<TToken, TToken> Any { get; }
Property Value
Type | Description |
---|---|
Parser<TToken, TToken> | A parser that parses any single character |
CurrentPos
A parser which returns the current source position
Declaration
public static Parser<TToken, SourcePos> CurrentPos { get; }
Property Value
Type | Description |
---|---|
Parser<TToken, SourcePos> | A parser which returns the current source position |
End
Creates a parser which parses the end of the input stream
Declaration
public static Parser<TToken, Unit> End { get; }
Property Value
Type | Description |
---|---|
Parser<TToken, Unit> | A parser which parses the end of the input stream and returns Value |
Methods
| Improve this Doc View SourceFail<T>(String)
Creates a parser which always fails without consuming any input.
Declaration
public static Parser<TToken, T> Fail<T>(string message = "Failed")
Parameters
Type | Name | Description |
---|---|---|
String | message | A custom error message |
Returns
Type | Description |
---|---|
Parser<TToken, T> | A parser which always fails |
Type Parameters
Name | Description |
---|---|
T | The return type of the resulting parser |
FromResult<T>(T)
Creates a parser which returns the specified value without consuming any input
Declaration
public static Parser<TToken, T> FromResult<T>(T result)
Parameters
Type | Name | Description |
---|---|---|
T | result | The value to return |
Returns
Type | Description |
---|---|
Parser<TToken, T> | A parser which returns the specified value without consuming any input |
Type Parameters
Name | Description |
---|---|
T | The type of the value to return |
Return<T>(T)
Creates a parser which returns the specified value without consuming any input
Declaration
public static Parser<TToken, T> Return<T>(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to return |
Returns
Type | Description |
---|---|
Parser<TToken, T> | A parser which returns the specified value without consuming any input |
Type Parameters
Name | Description |
---|---|
T | The type of the value to return |
Sequence(TToken[])
Creates a parser that parses and returns a literal sequence of tokens
Declaration
public static Parser<TToken, TToken[]> Sequence(params TToken[] tokens)
Parameters
Type | Name | Description |
---|---|---|
TToken[] | tokens | A sequence of tokens |
Returns
Type | Description |
---|---|
Parser<TToken, TToken[]> | A parser that parses a literal sequence of tokens |
Sequence<TEnumerable>(TEnumerable)
Creates a parser that parses and returns a literal sequence of tokens. The input enumerable is enumerated and copied to a list.
Declaration
public static Parser<TToken, TEnumerable> Sequence<TEnumerable>(TEnumerable tokens)
where TEnumerable : IEnumerable<TToken>
Parameters
Type | Name | Description |
---|---|---|
TEnumerable | tokens | A sequence of tokens |
Returns
Type | Description |
---|---|
Parser<TToken, TEnumerable> | A parser that parses a literal sequence of tokens |
Type Parameters
Name | Description |
---|---|
TEnumerable | The type of tokens to parse |
Sequence<T>(IEnumerable<Parser<TToken, T>>)
Creates a parser that applies a sequence of parsers and collects the results. This parser fails if any of its constituent parsers fail
Declaration
public static Parser<TToken, IEnumerable<T>> Sequence<T>(IEnumerable<Parser<TToken, T>> parsers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Parser<TToken, T>> | parsers | A sequence of parsers |
Returns
Type | Description |
---|---|
Parser<TToken, IEnumerable<T>> | A parser that applies a sequence of parsers and collects the results |
Type Parameters
Name | Description |
---|---|
T | The return type of the parsers |
Sequence<T>(Parser<TToken, T>[])
Creates a parser that applies a sequence of parsers and collects the results. This parser fails if any of its constituent parsers fail
Declaration
public static Parser<TToken, IEnumerable<T>> Sequence<T>(params Parser<TToken, T>[] parsers)
Parameters
Type | Name | Description |
---|---|---|
Parser<TToken, T>[] | parsers | A sequence of parsers |
Returns
Type | Description |
---|---|
Parser<TToken, IEnumerable<T>> | A parser that applies a sequence of parsers and collects the results |
Type Parameters
Name | Description |
---|---|
T | The return type of the parsers |
Token(TToken)
Creates a parser that parses and returns a single token
Declaration
public static Parser<TToken, TToken> Token(TToken token)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token to parse |
Returns
Type | Description |
---|---|
Parser<TToken, TToken> | A parser that parses and returns a single token |
Token(Func<TToken, Boolean>)
Creates a parser that parses and returns a single token satisfying a predicate
Declaration
public static Parser<TToken, TToken> Token(Func<TToken, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Func<TToken, Boolean> | predicate | A predicate function to apply to a token |
Returns
Type | Description |
---|---|
Parser<TToken, TToken> | A parser that parses and returns a single token satisfying a predicate |