Table of Contents

Class CompiledGrammar

Namespace
Utils.Parser.Runtime
Assembly
Utils.Parser.dll

A ready-to-use grammar instance that encapsulates the full parse pipeline: LexerEngine tokenization followed by ParserEngine parsing.

Obtain an instance from a resolved ParserDefinition via the constructor, or compile directly from an ANTLR4 grammar source string via Antlr4GrammarConverter.Compile(grammarText).

public sealed class CompiledGrammar
Inheritance
CompiledGrammar
Inherited Members
Extension Methods

Constructors

CompiledGrammar(ParserDefinition)

Initialises a CompiledGrammar from a fully resolved ParserDefinition (i.e. the output of RuleResolver.Resolve).

public CompiledGrammar(ParserDefinition definition)

Parameters

definition ParserDefinition

A resolved grammar definition.

CompiledGrammar(ParserDefinition, ParserRuntimeFeaturePolicy)

Initialises a CompiledGrammar from a fully resolved ParserDefinition with an explicit runtime feature policy.

public CompiledGrammar(ParserDefinition definition, ParserRuntimeFeaturePolicy runtimeFeaturePolicy)

Parameters

definition ParserDefinition

A resolved grammar definition.

runtimeFeaturePolicy ParserRuntimeFeaturePolicy

Runtime feature policy applied to parser execution.

Properties

Definition

The resolved ParserDefinition backing this grammar.

public ParserDefinition Definition { get; }

Property Value

ParserDefinition

Methods

Parse(string)

Runs the full parse pipeline on input: tokenizes the text with the embedded LexerEngine and then builds a parse tree with the ParserEngine.

public ParseNode Parse(string input)

Parameters

input string

Source text to parse.

Returns

ParseNode

The root ParseNode. Returns an ErrorNode when the input does not conform to the grammar rather than throwing an exception.

Tokenize(string)

Tokenizes input and returns all tokens produced by the lexer, in source order. Skipped tokens (e.g. whitespace with -> skip) are already excluded from the stream at this stage.

public IReadOnlyList<Token> Tokenize(string input)

Parameters

input string

Source text to tokenize.

Returns

IReadOnlyList<Token>

Read-only list of tokens.