Class SyntaxParser
Represents properties and methods to perform syntax analysis of the text.
public class SyntaxParser : Parser, IComponent, IDisposable, ISyntaxParser, IParser, ILexer, INotify, IUpdate, IImport
- Inheritance
-
SyntaxParser
- Implements
- Derived
Examples
Here is how to declare a SyntaxParser from the C# code:
using Alternet.Syntax;
using Alternet.Editor;
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
var parser = new SyntaxParser();
var edit = new SyntaxEdit();
edit.Parent = this;
edit.Lexer = parser;
parser.Options = SyntaxOptions.SmartIndent | SyntaxOptions.CodeCompletion | SyntaxOptions.Outline | SyntaxOptions.SyntaxErrors;
string fileName = "myfile.cs";
if (System.IO.File.Exists(fileName))
{
parser.FileName = fileName;
edit.LoadFile(fileName);
}
}
}
Here is how to declare a SyntaxParser from the Visual Basic code:
Imports Alternet.Syntax
Imports Alternet.Editor
Imports System
Partial Public Class Form1
Inherits Form
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim parser = New SyntaxParser()
Dim edit = New SyntaxEdit()
edit.Parent = Me
edit.Lexer = parser
parser.Options = SyntaxOptions.SmartIndent Or SyntaxOptions.CodeCompletion Or SyntaxOptions.Outline Or SyntaxOptions.SyntaxErrors
Dim fileName As String = "myfile.cs"
If System.IO.File.Exists(fileName) Then
parser.FileName = fileName
edit.LoadFile(fileName)
End If
End Sub
End Class
Remarks
SyntaxParser is a base class of non-visual components that perform both lexical, syntax, and semantic analysis of the text. The SyntaxParser itself provides both lexical and syntax analysis, driving the syntax highlighting features of associated edit controls. Descendant classes implement additional syntax and semantic analysis for various programming languages, enabling advanced code writing features such as code completion, code outlining, code formatting, and syntax error highlighting.
SyntaxParser implements lexical analysis based on the collection of the lexical states and provides basic properties and methods for syntax analysis.
The most important properties and methods of the SyntaxParser are:
The SyntaxTree property contains a hierarchical collection of the ISyntaxNode elements that describe a particular language element.
The Options property determines how the edit controls should use the syntax analysis performed by the parser.
Constructors
- SyntaxParser()
Initializes a new instance of the
SyntaxParser
class with default settings.
- SyntaxParser(IContainer)
Initializes a new instance of the
SyntaxParser
class with default settings.
Properties
- Aborted
Gets or sets boolean variable indicating whether parsing process has been aborted.
- AutoIndentChars
Gets or sets a collection of characters that initializes an indentation procedure when typing.
- CaseSensitive
Gets or sets a boolean value that indicates whether
SyntaxParser
should perform case-sensitive analysis of its content.
- CodeCompletionChars
Gets or sets a collection of characters that initializes a code completion procedure when typing.
- CodeCompletionStopChars
Gets or sets a collection of characters that finalizes a code completion procedure when typing.
- CodeSnippets
When implemented by a class, returns code snippets for the given parser.
- CompletionRepository
Gets or sets an
ICodeCompletionRepository
that holds methods for code completion purposes.
- Delimiters
Gets or sets a collection of characters representing delimiters
- ExpressionEvaluator
Gets or sets an
IExpressionEvaluator
instance using to evaluate conditional defines.
- FileName
Gets or sets file name of the file being parsed.
- FoldedRanges
When implemented by a class, gets or sets a collection of
IRange
elements representing ranges based on the indentation levels of the text
- Options
Gets or sets a flags determining syntax parsing and formatting behavior.
- ParseInterval
Specifies delay reparsing should trigger after any change in the editor.
- SmartFormatChars
Gets or sets a collection of characters that initializes a smart formatting procedure when typing.
- SupportsThread
Gets boolean value indicating whether parser supports working in thread.
- SyntaxTree
Gets or sets a hierarchical collection of
ISyntaxNode
elements representing abstract syntax tree of the text being parsed.
- UseScheme
Gets or sets a boolean value that indicates whether
ISyntaxParser
should perform lexical analysis based on it's rules rather than using internal method.
- XmlScheme
Gets or sets an xml representation of
Scheme
property.
Methods
- Abort()
Aborts parsing process by raising StopParseException exception.
- BlockDeleting(Rectangle)
Removes all nodes from the node collection which position in the specified rectangle.
- CodeCompletion(string, StringItemInfo[], Point, CodeCompletionArgs)
Performs code completion for the specified text representing language element.
- CodeCompletion(string, StringItemInfo[], Point, bool, CodeCompletionArgs)
Performs code completion for the specified text representing language element.
- CreateRepository()
Creates
ICodeCompletionRepository
to perform code completion functionality for this parser.
- Dispose(bool)
Releases the unmanaged resources used by the Component and optionally releases the managed resources.
- FindCodeActions(Point, Point, Point, ISyntaxError, bool)
Locates and highlights available code fixes and code refactors for given position in the texts.
- FindDeclaration(Point)
Finds the declaration node at given position.
- FindDeclaration(string, Point)
Finds the declaration node at given position.
- FindDeclarationAsync(Point, CancellationToken)
Finds the declaration location at given position.
- FindImplementations(Point, IRangeList, bool)
Locates all implementations at given position and in the text.
- FindImplementationsAsync(Point, IRangeList, bool, CancellationToken)
Locates declaration at given position and finds all implementations to this declaration in the text.
- FindReferences(ISyntaxNode, ISyntaxNodes)
Locates all references to the node in the text.
- FindReferences(Point)
Locates and highlights references at given position in the text.
- FindReferences(Point, IRangeList, bool)
Locates declaration at given position and finds all references to this declaration in the text.
- FindReferencesAsync(Point, IRangeList, bool, CancellationToken)
Locates declaration at given position and finds all references to this declaration in the text.
- FindReferencesAsync(Point, CancellationToken)
Locates and highlights references at given position in the text.
- FinishParsing()
Commits parsing process.
- GetActiveStatementAt(Point)
Gets
IRange
that corresponds to the statement at specified position.
- GetAutoFormatNode(Point, bool, out Point)
Gets syntax block node at specified position.
- GetCodeFixes(ISyntaxError, bool)
Retrieves all code fixes available for the given syntax error.
- GetCodeFixesAsync(ISyntaxError, bool, CancellationToken)
Retrieves all code fixes available for the given syntax error in async mode.
- GetCodeRefactors(Point, Point, bool)
Retrieves all applicable refactors at given range.
- GetCodeRefactorsAsync(Point, Point, bool, CancellationToken)
Retrieves all applicable refactors at given range in async mode.
- GetCompletionType(CodeCompletionArgs)
Obtains type of code completion window from specifies
CodeCompletionArgs
parameter.
- GetCompletionType(char)
Obtains type of code completion window from specifies
char
parameter.
- GetContentDividers(IList<int>)
Gets list of content dividers.
- GetDeclarationAt(Point)
Gets
IRange
that corresponds to the declafration at specified position.
- GetMultiLineComment(Point, out string, out string)
Gets the start and symbols multi-line comment.
- GetMultiLineComment(out string, out string)
Gets the start and symbols multi-line comment.
- GetNodeAt(Point)
Gets
ISyntaxNode
that corresponds to the specified position.
- GetRangeAt(Point)
Gets
IRange
that contains given position.
- GetRangeAt(Point, IList<IRange>)
Gets
IRange
that contains given position.
- GetSingleLineComment()
Gets the string that represents start symbol of single line comment.
- GetSingleLineComment(Point)
Gets the string that represents start symbol of single line comment.
- GetSmartIndent(int, bool)
Returns indentation level of specified line.
- GetSmartIndent(int, bool, out bool)
Returns indentation level of specified line.
- GetSmartIndentString(int, bool, bool, int)
Returns indentation string for specified line.
- GetStructureGuideLines(IList<IRange>)
Gets list of guide lines.
- GetSyntaxErrors(IList<ISyntaxError>)
Retrieves all syntax errors found while analyzing the text.
- HasCodeFixes(ISyntaxError, bool)
When implemented by a class, determines if code fixes are available for a given syntax error.
- HasCodeFixesAsync(ISyntaxError, bool, CancellationToken)
Determines if code fixes are available for a given syntax error in async mode.
- HasCodeRefactors(Point, Point, bool)
When implemented by a class, determines if code fixes are available for a given syntax error.
- HasCodeRefactorsAsync(Point, Point, bool, CancellationToken)
Determines if code fixes are available for a given syntax error in async mode.
- IsCodeCompletionChar(char, byte, ref int)
Returns boolean value indicating that given character initializes a code completion procedure when typing.
- IsDeclaration(ISyntaxNode)
Indicates whether specified node represents declaration elements.
- LoadFile(string)
Loads the contents of the specified file.
- LoadFile(string, Encoding)
Loads the contents of the specified file with specified encoding.
- LoadStream(Stream)
Loads the contents of the specified stream.
- LoadStream(Stream, Encoding)
Loads the contents of the specified stream.
- LoadStream(TextReader)
Loads the contents of the specified stream.
- OnTextChanged(ITextUndo)
Responds to incremental change of the text in the editor.
- OnTextParsed()
Raises TextParsed event.
- Outline()
Creates outlined sections for parsed text using result of syntax analysis.
- Outline(IList<IRange>)
Creates outlined sections for parsed text using result of syntax analysis and fills ranges parameter by the collection of the outlined sections.
- ParseText(int, int, string, ref StringItemInfo[])
Performs lexical analysis of given text.
- ParseText(int, int, string, ref int, ref int, ref int)
Performs lexical analysis of given text.
- PositionChanged(int, int, int, int)
Changes positions of any syntax nodes and its elements located next to the specified position.
- Prepare(string, IStringList, ISyntaxTree, bool, PrepareReason)
Sets lines to parse.
- Prepare(string, IStringList, PrepareReason)
When implemented by a class, sets lines to parse.
- ProcessAutoComplete(string, Point, out string)
Checks whether end-of-block code needs inserting.
- ProcessSnippetBody(string, Point, out string)
Checks whether snippet body code needs inserting.
- ReparseBlock(Point)
Reparses syntax block at specified position.
- ReparseBlock(ref Point, string, out ISyntaxNode, CodeCompletionType)
Reparses syntax block at specified position.
- ReparseText()
Reparses entire text.
- ReparseText(bool)
Reparses entire text.
Specifies whether parser should perform the task in the separate thread
- ReparseText(bool, int, int)
Reparses entire text.
Specifies whether parser should perform the task in the separate thread Specifies first changed line in the source text. Specifies last changed line in the source text.
- Reset()
Resets
SyntaxParser
to the start position.
- ResetAutoIndentChars()
Resets
AutoIndentChars
to the default value.
- ResetCodeCompletionChars()
Resets
CodeCompletionChars
to the default value.
- ResetCodeCompletionStopChars()
Resets
CodeCompletionStopChars
to the default value.
- ResetOptions()
Resets
Options
to the default value.
- ResetParseInterval()
Resets
ParseInterval
to the default value.
- ResetSmartFormatChars()
Resets
SmartFormatChars
to the default value.
- RestoreSyntaxTree()
Restores syntax tree, stored by
SaveSyntaxTree
method.
- SaveSyntaxTree()
Saves current syntax tree.
- ShouldSerializeAutoIndentChars()
Indicates whether the
AutoIndentChars
property should be persisted.
- ShouldSerializeCodeCompletionChars()
Indicates whether the
CodeCompletionChars
property should be persisted.
- ShouldSerializeCodeCompletionStopChars()
Indicates whether the
CodeCompletionStopChars
property should be persisted.
- ShouldSerializeOptions()
Indicates whether the
Options
property should be persisted.
- ShouldSerializeParseInterval()
Indicates whether the
ParseInterval
property should be persisted.
- ShouldSerializeSmartFormatChars()
Indicates whether the
SmartFormatChars
property should be persisted.
- SmartFormat(ref Point, bool, int, ITextUndoList, string)
Formats block of text according to the parser rules.
- SmartFormat(ref Point, ref Point, bool, int, bool, ITextUndoList)
Formats block of text according to the parser rules.
Start position of the block End position of the block Indicates whether indentation string should contain spaces or tabs Specifies number of spaces in tab Specifies if whole syntax block containing start and end point should be formatted List containing insertion or deletion of text fragments.
- SmartFormatLine(int, string, StringItemInfo[], ITextUndoList)
Formats line according to the parser rules.
- SmartFormatLine(int, string, StringItemInfo[], ITextUndoList, out bool)
Formats line according to the parser rules.
- StartParsing(string, int, int)
Prepares parser to parse the specified range of the text.
- StopParsing()
Aborts parsing process.
- SupportsAsyncParsing()
Indicates whether parser supports async parsing.
- SupportsCodeActions()
Indicates whether code fixes or code refactors are supported.
- SupportsCodeCompletionFiltering(CodeCompletionType)
When implemented by a class, returns boolean value indicating that information can be filtered for given code completion type.
- SupportsContentDividers()
Indicates whether content dividers are supported.
- SupportsTextChanges()
Indicates whether parser supports incremental text changes.
Events
- TextReparsed
Occurs when
SyntaxParser
text content is fully parsed.