Retrieve Keywords in Language

SyntaxEditor for WPF Forum

Posted 10 years ago by cowcow
Avatar
In the Sql.langdef, I have the following ExplicitPatternGroup where TokenKey="Keyword"

<ExplicitPatternGroup TokenKey="Keyword" ClassificationTypeKey="SqlKeyword" LookAheadPattern="{NonWord}|\z">
<ExplicitPatterns><![CDATA[
ADD ALTER AS ASC AUTHORIZATION BACKUP BEGIN BREAK BROWSE BULK BY CASCADE CHECK CHECKPOINT CLOSE SELECT
]]></ExplicitPatterns>
</ExplicitPatternGroup>



I have initialize the language to the SyntaxEditor.

Using stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Sql.langdef")
If stream IsNot Nothing Then
Dim serializer As New SyntaxLanguageDefinitionSerializer()
serializer.InitializeFromStream(language, stream)
End If
End Using

Is it possible to get all the keywords from the object language?

e.g something like this


For each keyword in language.xxxx
......
next keyword

I would expect to get these keywords one by one, e.g: ADD ALTER AS
Is that possible?


Thanks,
Cow

[Modified at 05/16/2010 07:40 AM]

Comments (2)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

What you would need to do is get the DynamicLexer, find the default state, get the appropriate pattern group, and iterate through the pattern group. Here is some example code that might be helpful:

Dim lexer As ILexer = syntaxEditorInstance.Document.Language.GetService(Of ILexer)()
Dim dynamicLexer As DynamicLexer = TryCast(lexer, DynamicLexer)
If dynamicLexer IsNot Nothing Then
 Dim group As DynamicLexicalPatternGroup = dynamicLexer.DefaultLexicalState.LexicalPatternGroups("SqlKeyword")
 For Each pattern As DynamicLexicalPattern In group.Patterns
  ' do something with pattern
 Next pattern
End If
Please let us know if you have further questions.


Actipro Software Support

Posted 10 years ago by cowcow
Avatar
It works, thanks.
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.