CSV Syntax Style

I am trying to create a custom config file for a custom language. It's more of a scripting language that is all comma separated.

There are different methods with a different number of arguments and data types.

scriptID, methodName, arg1, arg2, arg3, arg3, arg4, arg5... etc

I am creating my own custom config file, and I have made rules for my method names, enums, and numbers

Strings are not closed with quotes.

My question: How do I set argument type rules for specific keywords? 

Say I have this: scriptID,methodName,title, text,duration
script1,helloWorld,Message!,Hello world!,4000

It should be colored as followed
script1,helloWorld,Message!,Hello world!,4000



Current Config File: Config File


8 Replies

MA Matt April 30, 2018 07:52 PM UTC

I currently have everything working, but I'm using EditControl.SetTextColor to color the strings and commas


SM Subashini Mahendran Syncfusion Team May 1, 2018 10:40 AM UTC

Hi Matt,                                               
                                                                                                                                                                                                                                                                                                                                                                                Thank you for contacting Syncfusion support.

We have checked your query “How do I set argument type rules for specific keywords ”. In EditControl, SetTextColor method is used to set the color of text which was present within the specified point that was passed as an argument. If you are want represent the particular text as strings then you should mention the specific text as custom type in configuration file and then apply color for it. We have prepared a sample based on your requirement in which we have set the color for custom strings and commas in the custom configuration file. Please find the sample from the below location.

Sample: EdittControl_CustomConfiguration
                                                                                                                                                                                                                                                                                                                                                                                  If we misunderstood your requirement, please provide more information regarding your requirement. This would help us to proceed further.
                                                                                                                                                                                                                                                                                                                                                                                        Regards,
Subashini M.



MA Matt May 1, 2018 05:02 PM UTC

So I have these: 
scriptID, method1, int, string
scriptID, method2, float, string, int, enum
scriptID, method3, string, string


I would like to use a custom language config to style my custom language.

method1 has 2 arguments, and it will always be (int, string)
method2 has 4 arguments, and it will always be (float, string, int, enum)
method3 has 2 arguments and it will always be (string,string)

I need to style this syntax so that it will style the different variables.

method1 will always have an int after the 2nd comma.


I currently have it working using similar code provided in your example. But I want to figure out if it's possible to do it using a custom config file



MK Mallika Kannan Syncfusion Team May 2, 2018 05:10 PM UTC

Hi Matt 
 
Thanks for your update. 
 
Yes, this reported requirement for “Highlighting the custom language code that is all comma separated” can be achieved using Custom Language configuration file in EditControl. You can define the syntax coloring based on your requirement by configuring the custom language in the EditControl with the help of Format and Lexems. Formats will be applied to the text which match with syntax defined in the lexem. Each lexem contains the attributes such as BeginBlock, EndBlock, Type… etc.  We have also prepared the sample which tries to meet your requirement. Please make use of the below code example. 
 
Code Example: [XML] 
 
