Table of Contents

Class ParseContext

Namespace
NMF.AnyText
Assembly
NMF.AnyText.Core.dll

The context in which a text is parsed

public class ParseContext : IDisposable
Inheritance
ParseContext
Implements
Derived
Inherited Members

Constructors

ParseContext(Grammar, Matcher, StringComparison)

Creates a new instance

public ParseContext(Grammar grammar, Matcher matcher, StringComparison stringComparison = StringComparison.OrdinalIgnoreCase)

Parameters

grammar Grammar

the grammar for this context

matcher Matcher

the matcher for the context

stringComparison StringComparison

the string comparison mode

Properties

CurrentDirectory

Gets the directory the currently opened document is in

public string CurrentDirectory { get; }

Property Value

string

Errors

Gets the errors that occured while parsing

public IEnumerable<DiagnosticItem> Errors { get; }

Property Value

IEnumerable<DiagnosticItem>

FileUri

Gets the file-Uri for this context

public Uri FileUri { get; }

Property Value

Uri

Grammar

Gets the grammar for this context

public Grammar Grammar { get; }

Property Value

Grammar

Imports

Gets a collection of imports

public List<string> Imports { get; }

Property Value

List<string>

Input

Gets or sets the input text in lines

public string[] Input { get; }

Property Value

string[]

IsExecutingModelChanges

True, if changes to the text should imply changes to the semantic model, otherwise false

public bool IsExecutingModelChanges { get; }

Property Value

bool

IsLastUpdateSuccessful

Indicates whether the last update sent to the parser was successful

public bool IsLastUpdateSuccessful { get; }

Property Value

bool

IsParsing

Gets or sets a flag indicating whether the parser is currently in the process of parsing.

public bool IsParsing { get; }

Property Value

bool

LastSuccessfulRootRuleApplication

Gets the last successful root rule application

public RuleApplication LastSuccessfulRootRuleApplication { get; }

Property Value

RuleApplication

Matcher

Gets the matcher used in this parse context

public Matcher Matcher { get; }

Property Value

Matcher

Root

Gets the semantic root of the parsed text

public object Root { get; }

Property Value

object

RootRule

Gets the root rule of this parse context

public Rule RootRule { get; }

Property Value

Rule

RootRuleApplication

Gets or sets the current root rule application

public RuleApplication RootRuleApplication { get; }

Property Value

RuleApplication

StringComparison

Gets the string comparison mode

public StringComparison StringComparison { get; }

Property Value

StringComparison

Methods

AcceptOneOrMoreAdd(OneOrMoreRule, RuleApplication, List<RuleApplication>)

Decides whether the provided rule application shall be accepted

protected virtual bool AcceptOneOrMoreAdd(OneOrMoreRule rule, RuleApplication toAdd, List<RuleApplication> added)

Parameters

rule OneOrMoreRule

the star rule in which to add the rule application

toAdd RuleApplication

the rule application that shall be accepted

added List<RuleApplication>

the rule applications accepted so far

Returns

bool

true, if the rule application shall be accepted, otherwise false

AcceptSequenceAdd(SequenceRule, ref RuleApplication, List<RuleApplication>)

Decides whether the provided rule application shall be accepted

protected virtual bool AcceptSequenceAdd(SequenceRule sequence, ref RuleApplication toAdd, List<RuleApplication> added)

Parameters

sequence SequenceRule

the sequence in which to add a rule application

toAdd RuleApplication

the rule application that shall be accepted

added List<RuleApplication>

the rule applications accepted so far

Returns

bool

true, if the rule application shall be accepted, otherwise false

AcceptZeroOrMoreAdd(ZeroOrMoreRule, RuleApplication, List<RuleApplication>)

Decides whether the provided rule application shall be accepted

protected virtual bool AcceptZeroOrMoreAdd(ZeroOrMoreRule star, RuleApplication toAdd, List<RuleApplication> added)

Parameters

star ZeroOrMoreRule

the star rule in which to add the rule application

toAdd RuleApplication

the rule application that shall be accepted

added List<RuleApplication>

the rule applications accepted so far

Returns

bool

true, if the rule application shall be accepted, otherwise false

AddDefinition(object, RuleApplication)

Add a rule application to the list of definitions in the document

public void AddDefinition(object key, RuleApplication value)

Parameters

key object

The semantic element of the rule application

value RuleApplication

