Locate Keywords and Tolken Info (code snippit)

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by ernesto
Avatar
Here is a quick piece of info for any newbi,

This is a code snipit on how to find the location of the keyword that was just typed using the KeyPressTrigger event. Here we create a textstream for the GetTextStream method of the Document name space. Next we capture the last word typed start position in the edit control using SelctedView. Next we capture the stream (in this case only the text typed starting at the keywordstartpoint up to the current carret position, this should only capture the word typed. Next capture the keyword's tokenName, which will let us know if the word captured is actually a defined KeyWord Token from our syntax language xml file. Finally we display in a message box the two string values we found, if it is key word then the message will show the key word and its token name.

Private Sub SyntaxEditor_TriggerActivated(ByVal sender As Object, ByVal e As ActiproSoftware.SyntaxEditor.TriggerEventArgs) Handles SyntaxEditor.TriggerActivated

        Dim stream As TextStream
        Dim keywordStartPoint As Integer = SyntaxEditor.SelectedView.FindPreviousWordStart
        Dim tokenName As String
        stream = SyntaxEditor.Document.GetTextStream(keywordStartPoint)
        tokenName = stream.Token.Key
        
       Select Case tokenName
            Case "ReservedWordToken"
                MessageBox.Show("Key word =" & " " & "(" & stream.TokenText & ")" & "   " & "Token name =" & " " & "(" & tokenName & ")")

        End Select

    End Sub
thanks
Actipro

Updated to use Select Case statement for tokenName in case someone needs to find other KeyWordToken names that are defined in the Syntax Language xml file.

[Modified at 01/25/2007 05:27 PM]

[Modified at 01/25/2007 05:33 PM]

[Modified at 01/25/2007 09:34 PM]

Comments (1)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks Ernesto,

Also just FYI at TextStream is ideal for scanning through one or more tokens anywhere in the document.
It has a ton of methods for navigating through documents.

We also have several helper methods on EditorView to return a single token or word, like:
GetCurrentToken
GetCurrentWordText
GetCurrentWordTextRange
GetPreviousToken


Actipro Software Support

The latest build of this product (v24.1.0) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.