how to get all keywords from language

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by László Mohácsi
Avatar
Hello!
I've tried the following : (in the OnTrigger handler)

SyntaxEditor editor = sender as SyntaxEditor;
SyntaxLanguage lan = editor.Document.Language;
LexicalPatternGroupCollection col = lan.LexicalStates["DefaultState"].LexicalPatternGroups;
string PatternText = null;
foreach (LexicalPatternGroup lp in col)
{
if ("ReservedWordToken" == lp.TokenKey)
{
foreach (LexicalPattern p in lp)
{
Console.WriteLine(p.Pattern);
PatternText = p.Pattern;
break;
}

}
}
string[] PatternList = PatternText.Split(" ", StringSplitOptions.None);
foreach (string s in PatternList){
Console.WriteLine("keyword=" + s);
}

But this only retrived the first word from the list. What am I missing here?

Second question would be how to add a keyword dynamically to this list ?
And if that's possible should Reparse be called ?

[Modified at 01/10/2006 01:46 PM]

Comments (4)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You're just updating PatternText and replacing its value. That's the problem in your code.

To dynamically add a keyword, set the language's IsUpdating property to true, then add the LexicalPattern for the keyword to the appropriate LexicalPatternGroup, then set IsUpdating back to false. Setting IsUpdating to false automatically reparses the document.


Actipro Software Support

Posted 14 years ago by László Mohácsi
Avatar
Ok, I understand the isUpdating property.
The other part of the question was why do I only retrive one keyword (the first one) ?
The code is

foreach (LexicalPatternGroup lp in col) {
                if ("ReservedWordToken" == lp.TokenKey) {
                    foreach (LexicalPattern p in lp) {
                        Console.Write(p.Pattern);
                        break;
                    }
                }
            }
This simply outputs keyword "break", while there are like 1000 keywords (which are
properly highlighted in the editor).
I would like to put all the keywords into IntelliMemberlist. Is there some other way
to do that?

[Modified at 01/11/2006 02:35 PM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You have to look at your program logic, which is incorrect here. You have a break statement that exits the loop after the first iteration. I think you meant to put it outside of the foreach. Other than that, I think it will work.


Actipro Software Support

Posted 14 years ago by László Mohácsi
Avatar
Ahh, ok see. So it is a collection of patterns, already sliced up. Sorry for the confusing question.
The latest build of this product (v2020.1 build 0400) was released 9 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.