Skip to content

Latest commit

 

History

History
1068 lines (692 loc) · 49.4 KB

File metadata and controls

1068 lines (692 loc) · 49.4 KB

Monda

Contents

ParseFunction`2 type

Namespace

Monda

Summary

Delegate that attempts to parse a result from an input data set, beginning at a specific point

Returns

A ParseResult`1 indicating the success or failure of the parse attempt

Parameters
Name Type Description
data T:Monda.ParseFunction`2 Input data to parse
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of the parser

ParseResult type

Namespace

Monda

Summary

Generic helper functions for constructing ParseResult`1 instances

Fail``1() method

Summary

Create a failure result with the default value for T

Returns

A failure ParseResult`1 with it's value set to default(T)

Parameters

This method has no parameters.

Generic Types
Name Description
T The underlying value type

Fail``1(value) method

Summary

Create a failure result with a specified value

Returns

A failure ParseResult`1 with it's value set to value

Parameters
Name Type Description
value ``0@ The value of the result
Generic Types
Name Description
T The underlying value type

Success``1(value,start,length) method

Summary

Create a success result

Returns
Parameters
Name Type Description
value ``0@ The value of the result
start System.Int32 The position at which the result started
length System.Int32 The length of data used to parse value
Generic Types
Name Description
T The underlying value type

ParseResult`1 type

Namespace

Monda

Summary

Represents the result of a parsing operation

Generic Types
Name Description
TValue Underlying value type
See Also

Length property

Summary

The length of data in the data source used to construct this result

Start property

Summary

The position in the data source where this result started

Success property

Summary

Indicates if this result was successful

Value property

Summary

The underlying result value

Parser type

Namespace

Monda

Summary

Static Parser helper methods

IsAny``1(values) method

Summary

Creates a Parser`2 that yields a single TSource item if it exists in values, using the default comparer for TSource to compare items

Returns

A Parser`2 that will succeed if the TSource item at the parser's current position exists in values

Parameters
Name Type Description
values System.Collections.Generic.IReadOnlyList{``0} Item to compare
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentNullException values is null

IsAny``1(values,comparer) method

Summary

Creates a Parser`2 that yields a single TSource item if it exists in values, using comparer to compare values

Returns

A Parser`2 that will succeed if the TSource item at the parser's current position exists in values

Parameters
Name Type Description
values System.Collections.Generic.IReadOnlyList{``0} Item to compare
comparer System.Collections.Generic.IEqualityComparer{``0} Comparer to use to determine equality between TSource items
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentException values is empty
System.ArgumentNullException values or comparer is null

IsNotAny``1(values) method

Summary

Creates a Parser`2 that yields a single TSource item if it does not exist in values, using the default comparer for TSource to compare items

Returns

A Parser`2 that will succeed if the TSource item at the parser's current position does not exist in values

Parameters
Name Type Description
values System.Collections.Generic.IReadOnlyList{``0} Item to compare
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentNullException values is null

IsNotAny``1(values,comparer) method

Summary

Creates a Parser`2 that yields a single TSource item if it does not exist in values, using comparer to compare values

Returns

A Parser`2 that will succeed if the TSource item at the parser's current position does not exist in values

Parameters
Name Type Description
values System.Collections.Generic.IReadOnlyList{``0} Item to compare
comparer System.Collections.Generic.IEqualityComparer{``0} Comparer to use to determine equality between TSource items
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentException values is empty
System.ArgumentNullException values or comparer is null

IsNot``1(value) method

Summary

Creates a Parser`2 that yields a single TSource item if it does not equal value, using the default comparer for TSource to compare items

Returns

A parser that will succeed if the TSource item at the parser's current position does not equal value

Parameters
Name Type Description
value ``0 Item to match
Generic Types
Name Description
TSource The type of items in the input data

IsNot``1(value,comparer) method

Summary

Creates a Parser`2 that yields a single TSource item if it does not equal value, using comparer to compare items

Returns

A parser that will succeed if the TSource item at the parser's current position does not equal value

Parameters
Name Type Description
value ``0 Item to match
comparer System.Collections.Generic.IEqualityComparer{``0} Comparer used to determine equality between TSource items
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentNullException comparer is null

IsSequence``1(value) method

Summary

Creates a Parser`2 that yields a IReadOnlyList`1 if the sequence of items at the current position equals value, using the default comparer for TSource to compare items

Returns

A Parser`2 that will succeed if the sequence of TSource items at the parser's current position equals value

