Class CParser
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
Fields
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.
Methods
- CreateRepository()
Creates
ICodeCompletionRepository
to perform code completion functionality for this parser.
- FinishParsing()
Commits parsing process.
- GetAutoFormatNode(Point, bool, out Point)
Obtains block node at specified position.
- GetCompletionType(char)
Obtains type of code completion window from specifies
char
parameter.
- GetSingleLineComment()
Gets the string that represents start symbol of single line comment.
- GetStructureGuideLines(IList<IRange>)
Gets list of guide lines.
- InitBoolExtension()
Enables usage of bool, true and false as reserved words.
- IsDeclaration(ISyntaxNode)
Indicates whether specified node is a declaration node (contains declaration of some syntax structure, such as class, namespace and so on).
- NextToken()
Parses text from current position to the next token and updates
TokenPos
,CurrentPos
andTokenString
properties.
- 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.
- ReparseBlock(Point)
Reparses syntax block at specified position.
- 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 bySaveState
method.
- SaveState()
Saves current
Parser
state and position.
- 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.
- SmartFormatLine(int, string, StringItemInfo[], ITextUndoList, out bool)
Formats line according to the parser rules.