Adding tokens at runtime

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by John Youren
Avatar
Hi,

I am trying to dynamically add [multi-word] tokens at runtime, here is the code I have.

Documents[tabID].getCode().Document.LoadLanguageFromXml(Application.StartupPath + "\\Syntax\\" + Variables.Compiler + ".xml", 0);
                        // Set up TPC's
                        if (Variables.Compiler == Constant.CompilerDBP)
                        {
                            Documents[tabID].getCode().Document.Language.IsUpdating = true;
                            for(int pattern = 0; pattern < DBPSyntax.keywords.Count; pattern++)
                            {
                                Console.WriteLine(DBPSyntax.keywords[pattern].Replace(" ", "\\s+"));
                                Documents[tabID].getCode().Document.Language.DefaultLexicalState.LexicalPatternGroups.Add(new ActiproSoftware.SyntaxEditor.LexicalPatternGroup(ActiproSoftware.SyntaxEditor.LexicalPatternType.Regex, "ReservedWordToken", Documents[tabID].getCode().Document.Language.HighlightingStyles["ReservedWordStyle"], DBPSyntax.keywords[pattern].Replace(" ", "\\s+"), "{NonWordMacro}"));
                               
                            }
                            Documents[tabID].getCode().Document.Language.IsUpdating = false;
                        }
The problem is even a simple word such as 'hello' won't highlight, even though I have stepped through it getting added.

Any ideas? :)

Comments (1)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes the lexical pattern groups are scanned in order. You probably have an Identifier pattern matching
them before they get to your new patterns. Use the Insert method and put them up higher in the
LexicalPatternGroups collection.

As a side note, you can always load your language in our sample project. It shows the token in the
statusbar that the caret is over. That helps debug language problems like this.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) 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.