Parameters
Name Type Description
value System.Collections.Generic.IReadOnlyList{``0} ReadOnlyMemory`1 containing the sequence of TSource items to compare
Generic Types
Name Description
TSource The type of items in the input data

IsSequence``1(value,comparer) method

Summary

Creates a Parser`2 that yields a IReadOnlyList`1 if the sequence of items at the current position equals value, using comparer to compare items

Returns

A Parser`2 that will succeed if the sequence of TSource items at the parser's current position equals value

Parameters
Name Type Description
value System.Collections.Generic.IReadOnlyList{``0} ReadOnlyMemory`1 containing the sequence of TSource items to compare
comparer System.Collections.Generic.IEqualityComparer{``0} Comparer used to determine equality between TSource items
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentException value is empty
System.ArgumentNullException value or comparer is null

Is``1(value) method

Summary

Creates a Parser`2 that yields a single TSource item if it equals value, using the default comparer for TSource to compare items

Returns

A parser that will succeed if the TSource item at the parser's current position equals value

Parameters
Name Type Description
value ``0 Item to match
Generic Types
Name Description
TSource The type of items in the input data

Is``1(value,comparer) method

Summary

Creates a Parser`2 that yields a single TSource item if it equals value, using the comparer to compare items.

Returns

A Parser`2 that will succeed if the TSource item at the parser's current position equals value

Parameters
Name Type Description
value ``0 Item to compare
comparer System.Collections.Generic.IEqualityComparer{``0} Comparer used to determine equality between TSource items
Generic Types
Name Description
TSource The type of items in the input data

TakeUntil``2(next,min) method

Summary

Creates a Parser`2 that yields the range of TSource items from the current parser until next succeeds

Returns

A [](#!-Parser<TSource, Tuple<Range, TNext>> 'Parser<TSource, Tuple<Range, TNext>>') that yields a tuple containing the Range that was matched and the result of next

Parameters
Name Type Description
next Monda.Parser{``0,``1} A Parser`2 that will succeed at the end of the range
min System.Int32 Minimum number of matches required (inclusive)
Generic Types
Name Description
TSource The type of items in the input data
TNext The return type of the next parser
Exceptions
Name Description
System.ArgumentNullException next is null
System.ArgumentOutOfRangeException min is less than 0

TakeWhile``1(predicate,min,max) method

Summary

Creates a Parser`2 that yields the range of TSource items from the current parser position matching predicate

Returns

A Parser`2 that yields the Range of data that was matched

Parameters
Name Type Description
predicate System.Func{``0,System.Boolean} Predicate that is invoked for each TSource item
min System.Int32 Minimum number of matches required (inclusive)
max System.Nullable{System.Int32} Maximum number of matches allowed (inclusive)
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentNullException predicate is null
System.ArgumentOutOfRangeException min is less than 0 or max is less than min

TakeWhile``1(predicate,min,max) method

Summary

Creates a Parser`2 that yields the range of TSource items from the current parser position matching predicate

Returns

A Parser`2 that yields the Range of data that was matched

Parameters
Name Type Description
predicate Monda.ParserPredicate{``0} Predicate that is invoked for each TSource item
min System.Int32 Minimum number of matches required (inclusive)
max System.Nullable{System.Int32} Maximum number of matches allowed (inclusive)
Generic Types
Name Description
TSource The type of items in the input data
Exceptions
Name Description
System.ArgumentNullException predicate is null
System.ArgumentOutOfRangeException min is less than 0 or max is less than min
Remarks

The ReadOnlySpan`1 passed to predicate is a slice starting at the parser's intial position and the index will increase from 0

ParserExtensions type

Namespace

Monda

Between``4(self,left,right) method

Summary

Creates a new parser that ensures that the current parser is between left and right

Returns

A new Parser`2 that returns the result of the current parser if it is found between left and right

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
left Monda.Parser{``0,``2} The first parser to be executed
right Monda.Parser{``0,``3} The last parser to execute
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
TLeft The result type of left
TRight The result type of right

FollowedBy``3(self,next) method

Summary

Create a new parser that ensures that the current parser is followed by next

Returns

A new Parser`2 that executes self and next in that order and returns the TResult from self

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
next Monda.Parser{``0,``2} The parser to execute after the current parser, its result will be discarded
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
TNext The result type of next
Remarks

Although the parsing position will be advanced accordingly, the result of next will be discarded. Use Then``3 if you need to capture the result

ManyUntil``3(self,next,min) method

Summary

Create a new parser that executes the current parser until another parser succeeds, then aggregates and combines the results

Returns

A new Parser`2 that executes the current parser until next succeeds, aggregating and combining the results

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
next Monda.Parser{``0,``2} The parser that determines when to stop repeating
min System.Int32 The minimum number of times the parser must execute
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
Exceptions
Name Description
System.StackOverflowException If the current parser returns a zero-length result
See Also

