This topic explains when the syntax tree is created and how to access it.
The following topics are prerequisites to understanding this topic:
The TextDocument triggers lexical analysis automatically because the document is stored as tokens, but it does not do so for syntax analysis. This must be done by using either the Parse or ParseAsync methods. There is no difference between these methods other than the fact that ParseAsync
will analyze the document on a background thread so the calling thread is not blocked. If ParseAsync
is used to parse a document, the caller must listen to the PropertyChanged event to get notified when the SyntaxTree property is updated with the new syntax tree created by the syntax analyzer.
Once syntax analysis is complete, the TextDocument.SyntaxTree
property will be an instance of type SyntaxTree, a class defined in the Infragistics.Documents.Parsing namespace. The SyntaxTree.RootNode property will always be associated with the Grammar.StartSymbol of the grammar used to parse the document. It is an instance of the SyntaxNode class, a class used to represent all nodes in the syntax tree. Like the snapshot, the syntax tree and all its nodes are immutable - they are for obtaining information only.
The following topics provide additional information related to this topic.