Table of Contents

Class CParser

Namespace
Alternet.Syntax.Parsers.Advanced
Assembly
Alternet.Syntax.Parsers.Advanced.v9.dll

Represents a class that performs syntax and lexical analysis of specified Ansi-C code text.

[ToolboxBitmap(typeof(CParser), "Images.CParser.Icon.bmp")]
public class CParser : SyntaxParser, IComponent, IDisposable, ISyntaxParser, IParser, ILexer, INotify, IUpdate, IImport
Inheritance
CParser
Implements

Examples

Here is how to declare a CParser and assign it to the edit control from the C# code:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        var parser = new Alternet.Syntax.Parsers.Advanced.CParser();
        var edit = new Alternet.Editor.SyntaxEdit();
        edit.Parent = this;
        edit.Lexer = parser;

        string fileName = "myfile.c";
        if (System.IO.File.Exists(fileName))
        {
            parser.FileName = fileName;
            edit.LoadFile(fileName);
        }
    }
}

Here is how to declare a CParser and assign it to the edit control from the Visual Basic code:

Partial Public Class Form1
    Inherits Form

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim parser = New Alternet.Syntax.Parsers.Advanced.CParser()
        Dim edit = New Alternet.Editor.SyntaxEdit()
        edit.Parent = Me
        edit.Lexer = parser
        Dim fileName As String = "myfile.c"

        If System.IO.File.Exists(fileName) Then
            parser.FileName = fileName
            edit.LoadFile(fileName)
        End If
    End Sub
End Class

Remarks

CParser is a non-visual component designed to perform syntax highlighting and provide advanced code editing capabilities for ANSI-C language. This parser supports full syntax and analysis of the ANSI-C code. When linked to the SyntaxEdit or TextEditor controls, this parser drives additional features such as code completion, code outlining, code formatting, and underlying syntax errors and warnings.

Please note that CPaser is designed to work with single C files; it does not support parsing of the include files or macro expansion. For industrial-grade C/C++ parsing, please refer to <xref=Alternet.Syntax.Parsers.Lsp.Clangd> namespace.

Here are some of the essential features provided by the CParser:

  • Syntax Highlighting
  • IntelliSense (Code completion)
  • Code Outlining
  • Structure guidelines
  • Formatting a selected block of text or the whole document.

Constructors

CParser()

Fields

comments
defaultTypeName
defines
expressionEvaluator
lexCommentEndProc
lexCommentProc
lexDefineCommentEndProc
lexDefineCommentProc
lexDefineProc
lexDefineStringProc
lexIdentifierProc
lexIncludeProc
lexNumberProc
lexStringEndProc
lexStringProc
lexSymbolProc
lexWhitespaceProc
lexXmlCommentProc
lexXmlCommentTagProc
prevPosition
prevValidToken
reswords
savePrevPosition

Properties

CaseSensitive

Gets or sets a boolean value that indicates whether CParser should perform case-sensitive analysis of its content.

ExpressionEvaluator

Gets or sets an IExpressionEvaluator instance using to evaluate conditional defines.

XmlParser

Methods

AddAttribute(ISyntaxAttribute)
AddNode(ISyntaxNode)
AddXmlNode(ISyntaxNode, ISyntaxNode, Point)
AfterDeclaration(ISyntaxNode)
AssignParser(ISyntaxParser)
BeforeDeclaration(ISyntaxNode)
ClearStack()
CreateExpressionEvaluator()
CreateExpressionNode(Point, string, int, ISyntaxNode, bool)
CreateListMembers()
CreateParameterInfo()
CreateRepository()

Creates ICodeCompletionRepository to perform code completion functionality for this parser.

Expected(CLexerToken)
Expected(CLexerToken, CLexerToken)
Expected(int)
FindMethodDeclaration(ISyntaxNode, ISyntaxNode)
FinishParsing()

Commits parsing process.

FixupComments()
FixupRegions(ISyntaxNode)
GetAutoFormatNode(Point, bool, out Point)

Obtains block node at specified position.

GetBlockNode(ISyntaxNode, Point)
GetCompletionType(char)

Obtains type of code completion window from specifies char parameter.

GetLastChild(ISyntaxNode)
GetLexerStyle(int)
GetSingleLineComment()

Gets the string that represents start symbol of single line comment.

GetStructureGuideLines(IList<IRange>)

Gets list of guide lines.

GetValidNode(ISyntaxNode)
IdentifierExpected()
InitBoolExtension()

