Class Parser
Represents class that performs lexical analysis of specified text.
[Serializable]
[ToolboxBitmap(typeof(Parser), "Images.Parser.Icon.bmp")]
public class Parser : Lexer, IComponent, IDisposable, IParser, ILexer, INotify, IUpdate
- Inheritance
-
Parser
- Implements
- Derived
Examples
Here is how to declare a Parser from the C# code:
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
var parser = new Alternet.Syntax.Parser();
parser.Scheme.LoadFile("Lua.xml");
}
}
Here is how to declare a Parser from the Visual Basic code:
Partial Public Class Form1
Inherits Form
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim parser = New Alternet.Syntax.Parser()
parser.Scheme.LoadFile("Lua.xml")
End Sub
End Class
Remarks
Parser is a base class of non-visual components that perform a lexical, syntax, and semantic analysis of the text. The Parser itself provides only lexical analysis, driving 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.
Parser implements lexical analysis using finite-state automation rules driven by regular expressions matching the parsed text. The most important properties and methods of the Parser are:
The Scheme property defines lexical rules and styles.
The Strings property contains a list of strings being parsed.
The Token property represents a current lexical token related to the current position in the parsed text.
The TokenString property represents the text of the current syntax token.
The TokenPosition represents the start position of the current token.
The Reset() resets the Parser's position to the beginning of the document.
The NextToken() parses the next token and moves the Parser's position to the next lexical token.
Constructors
- Parser()
Initializes a new instance of the
Parser
class with default settings.
- Parser(IContainer)
Initializes a new instance of the
Parser
class with default settings.
Fields
Properties
- CurrentPosition
Represents position of current character within the current line.
- Eof
Indicates whether current position is out of the text, signaling that whole text is parsed.
- Lines
Gets or sets a list of string to parse represented as string array.
- State
Represents current
Parser
state.
- Strings
Gets or sets a list of strings to parse.
- Token
Represents token (number of style in the class style collection) related to the current position in the parsed text.
- TokenPosition
Represents start position of the current token.
- TokenString
Represents text of the current syntax token.
Methods
- NextToken()
Parses text from current position to the next token and updates
TokenPos
,CurrentPos
andTokenString
properties.
- NextToken(out string)
Parses text from current position to the next token and updates
TokenPos
,CurrentPos
andTokenString
properties.
- NextValidToken()
Parses text from current position to the next valid (non-whitespace, non-comment) token and updates
TokenPos
,CurrentPos
andTokenString
properties.
- NextValidToken(out string)
Parses text from current position to the next valid (non-whitespace, non-comment) token and updates
TokenPos
,CurrentPos
andTokenString
properties.
- PeekToken()
Parses next portion of the text, remaining current position unchanged.
- PeekToken(out string)
Parses next portion of the text, remaining current position unchanged.
- PeekValidToken()
Parses to the next valid (non-whitespace, non-comment) portion of the text, remaining current position unchanged.
- PeekValidToken(out string)
Parses to the next valid (non-whitespace, non-comment) portion of the text, remaining current position unchanged.
- Reset()
Resets
Parser
to the start position.
- Reset(int, int, int)
Resets
Parser
to the specified position.
- RestoreState()
Restores
Parser
state and position stored bySaveState
method.
- RestoreState(bool)
Restores
Parser
state and position stored bySaveState
method.
- SaveState()
Saves current
Parser
state and position.