Table of Contents

Class PythonParser

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

Represents a class that performs syntax and lexical analysis of specified Python code text.

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

Examples

Here is how to declare a PythonParser 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.Python.PythonParser();
        var edit = new Alternet.Editor.SyntaxEdit();
        edit.Parent = this;
        edit.Lexer = parser;

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

Here is how to declare a PythonParser 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.Python.PythonParser()
        Dim edit = New Alternet.Editor.SyntaxEdit()
        edit.Parent = Me
        edit.Lexer = parser
        Dim fileName As String = "myfile.py"

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

Remarks

PythonParser is a non-visual component designed to perform syntax highlighting for the Python language. This parser supports full syntax and semantic analysis of the Python code. When linked to the SyntaxEdit or TextEditor controls, this parser drives additional features such as code completion, code outlining, code formatting, highlighting types in different colors, and underlying syntax and semantic errors and warnings.

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

  • Syntax Highlighting
  • IntelliSense (Code completion)
  • Signature Help (displaying parameter information for methods)
  • Code Outlining
  • Structure guidelines
  • Formatting a selected block of text or the whole document.
  • Finding declarations and references

Constructors

PythonParser()

Initializes a new instance of the PythonParser class with default settings.

Fields

lexCommentProc
lexIdentifierProc
lexNumberProc
lexStringEnd2Proc
lexStringEndProc
lexStringProc
lexSymbolProc
lexWhitespaceProc
prefixesByte
prefixesStr
prevPosition

Properties

CaseSensitive

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

Classifier
CodeEnvironment
Comments
Model

Methods

AddAttribute(ISyntaxAttribute)
AddNameDeclaration(ISyntaxNode, Point, string, ISyntaxNode)
AddNode(ISyntaxNode)
AddTypeDeclaration(ISyntaxNode, Point, string, ISyntaxNode)
AddXidContinue(char, char)
AddXidStart(char, char)
AfterDeclaration(ISyntaxNode)
AssignParser(ISyntaxParser)
BeforeDeclaration(ISyntaxNode)
CheckBlockStart(int)
CodeCompletion(string, StringItemInfo[], Point, CodeCompletionArgs)

Performs code completion for the specified text representing language element.

CreateClassifier()
CreateExpressionNode(Point, string, int, ISyntaxNode, bool)
CreateRepository()

Creates ICodeCompletionRepository to perform code completion functionality for this parser.

CreateSemanticModel()
Expected(PythonLexerToken)
Expected(PythonLexerToken[])
Expected(int)
FindChildNode(ISyntaxNode, int)
FindDeclaration(Point)

Finds the declaration node at given position.

FindDeclaration(string, Point)

Finds the declaration node at given position.

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.

FindReferences(Point, bool)
FinishParsing(ISyntaxParser)
FixupComments()
GetCompletionType(char)

Obtains type of code completion window from specifies char parameter.

GetInvocationNode(ISyntaxNode, Point, out int, out int)
GetLexerStyle(int)
GetSingleLineComment()

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

