Class PermutationParser<TToken, T>
A permutation parser represents a collection of parsers which can be run in an order-insensitive manner.
Declaration modifiers in C# are an example of an order-insensitive grammar.
Modifiers can appear in any order: protected internal static readonly int x;
means the same as internal readonly protected static int x;.
Usage of this class involves calling Add<U>(Parser<TToken, U>) or AddOptional<U>(Parser<TToken, U>, U) to add parsers to the permutation parser, and then calling Build() to create a parser which runs them in an order-insensitive manner and returns the results in a nested tuple.
Note that the parsers that are added to the permutation parser must always consume input before succeeding. If a parser succeeds on empty input the permutation parser will not work correctly. If you want to run a parser optionally, use AddOptional<U>(Parser<TToken, U>, U).
This class is immutable.
Inheritance
- Object
- PermutationParser<TToken, T>
Declaration
public sealed class PermutationParser<TToken, T> : ObjectType Parameters
| Name | Description | 
|---|---|
| TToken | |
| T | 
Methods
Add<U>(Parser<TToken, U>)
Adds a parser to the collection.
Declaration
public PermutationParser<TToken, ValueTuple<T, U>> Add<U>(Parser<TToken, U> parser)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, ValueTuple<T, U>> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | 
Add<U, R>(Parser<TToken, U>, Func<T, U, R>)
Adds a parser to the collection.
Declaration
public PermutationParser<TToken, R> Add<U, R>(Parser<TToken, U> parser, Func<T, U, R> resultSelector)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
| Func<T, U, R> | resultSelector | A transformation function to apply to the result of the current permutation parser and the result of  | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, R> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | |
| R | 
AddOptional<U>(Parser<TToken, U>)
Adds an optional parser to the collection.
The resulting permutation parser will successfully parse a phrase even if parser never succeeds.
In that case, Nothing<T>() will be returned.
Declaration
public PermutationParser<TToken, ValueTuple<T, Maybe<U>>> AddOptional<U>(Parser<TToken, U> parser)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, ValueTuple<T, Maybe<U>>> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | 
AddOptional<U>(Parser<TToken, U>, U)
Adds an optional parser to the collection.
The resulting permutation parser will successfully parse a phrase even if parser never succeeds.
In that case, defaultValue will be returned.
Declaration
public PermutationParser<TToken, ValueTuple<T, U>> AddOptional<U>(Parser<TToken, U> parser, U defaultValue)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
| U | defaultValue | A default value to return if  | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, ValueTuple<T, U>> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | 
AddOptional<U>(Parser<TToken, U>, Func<U>)
Adds an optional parser to the collection.
The resulting permutation parser will successfully parse a phrase even if parser never succeeds.
In that case, defaultValueFactory will be called to get a value to return.
Declaration
public PermutationParser<TToken, ValueTuple<T, U>> AddOptional<U>(Parser<TToken, U> parser, Func<U> defaultValueFactory)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
| Func<U> | defaultValueFactory | A factory for a default value to return if  | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, ValueTuple<T, U>> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | 
AddOptional<U, R>(Parser<TToken, U>, U, Func<T, U, R>)
Adds an optional parser to the collection.
The resulting permutation parser will successfully parse a phrase even if parser never succeeds.
In that case, defaultValue will be returned.
Declaration
public PermutationParser<TToken, R> AddOptional<U, R>(Parser<TToken, U> parser, U defaultValue, Func<T, U, R> resultSelector)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
| U | defaultValue | A default value to return if  | 
| Func<T, U, R> | resultSelector | A transformation function to apply to the result of the current permutation parser and the result of  | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, R> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | |
| R | 
AddOptional<U, R>(Parser<TToken, U>, Func<U>, Func<T, U, R>)
Adds an optional parser to the collection.
The resulting permutation parser will successfully parse a phrase even if parser never succeeds.
In that case, defaultValueFactory will be called to get a value to return.
Declaration
public PermutationParser<TToken, R> AddOptional<U, R>(Parser<TToken, U> parser, Func<U> defaultValueFactory, Func<T, U, R> resultSelector)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
| Func<U> | defaultValueFactory | A factory for a default value to return if  | 
| Func<T, U, R> | resultSelector | A transformation function to apply to the result of the current permutation parser and the result of  | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, R> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | |
| R | 
AddOptional<U, R>(Parser<TToken, U>, Func<T, Maybe<U>, R>)
Adds an optional parser to the collection.
The resulting permutation parser will successfully parse a phrase even if parser never succeeds.
In that case, Nothing<T>() will be returned.
Declaration
public PermutationParser<TToken, R> AddOptional<U, R>(Parser<TToken, U> parser, Func<T, Maybe<U>, R> resultSelector)Parameters
| Type | Name | Description | 
|---|---|---|
| Parser<TToken, U> | parser | The parser to add to the collection. | 
| resultSelector | A transformation function to apply to the result of the current permutation parser and the result of  | 
Returns
| Type | Description | 
|---|---|
| PermutationParser<TToken, R> | A new permutation parser representing the current collection of parsers with  | 
Type Parameters
| Name | Description | 
|---|---|
| U | |
| R | 
Build()
Creates a Parser<TToken, T> which runs the current collection of parsers in an order-insensitive manner.
Declaration
public Parser<TToken, T> Build()Returns
| Type | Description | 
|---|---|
| Parser<TToken, T> | A Parser<TToken, T> which runs the current collection of parsers in an order-insensitive manner. |