Table of Contents

Class SyntaxParser

Namespace
Alternet.Syntax
Assembly
Alternet.Syntax.v9.dll

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

HasCompletionRepository
InSyntaxUpdate
LineComparer
Options

Gets or sets a flags determining syntax parsing and formatting behavior.

ParseInterval

Specifies delay reparsing should trigger after any change in the editor.

PointComparer
RangeComparer
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.

ThreadParser
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.

AddStyle(string, Color)
AddStyle(string, Color, Color, FontStyle, bool)
AddStyle(string, Color, FontStyle)
AddStyle(string, Color, FontStyle, bool)
AfterLoad()
AssignParser(ISyntaxParser)
BeforeLoad()
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.

CreateListMembers()
CreateParameterInfo()
CreateRepository()

Creates ICodeCompletionRepository to perform code completion functionality for this parser.

CreateThreadParser()
CurChar()
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.

FindMember(string, IListMembers, out int)
FindPartial(ISortList<ICodeCompletionProviderItem>, IListMember, out int)
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.

FinishParsing(ISyntaxParser)
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(CodeCompletionArgs, StringItemInfo[], Point)
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.

GetLexerState(int)
GetLexerStyle(int)
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.

GetNodeForCodeCompletion(ref Point)
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(ISyntaxNode, int, ref int)
GetSmartIndent(ISyntaxNodes, int, bool)
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.

GetSyntaxErrors(IList<ISyntaxError>, ISyntaxNode)
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.

IndexOfLastNonWhitespaceChar(string)
IndexOfNonWhitespaceChar(string)
InitCopyright()
InitDefaultStyles()
InitLanguage()
InitLexer()
InitStyles()
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.

IsFirstIdentChar(char)
IsIdentChar(char)
IsImmediateCompletionType(CodeCompletionType)
LexIdent()
LexNum()
LexSpace()
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.

OnAutoIndentCharsChanged()
OnCodeCompletionCharsChanged()
OnCodeCompletionStopCharsChanged()
OnDelimitersChanged()
OnOptionsChanged()
OnParseIntervalChanged()
OnRepositoryChanged()
OnSmartFormatCharsChanged()
OnSyntaxTreeChanged()
OnTextChanged(ITextUndo)

Responds to incremental change of the text in the editor.

OnTextParsed()

Raises TextParsed event.

OnXmlSchemeChanged()
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.

Outline(IList<IRange>, ISyntaxNode, int)
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.

ParseToken(LexerProc, ref int, ref int, ref int, ref int, ref int, ref int)
PartialCompare(IListMember, IListMember)
PartialCompare(IListMember, IListMember, int, bool)
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.

PrevNonWhiteSpaceLine(int)
ProcessAutoComplete(string, Point, out string)

Checks whether end-of-block code needs inserting.

ProcessIndentationBasedFolding()
ProcessSnippetBody(string, Point, out string)

Checks whether snippet body code needs inserting.

RegisterLexerProc(int, LexerProc)
RegisterLexerProc(int, char, LexerProc)
RegisterLexerProc(int, char, char, LexerProc)
RegisterLexerProc(int, char[], LexerProc)
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.

SortMembers(IListMembers)
StartParsing(string, int, int)

Prepares parser to parse the specified range of the text.

StateChanged()
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.