Many``2(self,min,max) method

Summary

Create a new parser that executes the current parser until failure or an upper bound is reached and aggregates the results

Returns

A new Parser`2 that executes the current parser between min and max times and aggregates the results

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
min System.Int32 The minimum number of times the parser must execute (inclusive)
max System.Nullable{System.Int32} The maximum number of times the parser can execute (inclusive). A null value indicates there is no upper bound
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
Exceptions
Name Description
System.StackOverflowException If the current parser returns a zero-length result
See Also

Map``3(self,map) method

Summary

Create a new parser that maps the result of the current parser to a new value

Returns

A new Parser`2 that executes the current parser and maps the value to a new value

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
map Monda.MapFunction{``0,``1,``2} A function that maps the value from the current parser to a new value
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
TNext The mapped value type

Optional``2(self,defaultValue) method

Summary

Create a parser that returns a zero-length default result if the current parser fails

Returns

A new Parser`2 that executes the current parser, returning its result when successful or a default zero-length result otherwise

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
defaultValue ``1 The default value to return if the current parser fails
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self

Or``2(self,other) method

Summary

Create a new parser that executes the current parser, or other if the current parser fails

Returns

A new Parser`2 that returns the first successful result of the current parser and other in that order

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
other Monda.Parser{``0,``1} The other parser to execute if the current one is fails
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self and other

PrecededBy``3(self,previous) method

Summary

Create a new parser that ensures that the current parser is preceded by previous

Returns

A new Parser`2 that executes previous and self in that order and returns the TResult from self

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
previous Monda.Parser{``0,``2} The parser to execute before the current parser, its result will be discarded
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
TPrevious The result type of previous
Remarks

Although the parsing position will be advanced accordingly, the result of previous will be discarded. Use Then``3 if you need to capture the result

Repeat``2(self,count) method

Summary

Create a new parser that executes the current parser a fixed number of times and aggregates the results

Returns

A new Parser`2 that executes the current parser count times and aggregates the results

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
count System.Int32 The number of times to repeat the current parser
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
Exceptions
Name Description
System.StackOverflowException If the current parser returns a zero-length result
See Also

SkipMany``2(self,min,max) method

Summary

Create a new parser that executes the current parser until failure or an upper bound is reached and counts the number of results

Returns

A new Parser`2 that executes the current parser between min and max times and counts the number results

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
min System.Int32 The minimum number of times the parser must execute (inclusive)
max System.Nullable{System.Int32} The maximum number of times the parser can execute (inclusive). A null value indicates there is no upper bound
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
Exceptions
Name Description
System.StackOverflowException If the current parser returns a zero-length result
See Also

SkipUntil``3(self,next,min) method

Summary

Create a new parser that executes the current parser until another parser succeeds, then counts and combines the results

Returns

A new Parser`2 that executes the current parser until next succeeds, counting and combining the results

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
next Monda.Parser{``0,``2} The parser that determines when to stop repeating
min System.Int32 The minimum number of times the parser must execute
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
Exceptions
Name Description
System.StackOverflowException If the current parser returns a zero-length successful result
See Also

Then``3(self,next) method

Summary

Create a new parser that executes the current parser and next in order and combines the results

Returns

A new Parser`2 that executes self and next is sequence and returns a Tuple`2 of the results if both are successful

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
next Monda.Parser{``0,``2} The next Parser`2
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of the current parser
TNext The result type of next

TryMap``3(self,tryMap) method

Summary

Create a new parser that tries to map the result of the current parser to a new value

Returns

A new Parser`2 that executes the current parser and tries to map the value to a new value

Parameters
Name Type Description
self Monda.Parser{``0,``1} The current parser
tryMap Monda.TryMapFunction{``0,``1,``2} A function that tries to map the value from the current parser to a new value
Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of self
TNext The mapped value type

ParserPredicate`1 type

Namespace

Monda

Summary

Predicate that tests the TSource item at the current index.

Returns

True if the TSource item at the current index is acceptable, false otherwise

Parameters
Name Type Description
data T:Monda.ParserPredicate`1 Input data to parse
Generic Types
Name Description
TSource The type of items in the input data

Parser`2 type

Namespace

Monda

Summary

Fundamental parsing unit to extract one TResult output from a set of TSource input items

Generic Types
Name Description
TSource The type of items in the input data
TResult The result type of the parser

Range type

Namespace

Monda

Summary

Represents start and length properties that define a range in contiguous data