Recent

Author Topic: Highlighter for SynEdit  (Read 651 times)

paulee32

  • New Member
  • *
  • Posts: 18
Highlighter for SynEdit
« on: March 25, 2022, 02:02:56 pm »
Hello,

for TSynEdit, I would like to implement a custom Highlighter, but I fail.
I have compile the helper tool SynGen, that output, I have modified a little bit:
I would like highlight comments, and block of:
@mainpage    and
@end

The strings in TSynEdit dont be colored. when the @ sign is moved, then they will be colored.
So, How can I use @mainpage ?

here is the grammar.msg file:
Code: Pascal  [Select][+][-]
  1. TSynHelpNdocSyn
  2. tk
  3. IdentStart '@','_', 'a'..'z', 'A'..'Z':: '_', '0'..'9', 'a'..'z', 'A'..'Z'::
  4.  
  5. TOKENTYPES
  6. Identifier
  7. Comment      Style=[fsItalic]|Foreground=clGreen
  8. Key          Style=[]|Foreground=clBlue
  9.  
  10. |><|
  11.  
  12. KEYS
  13. '@mainpage'
  14. '@end'
  15.  
  16. |><|
  17.  
  18. CHARS
  19. 'A'..'Z', 'a'..'z', '_':: Ident
  20.  
  21. BeginProc
  22.   fTokenID := IdentKind((fLine + Run));
  23.   inc(Run, fStringLen);
  24. EndProc
  25. |><|
  26.  
  27. ENCLOSEDBY
  28. Comment,CStyleComment,/*,*/,MultiLine
  29. |><|
  30.  

Edson

  • Hero Member
  • *****
  • Posts: 1247
Re: Highlighter for SynEdit
« Reply #1 on: March 25, 2022, 03:47:03 pm »
Hi.

I haven't hear about "SynGen". Maybe it's only for Delphi Synedit.   :-\

Lazarus SynEdit is incompatible with Delphi SynEdit since a long time ago.

I recommend to use SynFacilSyn for Lazarus SynEdit: https://github.com/t-edson/SynFacilSyn . It has a detailed documentation.

Moreover if you want to add completion code, you can use SynFacilCompletion: https://github.com/t-edson/SynFacilCompletion. It's 100% compatible with SynFacilSyn.

Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

paulee32

  • New Member
  • *
  • Posts: 18
Re: Highlighter for SynEdit
« Reply #2 on: March 25, 2022, 04:58:16 pm »
Hello,

I search the Internet via Google, and found a hint, to use SynGeneralHighlighter.
This component is indeed under the Palette of SynEdit's Highlighters.

I can put keywords into a StringList, and I have the possibility, to set the FG/BG color of the keywords.
But the Problem is, that the Sign "@" will not be recognize.

So, the keyword "@mainpage"  will not be parsed or colored.
Only "mainpage" as keyword is accepted.

Has someone an Idea, how to use the @ with keyword(s) ?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8253
  • Debugger - SynEdit - and more
    • wiki
Re: Highlighter for SynEdit
« Reply #3 on: March 25, 2022, 06:46:09 pm »

paulee32

  • New Member
  • *
  • Posts: 18
Re: Highlighter for SynEdit
« Reply #4 on: March 25, 2022, 07:30:23 pm »
Thank You @all,

I get it done.
The simplest thing was to rename the classname of TSynGeneral to my highlighter,
and do little bit modifications.

Here a picture:
https://imgur.com/Yrtv5Ks

Edson

  • Hero Member
  • *****
  • Posts: 1247
Re: Highlighter for SynEdit
« Reply #5 on: March 25, 2022, 08:46:20 pm »
You can easily do some similar in SynFacilCompletion.

In the picture you can see a sample XML to set syntax, coloring, folding and completion


Lazarus 2.0.10 - FPC 3.2.0 - x86_64-win64 on Windows 8

 

TinyPortal © 2005-2018