IdentifierExpected()
InForInitializer()
InitDefaultStyles()
InitLanguage()
InitLexer()
InitPrefixes()
InitStyles()
InitXid()
InitXidContinue()
InitXidStart()
InternalCreateRepository()
IsBaseList(int)
IsComment(int)
IsIdentChar(char)
IsIdentifierToken(int)
IsInvocationNode(ISyntaxNode)
IsKeywordToken(int)
IsLineContinuation(ISyntaxNode)
IsMultiLineStringExpression(ISyntaxNode)
IsSigneLineIfStatementNext(ISyntaxNode)
IsType(int)
IsValidArgument(ISyntaxNode, Point)
IsValidToken(int)
IsXidContinueChar(char)
IsXidFirstChar(char)
LexBinNumber()
LexComment()
LexHexNumber()
LexIdentifier()
LexNum()
LexNumber()
LexOctNumber()
LexString()
LexString(char)
LexStringEnd()
LexStringEnd(char, int)
LexStringEnd2()
LexSymbol()
LexWhitespace()
MakePrimaryExpressionListAsLocalVar(ISyntaxNode)
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(ref ISyntaxNode)
ParseArgumentList(ref ISyntaxNode)
ParseAssertStatement()
ParseBaseList()
ParseBaseSpecifier()
ParseBaseSpecifierList()
ParseBlock(ISyntaxNode)
ParseBlockStatement()
ParseBlockStatement(ISyntaxAttributes, SyntaxNodeOptions, out ISyntaxNode)
ParseBreakStatement()
ParseChildExpression(ISyntaxNode)
ParseChildSlice(ISyntaxNode, ref bool)
ParseClassBody()
ParseComment()
ParseConditionalAndExpression(ref ISyntaxNode)
ParseConditionalOrExpression(ref ISyntaxNode)
ParseContinueStatement()
ParseDeclaration(ISyntaxAttributes, ISyntaxNode, int)
ParseDeclaration(ISyntaxAttributes, int)
ParseDeclarationBody(ISyntaxNode, int)
ParseDecorator(ISyntaxAttributes)
ParseDelStatement()
ParseDictDisplayExpression(ref ISyntaxNode)
ParseElseIfStatement(bool)
ParseElseStatement(bool)
ParseEmbeddedStatement()
ParseEqualityExpression(ref ISyntaxNode)
ParseExceptStatement()
ParseExceptStatements()
ParseExclusiveOrExpression(ref ISyntaxNode)
ParseExecStatement()
ParseExpression(ref ISyntaxNode)
ParseExpressionList(ref ISyntaxNode, int)
ParseExpressionStatement()
ParseFinallyStatement()
ParseForInitializer()
ParseForStatement(bool)
ParseGlobalStatement()
ParseIdentifier(out string)
ParseIfStatement(bool)
ParseImportStatement()
ParseImportsStatement()
ParseImportsStatement(ISyntaxNode)
ParseInclusiveOrExpression(ref ISyntaxNode)
ParseInvocationExpression(ref ISyntaxNode)
ParseKeyDatum(ref ISyntaxNode)
ParseKnownMemberDeclaration(ISyntaxAttributes)
ParseLambdaExpression(ref ISyntaxNode)
ParseListDisplayExpression(ref ISyntaxNode)
ParseMemberAccess(ref ISyntaxNode)
ParseMethodBody()
ParseMethodDeclaration(ISyntaxAttributes)
ParseMethodDeclaration(ISyntaxNode, bool)
ParseMultiplicativeExpression(ref ISyntaxNode)
ParseParameterDeclaration(int)
ParseParameterListDeclaration()
ParseParameterListDeclaration(int, int)
ParseParenthesizedExpression(ref ISyntaxNode)
ParsePassStatement()
ParsePrefixedUnaryExpression(ref ISyntaxNode)
ParsePrimaryExpression(ref ISyntaxNode)
ParsePrintStatement()
ParseQualifiedIdentifier(out string, out ISyntaxNode)
ParseRaiseStatement()
ParseRelationalExpression(ref ISyntaxNode)
ParseReturnStatement()
ParseSemantic()
ParseShiftExpression(ref ISyntaxNode)
ParseSimpleExpression(ref ISyntaxNode)
ParseSliceExpression(ref ISyntaxNode, ref bool)
ParseSliceList(ref ISyntaxNode, ref bool)
ParseStatement()
ParseStatementExpression()
ParseStatementExpressionList()
ParseStatementList(ISyntaxNode)
ParseStringConversionExpression(ref ISyntaxNode)
ParseStringExpression(out string)
ParseSyntax()
ParseTargetList(out ISyntaxNode)
ParseTryStatement()
ParseTupleFieldDeclaration(Point, PythonNodeType, SyntaxNodeOptions)
ParseType(out string)
ParseType(out string, out ISyntaxNode)
ParseTypeName(out string)
ParseTypeName(out string, out ISyntaxNode)
ParseUnit()
ParseUnitBody()
ParseUnknownMemberDeclaration(ISyntaxAttributes)
ParseVariableDeclaration(ISyntaxAttributes, int)
ParseVariableDeclaration(ISyntaxAttributes, int, ref ISyntaxNode)
ParseVariableDeclarator()
ParseVariableInitializer(ref ISyntaxNode)
ParseWhileStatement()
ParseWithItem()
ParseWithStatement()
ParseYieldExpression(ISyntaxNode)
ParseYieldStatement()
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()

Reparses entire text.

Reset()

Resets PythonParser to the start position.

ResetCodeCompletionChars()

Resets CodeCompletionChars to the default value.

ResetOptions()

Resets Options to the default value.

RestoreState(bool)

Restores Parser state and position stored by SaveState method.

ShouldSerializeCodeCompletionChars()

Indicates whether the CodeCompletionChars property should be persisted.

ShouldSerializeOptions()

Indicates whether the Options property should be persisted.

SkipTo(int)
SkipTo(int, int)
SkipToDeclarationStart()
SyntaxError()
SyntaxError(int)
SyntaxError(string)
TryParseAssignmentStatement(ref ISyntaxNode)
TryParseForComprehension(ISyntaxNode)
TryParseImportsStatement(out bool)
TryParseKeyDatumList(ref ISyntaxNode, out bool)
TryParseLambdaParameterOrExpression(ref ISyntaxNode)
TryParsePostPrimaryExpression(ref ISyntaxNode)
TryParseSlicing(ref ISyntaxNode)
TryParseTupleExpression(ref ISyntaxNode, SyntaxNodeOptions)
TryParseVariableDeclaration(ref ISyntaxNode, int)