Class ParseContext
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
grammarGrammarthe grammar for this context
matcherMatcherthe matcher for the context
stringComparisonStringComparisonthe string comparison mode
Properties
CurrentDirectory
Gets the directory the currently opened document is in
public string CurrentDirectory { get; }
Property Value
Errors
Gets the errors that occured while parsing
public IEnumerable<DiagnosticItem> Errors { get; }
Property Value
FileUri
Gets the file-Uri for this context
public Uri FileUri { get; }
Property Value
Grammar
Gets the grammar for this context
public Grammar Grammar { get; }
Property Value
Imports
Gets a collection of imports
public List<string> Imports { get; }
Property Value
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
IsLastUpdateSuccessful
Indicates whether the last update sent to the parser was successful
public bool IsLastUpdateSuccessful { get; }
Property Value
IsParsing
Gets or sets a flag indicating whether the parser is currently in the process of parsing.
public bool IsParsing { get; }
Property Value
LastSuccessfulRootRuleApplication
Gets the last successful root rule application
public RuleApplication LastSuccessfulRootRuleApplication { get; }
Property Value
Matcher
Gets the matcher used in this parse context
public Matcher Matcher { get; }
Property Value
Root
Gets the semantic root of the parsed text
public object Root { get; }
Property Value
RootRule
Gets the root rule of this parse context
public Rule RootRule { get; }
Property Value
RootRuleApplication
Gets or sets the current root rule application
public RuleApplication RootRuleApplication { get; }
Property Value
StringComparison
Gets the string comparison mode
public StringComparison StringComparison { get; }
Property Value
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
ruleOneOrMoreRulethe star rule in which to add the rule application
toAddRuleApplicationthe rule application that shall be accepted
addedList<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
sequenceSequenceRulethe sequence in which to add a rule application
toAddRuleApplicationthe rule application that shall be accepted
addedList<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
starZeroOrMoreRulethe star rule in which to add the rule application
toAddRuleApplicationthe rule application that shall be accepted
addedList<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
keyobjectThe semantic element of the rule application
valueRuleApplicationThe rule application
AddDiagnosticItem(DiagnosticItem)
Adds the given diagnostic item
public void AddDiagnosticItem(DiagnosticItem diagnosticItem)
Parameters
diagnosticItemDiagnosticItemthe 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
keyobjectThe semantic element of the rule application
valueRuleApplicationThe 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
disposingboolTrue, if managed resources should be disposed of
EnqueueResolveAction(ParseResolveAction)
Enqueues the given resolve action
public virtual void EnqueueResolveAction(ParseResolveAction action)
Parameters
actionParseResolveActionthe 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
Returns
- IEnumerable<T>
A collection of references.
Type Parameters
TThe 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
keyobjectThe semantic element of the rule application
valueRuleApplicationThe rule application to be removed
RemoveDiagnosticItem(DiagnosticItem)
Removes the given diagnostic item
public bool RemoveDiagnosticItem(DiagnosticItem diagnosticItem)
Parameters
diagnosticItemDiagnosticItemthe 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
keyobjectThe semantic element of the referenced rule application
valueRuleApplicationThe the referencing rule application to be removed
RestoreContextElement(RuleApplication)
Calculates the context element for the given rule application
public object RestoreContextElement(RuleApplication ruleApplication)
Parameters
ruleApplicationRuleApplicationthe 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
falseif 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
editTextEdit[]An array of TextEdit objects representing the changes to be applied.
documentUriUriThe 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
keyobjectThe semantic element of the rule application
definitionsICollection<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
keyobjectThe semantic element of the referenced rule application
referencesICollection<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
contextElementobjectthe element in the context of which the string is resolved
inputstringthe textual reference
resolvedTthe resolved reference or the default
Returns
- bool
true, if the reference could be resolved, otherwise false
Type Parameters
T