Table of Contents

Property TokenPosition

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

TokenPosition

Represents start position of the current token.

[Browsable(false)]
public virtual Point TokenPosition { get; }

Property Value

Point

Examples

Here is how to use a TokenPosition in the C# code:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using Alternet.Syntax;

public partial class Form1 : Form
{
    private const int tokComment = 11;
    private IList<string> comments = new List<string>();
    private IList<string> multilineComments = new List<string>();
    private Parser parser = new Parser();

    private void ParseComment()
    {
        Point pos = parser.TokenPosition;
        StringBuilder sb = new StringBuilder();
        while (!parser.Eof && parser.Token == tokComment)
        {
            sb.AppendLine(parser.TokenString);
            parser.NextToken();
        }

        if (parser.CurrentPosition.Y > pos.Y)
            multilineComments.Add(sb.ToString());
        else
            comments.Add(sb.ToString());
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        parser.Strings = new StringList();
        comments.Clear();
        parser.Strings.LoadFile("text.txt");
        parser.Reset();

        while (!parser.Eof)
        {
            if (parser.Token == tokComment)
                ParseComment();
            parser.NextToken();
        }
    }
}

Here is how to use a TokenPosition in the Visual Basic code:

Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Text
Imports Alternet.Syntax

Partial Public Class Form1
    Inherits Form

    Private Const tokComment As Integer = 11
    Private comments As IList(Of String) = New List(Of String)()
    Private multilineComments As IList(Of String) = New List(Of String)()
    Private parser As Parser = New Parser()

    Private Sub ParseComment()
        Dim pos As Point = parser.TokenPosition
        Dim sb As StringBuilder = New StringBuilder()

        While Not parser.Eof AndAlso parser.Token = tokComment
            sb.AppendLine(parser.TokenString)
            parser.NextToken()
        End While

        If parser.CurrentPosition.Y > pos.Y Then
            multilineComments.Add(sb.ToString())
        Else
            comments.Add(sb.ToString())
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        parser.Strings = New StringList()
        comments.Clear()
        parser.Strings.LoadFile("text.txt")
        parser.Reset()

        While Not parser.Eof
            If parser.Token = tokComment Then ParseComment()
            parser.NextToken()
        End While
    End Sub
End Class

Remarks

Use the TokenPosition property to determine the start position of the current token in the text being parsed.