Read and Write LexicalState

SyntaxEditor for Windows Forms Forum

Posted 10 years ago by Ryan
Avatar
Does anyone have or can you provide a detailed example of how to read an ExplicitPatternGroup and add to the group.
For an example can you show how to read from the VBscript language and read or add to the group TokenKey="ReservedWordToken" ?

This is as far as I can get
Dim States As LexicalStateCollection
Dim ChildLexicalStates As LexicalStateCollection
Dim PatternGroup As LexicalPatternGroup

States = editor.Document.Language.LexicalStates

Comments (3)

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

Check out the DynamicallyCreateForm source code in the sample project. That shows some modification of the dynamic languages. You must make sure you set your language's IsUpdating = true before you change anything and set it to false afterwards.

Everything in the dynamic languages is an object model structure. So you can enumerate through your language's LexicalStates collection to look for one with the Key for your default style. Then once found, enumerate that lexical state's LexicalPatternGroups collection and look at each LexicalPatternGroup.TokenKey to find the one you want.


Actipro Software Support

Posted 10 years ago by Ryan
Avatar
I can get through the states but can not get to the patterns. Below is what I have been testing with. I would like to be able to add test3 to the group and remove test2.

Dim i As Integer
Dim States As LexicalStateCollection
Dim ChildLexicalStates As LexicalStateCollection
Dim LexicalScopes As LexicalScopeCollection

States = editor.Document.Language.LexicalStates
LexicalScopes = States.Item(1).LexicalScopes
ChildLexicalStates = States.Item(1).ChildLexicalStates
Console.WriteLine(States.Item(1).DefaultTokenKey)
Console.WriteLine(States.Item(1).Key)
Console.WriteLine(LexicalScopes.Item(0))

For i = 0 To States.Count - 1
Console.WriteLine(States.Item(i).DefaultTokenKey)
Console.WriteLine(States.Item(i).Key)
Next i

XML Pattern
<ExplicitPatternGroup TokenKey="Mycode Token" Style="Mycodes" LookBehind="^|[^\.]" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">
<ExplicitPatterns>
Test1 Test2
</ExplicitPatterns>
</ExplicitPatternGroup>
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Please make sure you read through what I had previously replied to you. Each DynamicLexicalState has a LexicalPatternGroups collection on it. You can enumerate that collection and look for the LexicalPatternGroup item with the TokenKey="Mycode Token". LexicalPatternGroup itself is a collection. So you can enumerate through it to look for the LexicalPattern with Pattern="test2" and remove that one. Then add a new LexicalPattern with Pattern="test3".


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.