Hello, Marco,
As it was previously noted, such a parsing implementation wouldn't be easy and it needs planning for implementing and covering the possible cases. However, we have prepared a sample example how to accomplish coloring of the string values in quotes:
public RadForm1()
{
InitializeComponent();
CustomCSharpTagger currentLanguageTagger = new CustomCSharpTagger(this.radSyntaxEditor1.SyntaxEditorElement);
this.radSyntaxEditor1.TaggersRegistry.RegisterTagger(currentLanguageTagger);
this.radSyntaxEditor1.TextFormatDefinitions.AddLast(ClassificationTypes.StringLiteral,
new Telerik.WinForms.Controls.SyntaxEditor.UI.TextFormatDefinition(new SolidBrush(Color.Fuchsia)));
}
public class CustomCSharpTagger : CSharpTagger
{
public CustomCSharpTagger(RadSyntaxEditorElement editor)
: base(editor)
{
}
private static readonly string[] STRINGS = new string[]
{
"\"",
};
private static readonly Dictionary<string, ClassificationType> WordsToClassificationType;
static CustomCSharpTagger()
{
WordsToClassificationType = new Dictionary<string, ClassificationType>();
foreach (var str in STRINGS)
{
WordsToClassificationType.Add(str, ClassificationTypes.StringLiteral);
}
}
protected override IList<string> SplitIntoWords(string value)
{
List<string> words = new List<string>();
string word;
int lastCharType = -1;
int startIndex = 0;
for (int i = 0; i < value.Length; i++)
{
int charType = GetCharType(value[i]);
if (lastCharType == 2)
{
int start = Math.Max(0, i - 1);
StringBuilder res = new StringBuilder();
res.Append(value[start]);
start = i;
while (start < value.Length)
{
res.Append(value[start]);
if (value[start] == '\"')
{
i = start + 1;
break;
}
start++;
}
words.Add(res.ToString());
startIndex = i;
lastCharType = charType;
continue;
}
if (charType != lastCharType)
{
word = value.Substring(startIndex, i - startIndex);
words.Add(word);
startIndex = i;
lastCharType = charType;
}
}
word = value.Substring(startIndex, value.Length - startIndex);
words.Add(word);
return words;
}
internal static int GetCharType(char c)
{
if (c == '#')
{
return 0;
}
if (char.IsWhiteSpace(c))
{
return 1;
}
if (c == '\"')
{
return 2;
}
if ((char.IsPunctuation(c) || char.IsSymbol(c)))
{
return 3;
}
return 0;
}
protected override bool TryGetClassificationType(string word, out ClassificationType classificationType)
{
if (word.StartsWith("\""))
{
classificationType = ClassificationTypes.StringLiteral;
return true;
}
return base.TryGetClassificationType(word, out classificationType);
}
}
The achieved result is illustrated in the below screenshot. Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way which suits your requirements best:
Should you have further questions please let me know.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
I have logged it in our feedback portal by making this thread public. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.
I have also updated your Telerik points.
Off topic, I have noticed that you have submitted several tickets about RadSyntaxEditor. Since it has been recently released, it would be greatly appreciated if you can share with us your feedback and first impressions when using RadSyntaxEditor. Our customers' opinion is always extremely valuable.Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik