Page 1 of 1
Help defining a custom syntax file
Posted: 14 Oct 2024 19:54
by ags
I have a custom syntax in a text file. I need to scan the file for certain strings with regular expressions.
I used Tools - Syntax Editor to create and save a new syntax file.
I defined a new Keyword group and a new keyword like this: \d\d.\d\d.\d\d\d\d (to find the date).
I go to Environment - Themes - Customize - Syntax highlighting - Highlighters, select my file, find my defined keyword group and give it a distinctive format.
To test it, I write some date, eg.: 14.10.2024, and select my custom syntax highlighter from the combo box.
Nothing happens, the date is not at all recognized. What is wrong?
Re: Help defining a custom syntax file
Posted: 14 Oct 2024 21:21
by pjj
You need to escape dots, i.e. write \d\d\.\d\d\.\d\d\d\d -- or \d{2}\.\d{2}\.\d{4} (which is more readable, methinks).
I did some tests and I can see there is a bug in the code, though: the background for a (new) keyword isn't used if the keyword is on the last line. It works, if I add a newline after the line with a keyword.
Edit: it's not a bug, I just needed to move caret to another line (and I didn't

)
Re: Help defining a custom syntax file
Posted: 15 Oct 2024 15:30
by ags
Thanks for the reply, pjj.
I took your suggestion and defined my keyword as: \d{2}\.\d{2}\.\d{4} and saved the file.
The date's format is still not changed.
I made it purple and bold so that the difference can be clearly noticed.

Re: Help defining a custom syntax file
Posted: 15 Oct 2024 15:46
by pjj
Can you post your .syx file here?
Re: Help defining a custom syntax file
Posted: 15 Oct 2024 18:57
by ags
- log_txt.zip
- The file is not a zip, it is a syx. But it wouldn't let me upload until I changed it to zip.
- (830 Bytes) Downloaded 371 times
Re: Help defining a custom syntax file
Posted: 15 Oct 2024 21:32
by pjj
I've changed keyword group name from Data to #Data (i.e. put hash sign # before it) and it works for me.
Re: Help defining a custom syntax file
Posted: 16 Oct 2024 12:52
by ags
Thanks pjj, starting a keyword group name with # works.
But why is this? Does the # tell RJ TextEd that what follows has to be interpreted as a regex instead of a literal string?
Re: Help defining a custom syntax file
Posted: 16 Oct 2024 13:49
by pjj
I think so, yes.
Glad it works for you

Re: Help defining a custom syntax file
Posted: 16 Oct 2024 15:05
by ags
Where is this documented? I could not find any info on this in the documentation.
If RJ TextEd has capabilities beyond what is documented, it is a great loss. The manual should be updated.
Especially with something so rare and useful like using regex to make a custom syntax highlighting file.
Not many text editors are capable of such a feat. I know only of CudaText and EmEditor.
Re: Help defining a custom syntax file
Posted: 16 Oct 2024 16:11
by pjj
Turns out it is mentioned in the help file: TextEd > Syntax files > Keywords.
Re: Help defining a custom syntax file
Posted: 16 Oct 2024 18:59
by ags
Whoops!
