R: a better lexer to CudaText

All questions regarding lexer highlighting schemes are discussed here...
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

comments in R are shown with 2 styles inTinn-R. do you want the same? which comments are special? I may apply theme style 'comments doc'.
In fact, the "comments" on Tinn-R are on 4 levels:
  • # single comment
  • #. note level 1 (is a comment subtype)
  • #.. note level 2 (is a comment subtype)
  • #... note level 3 (is a comment subtype)
If you can do this in R's Lexer I think it will be great!
It was a user who asked me to create a note-type identifier (derived from the comment) in the R highlighter in Tinn-R.

I initially made

Code: Select all

#.
, then I liked it so much that I made the other two

Code: Select all

#..
and

Code: Select all

#...
I use it a lot in my R scripts to give a sense of hierarchy and facilitate presentation in classes.

I use the same ones in the Tinn-R text file highlighter (*.txt).

Best,
Attachments
Look carefully
Look carefully
main Alexey
Posts: 2265
Joined: 25.08.2021 18:15

Re: R: a better lexer to CudaText

Post by main Alexey »

As you see in the "Options / Themes / Settings-theme-syntax" dlg, we have 3 theme colors for comments

Comment - ok
Comment2 - ok
CommentDoc - this is for documentation comments, not ok to use as one of 4 colors

but I may use

Comment
Comment2
String2
String3

styles.
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

As long as the way they are presented can be configured by the user - by customizing the R lexer styles - I don't see any problems.

I believe that these new styles (notes) should be identified - for the user - by:
Note1
Note2
Note3

Do you agree?
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

Or perhaps create in "Options / Themes / Settings-theme-syntax" dlg the styles for notes (Note1, Note2, Note3, etc). Maybe it can be used in other Lexers... you are the one who knows the degree of difficulty involved in each option.
main Alexey
Posts: 2265
Joined: 25.08.2021 18:15

Re: R: a better lexer to CudaText

Post by main Alexey »

>create in "Options / Themes / Settings-theme-syntax" dlg the styles for notes (Note1, Note2, Note3, etc).
No, it is not good: all themes then must be updated to include these styles. even themes in addons. so better use existing styles:
e.g.
Comment2
String2
String3

--
One thing, can you give the link to docs, which describe these special comments?
or is it your invention?
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

Originally it wasn't my invention, it was a suggestion from a Tinn-R user. I liked the idea, increased the levels (to three) and extended it to other highlighters, for example to *.txt.

I find it very useful for highlighters that accept comments with a single character, like R. In the case of *.txt, I only know it in Tinn-R as I had never seen comments for pure *.txt. :)

But I can't say it was my invention!
I've been using it for so many years...
main Alexey
Posts: 2265
Joined: 25.08.2021 18:15

Re: R: a better lexer to CudaText

Post by main Alexey »

So it is not official...
in this case, pls do the copy of my lexer to e.g. R_.lcf (you must rename 'R' to 'R_' inside LCF file).
in the copy, make new parsers. in SynWrite editor. like tutorials tell
https://github.com/Alexey-T/CudaText/tr ... /tutorials

- RegEx for level 3: \#\.\.\..*
- RegEx for level 2, must be AFTER level 3: \#\.\..*
- RegEx for level 1, must be AFTER level 3+2: \#\..*
- RegEx for usual comment must be after levels 3/2/1 !

and make 3 new lexer styles. note1, note2, note3.
assign them to 3 new 'lexer parsers'.
note:
when you open R file in CudaText, it will ask for STYLE_MAPPING! assign new 3 styles to Comment2/String2/String3.

--
if you cannot do it, i will do it for you. but you must read tutors so next time you will do it yourself.
https://github.com/Alexey-T/CudaText/tr ... /tutorials
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

Okay, thanks for your attention!

I'll try and let you know if I succeed.

Best,
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

Alexey,

I managed to get it!
See attached figures.

The only problem I noticed is that I couldn't underline on the Note1. I had to choose edge in the Options/Lexers/Lexer properties option. That's it?
Attachments
R.clf_TokenRules.png
R.clf_Formats.png
Tinn-R sample in CudaText.png
jcfaria.uesc
Posts: 27
Joined: 07.05.2024 18:58

Re: R: a better lexer to CudaText

Post by jcfaria.uesc »

More pictures...
Attachments
R.cuda-lex.map.png
R Lexer properties.png
Post Reply