Custom Regex Language
It is relatively easy to hardcode a collection of strings (such as the keywords in Python) and only highlight these specific words. Some languages, however, require regular expressions to be used so that highlighting can be applied as expected.
In this article you will learn how to setup a custom tagger which handles the text by using regular expressions. We will use JSON for the purposes of this example, but a similar approach can be applied to text in other formats as well.
We will first define the types of words the tagger will recognize.
Example 1: Recognized JSON types
Let's us now define the actual tagger class which will be responsible for classifying the words of the opened document.
Example 2: The custom tagger
Generally speaking, the same approach can be used for any language by creating the proper regular expressions.
Finally, we can register the custom tagger in RadSyntaxEditor's TaggersRegistry just as we would with any other tagger. We also add custom TextFormatDefinitions with specific foregrounds for the Key, StringLiteral, Number and the TrueFalseNull classification types which we created in Example 1. In addition, we can create a BracketFoldingTagger to handle the folding regions.