Pidgin

Class IncrementalParser

Extension methods for constructing and running incremental parsers

  • parsers which reuse the results of previous parses.
Inheritance
Inherited Members
Declaration
public static class IncrementalParser

Methods

Incremental<TToken, T>(Parser<TToken, T>)

Creates a parser which runs parser incrementally.

Declaration
public static Parser<TToken, T> Incremental<TToken, T>(this Parser<TToken, T> parser) where T : class, IShiftable<T>
Parameters
Type Name Description

Parser<TToken, T>

parser

The parser to run incrementally.

Returns
Type Description

Parser<TToken, T>

A parser which runs parser incrementally.

Type Parameters
Name Description

TToken

The type of tokens in the input stream.

T

The type of the value returned by the parser.

ParseIncrementallyOrThrow<TToken, T>(Parser<TToken, T>, ITokenStream<TToken>, IncrementalParseContext?, IConfiguration<TToken>?)

Applies parser to input, reusing results from the supplied context when possible. Throws an exception if parsing failed.

Declaration
public static (IncrementalParseContext Context, T Value) ParseIncrementallyOrThrow<TToken, T>(this Parser<TToken, T> parser, ITokenStream<TToken> input, IncrementalParseContext? context, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

The parser to run incrementally.

ITokenStream<TToken>

input

The input span to parse.

IncrementalParseContext

context

The incremental parse context containing cached results from the previous parse. Can be null if this is the first time running this parser.

IConfiguration<TToken>

configuration

The parser configuration, or null to use the default configuration.

Returns
Type Description

(IncrementalParseContext Context, T Value)

A Result<TToken, T> containing a tuple of the new IncrementalParseContext and the parsed value.

Type Parameters
Name Description

TToken

The type of tokens in the input stream.

T

The type of the value returned by the parser.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseIncrementallyOrThrow<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, IncrementalParseContext?, IConfiguration<TToken>?)

Applies parser to input, reusing results from the supplied context when possible. Throws an exception if parsing failed.

Declaration
public static (IncrementalParseContext Context, T Value) ParseIncrementallyOrThrow<TToken, T>(this Parser<TToken, T> parser, ReadOnlySpan<TToken> input, IncrementalParseContext? context, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

The parser to run incrementally.

ReadOnlySpan<TToken>

input

The input span to parse.

IncrementalParseContext

context

The incremental parse context containing cached results from the previous parse. Can be null if this is the first time running this parser.

IConfiguration<TToken>

configuration

The parser configuration, or null to use the default configuration.

Returns
Type Description

(IncrementalParseContext Context, T Value)

A Result<TToken, T> containing a tuple of the new IncrementalParseContext and the parsed value.

Type Parameters
Name Description

TToken

The type of tokens in the input stream.

T

The type of the value returned by the parser.

Exceptions
Type Condition

ParseException

Thrown when an error occurs during parsing.

ParseIncrementally<TToken, T>(Parser<TToken, T>, ITokenStream<TToken>, IncrementalParseContext?, IConfiguration<TToken>?)

Applies parser to input, reusing results from the supplied context when possible.

Declaration
public static Result<TToken, (IncrementalParseContext Context, T Value)> ParseIncrementally<TToken, T>(this Parser<TToken, T> parser, ITokenStream<TToken> input, IncrementalParseContext? context, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

The parser to run incrementally.

ITokenStream<TToken>

input

The input token stream to parse.

IncrementalParseContext

context

The incremental parse context containing cached results from the previous parse. Can be null if this is the first time running this parser.

IConfiguration<TToken>

configuration

The parser configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, (IncrementalParseContext Context, T Value)>

A Result<TToken, T> containing a tuple of the new IncrementalParseContext and the parsed value.

Type Parameters
Name Description

TToken

The type of tokens in the input stream.

T

The type of the value returned by the parser.

Examples
// First parse (no context)
var (context, result) = parser.ParseIncrementally(input, null).Value;

// ...user edits input, producing newInput and an Edit instance...
var edit = new Edit(new LocationRange(5, 3), 2); // example edit
var newContext = context.AddEdit(edit);

// Incremental parse after edit
var (context2, result2) = parser.ParseIncrementally(newInput, newContext);

ParseIncrementally<TToken, T>(Parser<TToken, T>, ReadOnlySpan<TToken>, IncrementalParseContext?, IConfiguration<TToken>?)

Applies parser to input, reusing results from the supplied context when possible.

Declaration
public static Result<TToken, (IncrementalParseContext Context, T Value)> ParseIncrementally<TToken, T>(this Parser<TToken, T> parser, ReadOnlySpan<TToken> input, IncrementalParseContext? context, IConfiguration<TToken>? configuration = null)
Parameters
Type Name Description

Parser<TToken, T>

parser

The parser to run incrementally.

ReadOnlySpan<TToken>

input

The input span to parse.

IncrementalParseContext

context

The incremental parse context containing cached results from the previous parse. Can be null if this is the first time running this parser.

IConfiguration<TToken>

configuration

The parser configuration, or null to use the default configuration.

Returns
Type Description

Result<TToken, (IncrementalParseContext Context, T Value)>

A Result<TToken, T> containing a tuple of the new IncrementalParseContext and the parsed value.

Type Parameters
Name Description

TToken

The type of tokens in the input stream.

T

The type of the value returned by the parser.

Examples
// First parse (no context)
var (context, result) = parser.ParseIncrementally(input, null).Value;

// ...user edits input, producing newInput and an Edit instance...
var edit = new Edit(new LocationRange(5, 3), 2); // example edit
var newContext = context.AddEdit(edit);

// Incremental parse after edit
var (context2, result2) = parser.ParseIncrementally(newInput, newContext);