The rule application

AddDiagnosticItem(DiagnosticItem)

Adds the given diagnostic item

public void AddDiagnosticItem(DiagnosticItem diagnosticItem)

Parameters

diagnosticItem DiagnosticItem

the diagnostic item to add

AddReference(object, RuleApplication)

Add a rule application to the list of references in the document

public void AddReference(object key, RuleApplication value)

Parameters

key object

The semantic element of the rule application

value RuleApplication

The rule application

Dispose()

Dispose of managed and unmanaged resources

public void Dispose()

Dispose(bool)

Dispose of managed and unmanaged resources

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True, if managed resources should be disposed of

EnqueueResolveAction(ParseResolveAction)

Enqueues the given resolve action

public virtual void EnqueueResolveAction(ParseResolveAction action)

Parameters

action ParseResolveAction

the resolve action

GetPotentialReferences<T>(object, string)

Retrieves all potential references for a given context element.

public virtual IEnumerable<T> GetPotentialReferences<T>(object contextElement, string input)

Parameters

contextElement object

The context element.

input string

The input from the user

Returns

IEnumerable<T>

A collection of references.

Type Parameters

T

The type of references to retrieve.

RefreshRoot()

Refreshes the current root value

public void RefreshRoot()

RemoveDefinition(object, RuleApplication)

Remove a rule application from the list of definitions

public void RemoveDefinition(object key, RuleApplication value)

Parameters

key object

The semantic element of the rule application

value RuleApplication

The rule application to be removed

RemoveDiagnosticItem(DiagnosticItem)

Removes the given diagnostic item

public bool RemoveDiagnosticItem(DiagnosticItem diagnosticItem)

Parameters

diagnosticItem DiagnosticItem

the diagnostic item

Returns

bool

true, if the diagnostic item was present, otherwise false

RemoveReference(object, RuleApplication)

Remove a reference of an object from the corresponding list of references

public void RemoveReference(object key, RuleApplication value)

Parameters

key object

The semantic element of the referenced rule application

value RuleApplication

The the referencing rule application to be removed

RestoreContextElement(RuleApplication)

Calculates the context element for the given rule application

public object RestoreContextElement(RuleApplication ruleApplication)

Parameters

ruleApplication RuleApplication

the rule application

Returns

object

A restored semantic context element or null, if it cannot be restored

ShouldParseChange()

Determines whether a change should trigger a reparsing of the document.

public bool ShouldParseChange()

Returns

bool

false if there are pending workspace edits from the system; otherwise, true.

Remarks

This method is designed to prevent infinite loops in a synchronization system. It checks if there are any pending workspace edits that were generated by the system.

TrackAndCreateWorkspaceEdit(TextEdit[], Uri)

Tracks and creates a new WorkspaceEdit with the provided text edits.

public WorkspaceEdit TrackAndCreateWorkspaceEdit(TextEdit[] edit, Uri documentUri)

Parameters

edit TextEdit[]

An array of TextEdit objects representing the changes to be applied.

documentUri Uri

The URI of the document to which the changes apply.

Returns

WorkspaceEdit

A new WorkspaceEdit instance containing the provided text edits.

Remarks

This method increments an internal counter to track the number of pending workspace edits. This is typically used to prevent the system from reparsing changes that were generated by the synchronization logic itself, thus avoiding infinite loops.

TryGetDefinitions(object, out ICollection<RuleApplication>)

Get the rule application for a definition

public bool TryGetDefinitions(object key, out ICollection<RuleApplication> definitions)

Parameters

key object

The semantic element of the rule application

definitions ICollection<RuleApplication>

The rule applications for the definitions

Returns

bool

True, if a definition is present for the given key

TryGetReferences(object, out ICollection<RuleApplication>)

Get the rule applications for references

public bool TryGetReferences(object key, out ICollection<RuleApplication> references)

Parameters

key object

The semantic element of the referenced rule application

references ICollection<RuleApplication>

A list of rule applications that reference the rule application

Returns

bool

True, if references are present for the given key

TryResolveReference<T>(object, string, out T)

Resolves the given input

public virtual bool TryResolveReference<T>(object contextElement, string input, out T resolved)

Parameters

contextElement object

the element in the context of which the string is resolved

input string

the textual reference

resolved T

the resolved reference or the default

Returns

bool

true, if the reference could be resolved, otherwise false

Type Parameters

T