Help defining a custom syntax file

Discuss syntax highlighting or submit new syntax files.
Post Reply
ags
Posts: 6
Joined: 13 Oct 2024 17:03

Help defining a custom syntax file

Post 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?
User avatar
pjj
Posts: 2215
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Help defining a custom syntax file

Post 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 :oops:)
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
ags
Posts: 6
Joined: 13 Oct 2024 17:03

Re: Help defining a custom syntax file

Post 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. :)
User avatar
pjj
Posts: 2215
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Help defining a custom syntax file

Post by pjj »

Can you post your .syx file here?
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
ags
Posts: 6
Joined: 13 Oct 2024 17:03

Re: Help defining a custom syntax file

Post 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 108 times
User avatar
pjj
Posts: 2215
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Help defining a custom syntax file

Post by pjj »

I've changed keyword group name from Data to #Data (i.e. put hash sign # before it) and it works for me.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
ags
Posts: 6
Joined: 13 Oct 2024 17:03

Re: Help defining a custom syntax file

Post 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?
User avatar
pjj
Posts: 2215
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Help defining a custom syntax file

Post by pjj »

I think so, yes.
Glad it works for you :)
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
ags
Posts: 6
Joined: 13 Oct 2024 17:03

Re: Help defining a custom syntax file

Post 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.
User avatar
pjj
Posts: 2215
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Help defining a custom syntax file

Post by pjj »

Turns out it is mentioned in the help file: TextEd > Syntax files > Keywords.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
ags
Posts: 6
Joined: 13 Oct 2024 17:03

Re: Help defining a custom syntax file

Post by ags »

Whoops! :shock:
Post Reply