<formats> 
<format name="Text" Font="Courier New, 13pt" FontColor="Black" /> 
<format name="KeyWord" Font="Courier New, 10pt" FontColor="SkyBlue" /> 
<!--Highlight the Arguments--> 
<format name="Argument1" Font="Courier New, 10pt" FontColor="Blue" /> 
<format name="Argument2" Font="Courier New, 10pt" FontColor="Red" /> 
<format name="Argument3" Font="Courier New, 10pt" FontColor="Yellow" /> 
<format name="Argument4" Font="Courier New, 10pt" FontColor="Violet" /> 
<format name="String" Font="Courier New, 13pt, style=Bold" FontColor="#a81515" /> 
<format name="Number" Font="Courier New, 13pt, style=Bold" FontColor="#b5cea8" /> 
<format name="Comment" Font="Courier New, 13pt, style=Bold" FontColor="#57a64a" /> 
<format name="Operator" Font="Courier New, 10pt" FontColor="Brown" /> 
</formats> 
<!-- Lexem--> 
<lexems> 
<lexem BeginBlock="enum" Type="Argument1" /> 
<lexem BeginBlock="int" Type="Argument2" /> 
<lexem BeginBlock="float" Type="Argument3" /> 
<lexem BeginBlock="string" Type="Argument4" /> 
<lexem BeginBlock="helloWorld" IsBeginRegex="false" Type="KeyWord"/> 
<lexem BeginBlock="Message" ContinueBlock="!"  Type="String"/> 
<lexem BeginBlock="," Type="Operator" /> 
<lexem BeginBlock="enum1" Type="Enum"/> 
<lexem BeginBlock="enum2" Type="Enum"/> 
<lexem BeginBlock="//" EndBlock="\n" IsEndRegex="true" Type="Comment" IsComplex="true" OnlyLocalSublexems="true" /> 
<!-- For Method --> 
<lexem BeginBlock="method1"  Type="Text"/> 
<lexem BeginBlock="method2"  Type="Text"/> 
<lexem BeginBlock="method3"  Type="Text"/> 
<lexem BeginBlock="//" EndBlock="\n" IsEndRegex="true" Type="Comment" IsComplex="true" OnlyLocalSublexems="true" /> 
<lexem BeginBlock="[0-9]+" IsBeginRegex="true" Type="Number" /> 
<lexem BeginBlock="(?i:Hello)"  IsBeginRegex="true" Type="String" MatchCase ="false" /> 
<lexem BeginBlock="(?i:world!)"  IsBeginRegex="true" Type="String" MatchCase ="false" /> 
</lexems> 
 
<!-- Split--> 
 
<splits> 
<split>//</split> 
<split IsRegex="true">(?i:world!)</split> 
<split>Message!</split> 
</splits> 
 
 
Screenshot 
 
  
 
 
We have documented about creating custom language in EditControl and you can find the elaborate explanation about configuring custom language to the EditControl from below link,  
 
 
Kindly check the above solution and let us know whether our understanding on your query is same? If not please share more details, this would help us to provide solution at earliest. 
 
Regards, 
Mallika       



MA Matt May 2, 2018 07:16 PM UTC

This works, but limits my string to only (Hello world!). I need to be able to insert any string in that argument, strings can not contain commas.

I want to use RegEx to find the nth occurrence of a comma after the helloWorld Keyword.

I tried this, but can't get it to work



DR Durga Rajan Syncfusion Team May 3, 2018 12:07 PM UTC

Hi Matt, 

Query 1 : I need to be able to insert any string in that argument, 

We have changed the color of the whole text to Brown if it is end with “!” character. Please refer the below code example, 

<lexem BeginBlock="[A-z\s]+\!" IsBeginRegex="true"  Type="String"/> 

Also we have to mention the same Regex expression in the Split tag.  

Query 2: I want to use RegEx to find the nth occurrence of a comma after the helloWorld Keyword. 

We have changed the color of the text based on the occurrence of the comma after the specified keyword. We have used following code to get the text till 2nd occurrence of comma after HelloWorld text, 

<lexem BeginBlock="heloWorld(?:[^\,]*\,){2}" IsBeginRegex="true" IsComplex="true" OnlyLocalSublexems="true" Type="KeyWord"/> 

The following screenshot illustrate the output of above two expressions, 

 

We have modified the sample which tries to meet your requirement. Please download it from below location, 


Please get back to us with more details, if we have misunderstood your query. This would help us to provide solution at earliest. 

Regards, 
Durga S.  



MA Matt May 3, 2018 03:37 PM UTC


That's it thank you! Query 2 helped me out, I really appreciate it!


DR Durga Rajan Syncfusion Team May 4, 2018 04:31 AM UTC

Hi Matt, 

Thanks for the update. Please let us know if you need any further assistance.  

Regards, 
Durga S. 


Loader.
Up arrow icon