Adding a lexical pattern at run time

SyntaxEditor for Windows Forms Forum

Posted 15 years ago by Jeff Key
Avatar
I've tried the following, but it doesn't appear to be working. Ideas?

SyntaxLanguage syntaxLanguage = editor.Language;
LexicalState lexicalState = syntaxLanguage.DefaultLexicalState;
LexicalPatternGroupCollection patternGroups = lexicalState.LexicalPatternGroups;
LexicalPatternGroup reservedWordsPatternGroup = patternGroups["ReservedWords"];

syntaxLanguage.IsUpdating = true;

reservedWordsPatternGroup.Add(new LexicalPattern("jeff"));

syntaxLanguage.IsUpdating = false;
If I iterate through the reservedWordsPatternGroup after adding "jeff", it is indeed in there, but it's not highlighted in the editor.

Thanks!

[ 05-05-2004: Message edited by: Jeff Key ]

Comments (4)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I tried something similar here and it worked ok. Couple things to try:

1) Remember that the NFA engine will acceptthe first pattern that it finds that can match. So if you had something (even in your reserved words) like "je", it would do that since you are doing Add (putting it at the end of the pattern group). You can try doing Insert(0, "jeff") which will help within that pattern group if this situation does exist there. Or maybe you have an identifier pattern group defined before the reserved words one, in which case you'd need to reverse that order.

2) Try doing a Document.Reparse after you make that change.


Actipro Software Support

Posted 15 years ago by Jeff Key
Avatar
Here's a little more context:

I'm using the bundled TestAppliation and added that code to the end of LoadXmlLanguageDefinition. "jeff" should be unique, so I don't think anything could be matching it or part of it.

I added "editor.Document.Reparse()" after the code I pasted and am still seeing the same behavior. I can email the app to you if you'd like.

Thanks
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I think you're probably running into a situation where you are putting the keyword into a lexical pattern group however the group has a StartsWith attribute that doesn't include the letter "j". Therefore it will never scan that text. Remember that in the C# def we optimized reserved words by splitting them into multiple groups each with a different StartsWith. If you add it to the appropriate one then it works.


Actipro Software Support

Posted 15 years ago by Jeff Key
Avatar
That was indeed it!
The latest build of this product (v2018.1 build 0341) was released 8 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.