This is a migrated thread and some comments may be shown as answers.

SQL operator wrapped with special characters

1 Answer 85 Views
SyntaxEditor
This is a migrated thread and some comments may be shown as answers.
Jong
Top achievements
Rank 1
Veteran
Jong asked on 09 Feb 2021, 10:06 PM

Hello I have a problem with operators wrapped with special characters.

For example when registering the parentheses as operators it works if the previous and next characters are not special characters like the example below.

select SUM(firstColumn) from myTable;

But if the previous or next character of parentheses is a special character, it does not recognize the parentheses as operators.

select SUM(*) from myTable;

How can I make it so that the registered operators are highlighted even if it is wrapped with special characters?

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Feb 2021, 09:23 AM

Hello, Jong,  

According to the provided information, I suppose that you are using a SQLTagger in RadSyntaxEditor. By default, it doesn't highlight in a different color the parentheses: 

I believe that you have some custom implementation to get the parentheses colored. Probably you classify them with special tag. Could you please specify how exactly you make the parentheses colored?

When RadSyntaxEditor splits the document into words, it checks the character types, e.g. whether it is a number, character, punctuation, etc. All of the mentioned characters, "(", "*", ")" are classified as punctionation and "(*)" is considered as a whole word. However, for the case with "(firstColumn)", it is split in 3 different words: "(", "firstColumn", ")" because of the different type of the symbols (not all symbols are punctuation). In this case, you can create a custom SQLTagger and override its SplitIntoWords method. Thus, you can have full control on how the document is split into words, e.g. classify the "*" symbol not as punctuation: 

        public class CustomSqlTagger : SqlTagger
        {
            public CustomSqlTagger(RadSyntaxEditorElement editor) : base(editor)
            {
            }
            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 (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 (c == '#')
                {
                    return 0;
                }

                if (char.IsWhiteSpace(c))
                {
                    return 1;
                }

                if (char.IsPunctuation(c) || char.IsSymbol(c))
                {
                    return 2;
                }

                return 0;
            }
        }

Using this approach, I believe that the coloring would be improved on your end. Is that true? In case you are still experiencing any further difficulties, it would be greatly appreciated you can provide a sample project demonstrating the problem you are facing. Thus, we would get better understanding of the precise case and think about a suitable solution.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
SyntaxEditor
Asked by
Jong
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or