Enables usage of bool, true and false as reserved words.

InitDefines()
InitLexer()
InitReswords()
InitStyles()
IsBaseList(int)
IsBuiltInType(int)
IsComment(int)
IsDeclaration(ISyntaxNode)

Indicates whether specified node is a declaration node (contains declaration of some syntax structure, such as class, namespace and so on).

IsFunctionPointer(out string, out string, out bool, bool, ref ISyntaxNode)
IsIdentifierToken(int)
IsKeywordToken(int)
IsModifier(int)
IsParameterModifier(int)
IsPointerType(int)
IsValidToken(int)
IsXmlComment(int)
LexComment()
LexCommentEnd()
LexDefine()
LexDefineComment()
LexDefineCommentEnd()
LexDefineString()
LexDefineStringEnd()
LexHexNumber()
LexIdentifier()
LexInclude()
LexNumber()
LexOctNumber()
LexString()
LexString(char)
LexStringEnd()
LexStringEnd(int)
LexSuffixes()
LexSymbol()
LexWhitespace()
LexXmlComment()
LexXmlCommentTag()
MoveNext()
NextToken()

Parses text from current position to the next token and updates TokenPos, CurrentPos and TokenString properties.

ParseAdditiveExpression(ref ISyntaxNode)
ParseAndExpression(ref ISyntaxNode)
ParseArgument(bool, ref ISyntaxNode)
ParseArgumentExpression(ref ISyntaxNode)
ParseArgumentExpressionList(ref ISyntaxNode)
ParseArgumentList(bool, ref ISyntaxNode)
ParseArrayInitializerExpression(ref ISyntaxNode)
ParseAttributeDeclaration()
ParseAttributeListDeclaration(Point, out ISyntaxNode)
ParseAttributeListDeclaration(Point, int, int, out ISyntaxNode)
ParseBaseList()
ParseBaseList(out string)
ParseBlock()
ParseBlockStatement()
ParseBlockStatement(ISyntaxAttributes, SyntaxNodeOptions, out ISyntaxNode)
ParseBreakStatement()
ParseCastTargetExpression(ref ISyntaxNode)
ParseClassBody()
ParseComment(out ISyntaxNode)
ParseConditionalAndExpression(ref ISyntaxNode)
ParseConditionalExpression(ref ISyntaxNode)
ParseConditionalOrExpression(ref ISyntaxNode)
ParseConstantExpression(ref ISyntaxNode)
ParseContinueStatement()
ParseDeclaration(ISyntaxAttributes, ISyntaxNode, int)
ParseDeclaration(ISyntaxAttributes, int)
ParseDeclaration(ISyntaxNode)
ParseDeclarationBody(ISyntaxNode, int)
ParseDeclarationBodyEnd(ISyntaxNode)
ParseDefineDirective()
ParseDefinedDirective()
ParseDirective(ref bool)
ParseDirectives()
ParseDoStatement()
ParseDoWhileStatement()
ParseElementAccess(ref ISyntaxNode)
ParseElseStatement()
ParseEmbeddedStatement()
ParseEmbeddedStatement(bool)
ParseEnumBody()
ParseEnumMember()
ParseEqualityExpression(ref ISyntaxNode)
ParseExclusiveOrExpression(ref ISyntaxNode)
ParseExpression(ref ISyntaxNode)
ParseExpressionStatement()
ParseFieldDeclaration(ISyntaxAttributes, string, Point, string, int)
ParseFieldInitializerExpression(ref ISyntaxNode)
ParseForCondition()
ParseForInitializer()
ParseForIterator()
ParseForStatement()
ParseGotoStatement()
ParseIdentifier(out string)
ParseIfStatement()
ParseInclusiveOrExpression(ref ISyntaxNode)
ParseInvocationExpression(ref ISyntaxNode)
ParseKnownMemberDeclaration(ISyntaxAttributes)
ParseLocalConstantDeclarationStatement()
ParseMacroBody(ISyntaxNode, int)
ParseMacroField(out ISyntaxNode)
ParseMacroMethod(out ISyntaxNode)
ParseMemberAccess(ref ISyntaxNode)
ParseMemberAccess(ref ISyntaxNode, int)
ParseMethodBody()
ParseMethodDeclaration(ISyntaxAttributes, string, Point, string, bool, ref ISyntaxNode)
ParseMethodDeclaration(bool, ISyntaxNode)
ParseModifiers(ref ISyntaxAttributes)
ParseMultiplicativeExpression(ref ISyntaxNode)
ParseNamedOrExpressionParam()
ParseParameterDeclaration(bool)
ParseParameterListDeclaration(bool, ref ISyntaxNode)
ParseParameterListDeclaration(int, int, bool, ref ISyntaxNode)
ParseParenthesizedExpression(ref ISyntaxNode)
ParseParenthesizedStatementExpression(ref ISyntaxNode)
ParsePointerMemberAccess(ref ISyntaxNode)
ParsePointerType(ref string)
ParsePostDecrementExpression(ref ISyntaxNode)
ParsePostIncrementExpression(ref ISyntaxNode)
ParsePrefixedUnaryExpression(ref ISyntaxNode)
ParsePreprocessor()
ParsePrimaryExpression(ref ISyntaxNode)
ParseQualifiedIdentifier(out string)
ParseRankSpecifier(out string)
ParseRelationalExpression(ref ISyntaxNode)
ParseReturnStatement()
ParseShiftExpression(ref ISyntaxNode)
ParseSimpleExpression(ref ISyntaxNode)
ParseSizeOfExpression(ref ISyntaxNode)
ParseStatement()
ParseStatementExpression()
ParseStatementExpressionList()
ParseStatementList()
ParseStringExpression(out string)
ParseStructInitializer(ref ISyntaxNode)
ParseSwitchBlock()
ParseSwitchBlockStatement()
ParseSwitchLabel()
ParseSwitchLabels()
ParseSwitchSection()
ParseSwitchStatement()
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.

ParseType(out string)
ParseTypeIdentifier(out string, bool)
ParseTypeName(out string)
ParseUnaryExpression(ref ISyntaxNode)
ParseUndefineDirective()
ParseUnit()
ParseUnitBody()
ParseUnknownMemberDeclaration(ISyntaxAttributes)
ParseUnknownMemberDeclaration(ISyntaxAttributes, string, Point)
ParseVariableDeclaration(Point, NetNodeType)
ParseVariableDeclarators(ISyntaxNode, NetNodeType, out Point)
ParseVariableInitializer()
ParseWhileStatement()
ParseXmlComment(ISyntaxNode)
PositionChanged(int, int, int, int)

Changes positions of any syntax nodes and its elements located next to the specified position.

ProcessGuideLines(IList<IRange>, ISyntaxNode)
ProcessGuideLinesInternal(IList<IRange>)
ReparseBlock(ISyntaxNode, Point)
ReparseBlock(Point)

Reparses syntax block at specified position.

ReparseDeclaration(ISyntaxNode)
ReparseText()

Resets Parser to the start position.

Reset()

Resets SyntaxParser to the start position.

ResetAutoIndentChars()

Resets the AutoIndentChars to the default value.

ResetCodeCompletionChars()

Resets the CodeCompletionChars to the default value.

ResetCodeCompletionStopChars()

Resets the CodeCompletionStopChars to the default value.

ResetOptions()

Resets Options to the default value.

ResetSmartFormatChars()

Resets the SmartFormatChars to the default value.

RestoreState(bool)

Restores Parser state and position stored by SaveState method.

SaveState()

Saves current Parser state and position.

ShiftPoint(Point, Point)
ShouldOutlineCommentNode(ISyntaxNode)
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.

ShouldSerializeSmartFormatChars()

Indicates whether the SmartFormatChars property should be persisted.

SkipComment()
SkipTo(int)
SkipTo(int, int)
SkipTo(int[])
SkipToDeclarationStart(int)
SkipToEndIf(bool, bool)
SmartFormatLine(int, string, StringItemInfo[], ITextUndoList, out bool)

Formats line according to the parser rules.

SyntaxError()
SyntaxError(Point, Point, string, string)
SyntaxError(int)
SyntaxError(string)
TryParseAssignmentExpression(ref ISyntaxNode)
TryParseAttributeListDeclaration(Point)
TryParseAttributeListDeclaration(Point, out ISyntaxNode)
TryParseCastExpression(ref ISyntaxNode)
TryParseFieldInitializerStatement(ref ISyntaxNode, out bool)
TryParseLabeledStatement(out bool)
TryParsePostPrimaryExpression(ref ISyntaxNode)
TryParseRankSpecifiers(out string)
TryParseVariableDeclarationStatement(out bool)
XmlToNetNodeType(int)