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>").
Inheritance
- Object
- Parser<TToken>
Declaration
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
Any
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 |
Configuration
A parser which returns the current IConfiguration<TToken>.
Declaration
public static Parser<TToken, IConfiguration<TToken>> Configuration { get; }
Property Value
Type | Description |
---|---|
Parser<TToken, IConfiguration<TToken>> |
CurrentOffset
A parser which returns the number of input tokens which have been consumed.
Declaration
public static Parser<TToken, int> CurrentOffset { get; }
Property Value
Type | Description |
---|---|
A parser which returns the number of input tokens which have been consumed |
CurrentPos
A parser which returns the current source position
Declaration
public static Parser<TToken, SourcePos> CurrentPos { get; }
Property Value
Type | Description |
---|---|
A parser which returns the current source position |
CurrentSourcePosDelta
A parser which returns the current source position
Declaration
public static Parser<TToken, SourcePosDelta> CurrentSourcePosDelta { get; }
Property Value
Type | Description |
---|---|
Parser<TToken, SourcePosDelta> |
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 |
---|---|
A parser which parses the end of the input stream and returns Value |
Methods
Fail<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 |
---|---|---|
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>(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 |
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 |
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 |
---|---|---|
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 |