Dear Support Team,
In my company we are using the XamSyntaxEditor to represent our own custom language which contains the following keywords:
"Base"
"Using"
and so on.
Now, what we are trying to do in addition is to highlight the keywords with a color (for example blue color). Therefore I need your assistant to figure out how to do this with XamSyntaxEditor.
Note: Preferably, we do not want to change the control.
Hello Tomas,
If you have configured your custom language file to associate the words “Base” and “Using” as keywords, you can modify their appearance by using a ClassificationAppearanceMap entry. There is a documentation article for this on our website, here.
If you have installed the Infragistics for WPF Samples Browser, there is also a sample there that may help you. In the samples tree, navigate to XamSyntaxEditor => Display => Highlighting Customization.
Please let me know if you have any other questions or concerns on this matter.
Hello Andrew,
Thanks for the reply. Then question would be how to configured custom language file with the words “Base” and “Using” and etc?
Based on example this is just a mapping to be shown in editor and it does not contain list of available keywords.
I've tried to convert the Grammar EBNF file to infragistics EBNF but unfortunately it fails with various problems. I've attached the source file with an example and the EBNF file which I've tried to converted using Infragistics syntax engine parser.
EBNF files.zip
Dear Andrew,
Thanks for a hint. We've managed to create a simple custom language without creating EBNF file. As start point is enough but I face a small problem in the editor:
Whenever typed a keyword text is replaced to the right format. So for example we have a keyword "Using" but if I type in the Editor text "using" it gets replaced after losing focus or hitting enter.
Our compiler code is case sensitive and it is OK from one point. However we did not covered this text as part of text and this should not change any text.
So I see here two options:
Keyword added to the grammar by this code:
var grammar = PlainTextLanguage.Instance.Grammar.Clone(); new MyLanguageSyntax().SyntaxElements.Cast().ToList().ForEach(element => { grammar.LexerStates.DefaultLexerState.Symbols.Insert(0, element.Keyword, element.Keyword, TerminalSymbolComparison.LiteralIgnoreCase).LanguageElement = LanguageElement.ContextSensitiveKeyword; }); return new CustomLanguage(grammar);
I've downloaded the samples which contains the EBNF conversion and it looks slightly different than the Grammar file which I have. I will try to convert this into Infragistics Grammar EBNF file.
In order to add keywords such as “Base” and “Using”, you will have to configure your custom EBNF file to have these keywords. From what I understand of EBNF file creation, there is a way to add keywords to your Grammar object.
The ClassificationAppearanceMap documentation topic that I linked above has a code-example on it that shows how you can define an appearance for the keywords that exist in your EBNF file that is loaded to the XamSyntaxEditor. You cannot actually define the keywords through the ClassificationAppearanceMap, though – they are defined within the EBNF file.
If you are currently licensed to the Infragistics for WPF product and would like to see an example EBNF file that is compatible with the XamSyntaxEditor, I would then recommend downloading the source code from your My Keys and Downloads page on the Infragistics website and taking a look at the TextDocument.WPF => Parsing => EbnfFiles directory. There, you will find the ebnf files for a few different languages that we support out-of-the-box in the XamSyntaxEditor including C# and Visual Basic.