Recent

Author Topic: ATSynEdit - Basic HighLight  (Read 686 times)

mosquito

  • New member
  • *
  • Posts: 9
ATSynEdit - Basic HighLight
« on: October 05, 2019, 07:23:44 pm »
In the ATSynEdit documentation [https://wiki.freepascal.org/ATSynEdit] it says there are two ways to attack HighLighting. The simple (OnCalcHillite) and the advanced (EControl / lexers).

I am interested in the simple way. Any examples or documentation on this? I would like to know the internal functioning of this event.

My goal is to highlight some own reserved words. I don't know if this would be possible without lexers.

Note: I have no previous experience using SynEdit. My pascal is very recent.
Thank you.

Alextp

  • Hero Member
  • *****
  • Posts: 1119
    • UVviewsoft
Re: ATSynEdit - Basic HighLight
« Reply #1 on: October 05, 2019, 07:33:22 pm »
OnCalcHilite has this type -
 TATSynEditCalcHiliteEvent = procedure(Sender: TObject; var AParts: TATLineParts;
    ALineIndex, ACharIndex, ALineLen: integer; var AColorAfterEol: TColor) of object;

In the handler of this event, you must fill
- AParts (array of parts, one part per one LANGUAGE TOKEN, e.g. one symbol, one keyword, one string const, one comment. And fill all other parts with zero.),
- AColorAfterEol (color which is used after line end for empty area).

you get
- ALineIndex is index of line
- ACharIndex is index of char for part of wrapped line (if line is wrapped)
« Last Edit: October 05, 2019, 07:35:40 pm by Alextp »

Alextp

  • Hero Member
  • *****
  • Posts: 1119
    • UVviewsoft

mosquito

  • New member
  • *
  • Posts: 9
Re: ATSynEdit - Basic HighLight
« Reply #3 on: October 05, 2019, 08:42:08 pm »
Do not really understand...

TATLineparts is an array of TATLinePart (s).
TATLinePart is a RECORD.

The documentation says that a TATLinePart is:

one part per one "syntax token" (e.g. one symbol, one keyword, one string const, one comment, etc). Fill all other parts with zeros.

TATLinePart was built like this:

Code: Pascal  [Select][+][-]
  1. type
  2.    TATLinePart = packed record
  3.      Offset, Len: integer;
  4.      ColorFont, ColorBG, ColorBorder: TColor;
  5.      FontBold, FontItalic, FontStrikeOut: ByteBool;
  6.      BorderUp, BorderDown, BorderLeft, BorderRight: TATLineStyle;
  7.    end;
 
I only see aesthetic characteristics, how I link my constant ...

Code: Pascal  [Select][+][-]
  1. myhword: string = 'PROCEDURE';

to a TATLinePart ??
« Last Edit: October 05, 2019, 08:50:37 pm by mosquito »

Alextp

  • Hero Member
  • *****
  • Posts: 1119
    • UVviewsoft
Re: ATSynEdit - Basic HighLight
« Reply #4 on: October 05, 2019, 09:01:20 pm »
Wrote more text at https://wiki.freepascal.org/ATSynEdit#How_to_handle_OnCalcLineHilite_event

see the example of parsed parts.

mosquito

  • New member
  • *
  • Posts: 9
Re: ATSynEdit - Basic HighLight
« Reply #5 on: October 05, 2019, 09:24:45 pm »
Thx for your time. I have read your updates.

Now all the content of my editor is affected by the highlight. I don't understand how the matching/parsing of a "token syntax" works as you call it. How are these "token syntax" created and related to a TATLinePart?

In other words:

 ;) SynEdit connects to a HighLighter.
 ;) ATSynEdit connects to an Adapter.
 :o ATSynEdit (without Adapter) with what does it connect?

How do I create this "syntax tokens" dictionary?
« Last Edit: October 06, 2019, 08:40:41 am by mosquito »

Alextp

  • Hero Member
  • *****
  • Posts: 1119
    • UVviewsoft
Re: ATSynEdit - Basic HighLight
« Reply #6 on: October 07, 2019, 11:40:17 am »
Syntax token == just a small fragment of text. it is one comment, one quoted string, one Id, one number....

ATSynEdit uses EControl adapter, EControl finds "tokens" and saved them to list. Later adapter read this list of tokens, and makes "parts" in OnCalcLineHilite

EControl adapter finds tokens.
You can find tokens w/out adapter, using RegExpr rules.
« Last Edit: October 07, 2019, 11:41:52 am by Alextp »

 

TinyPortal © 2005-2018