Recent

Author Topic: [SOLVED] All Things SynFacilSyn  (Read 9217 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #15 on: August 26, 2019, 05:51:50 pm »
Tried to translate the Spanish DOC file online... the ones I tried didn't work.
I don't know what you did. I called translate.google.com, clicked "Documents", selected translation from Spanish to English and uploaded the "La Biblia de SynEdit.pdf". After a short time, the English version came up, not too bad - hmm, pretty good actually! The translated doc is a html which I downloaded to my disk. It is not good for printing, but good for screen reading. Using 7-zip I was able to squeeze it into the 250KB upload limit of the forum

Cool WP... thanks for that.
Hmmm. i just did copy paste... never even noticed the document button.

Yeah, the html text seems okay... missing images though and some of the text is covered up by a blue square.
But, i can go into the Html and remove those.

Thanks man!
At least I have a fighting chance to get this working on my own.
I rather learn on my own as long as I have descent documentation.

After all, programming is not magic... you just can't guess what methods and events someone uses to code their library.

 :D
« Last Edit: August 26, 2019, 05:53:37 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

Edson

  • Hero Member
  • *****
  • Posts: 1326
Re: All Things SynFacilSyn
« Reply #16 on: August 26, 2019, 09:47:43 pm »
Too many questions in a few time.

Hi,
Is there any ENGLISH documentaion for SynFacilSyn
All I get in the download is some other language, Spanish?
Yes. There is one: https://github.com/t-edson/SynFacilSyn/blob/1.21/Docs/Technical%20documentation%20-%20Rev1.odt
Original doc is in spanish, so this could be a bad translation.  More updated documentation is in spanish, but it's a minimal difference.

Don't confuse "SynFacilSyn" with "SynEdit". If you want documentation for SynEdit, there is not so much. In spanish you have "The Bible of SynEdit" and as posted @lucamar, it's in process of translating.

Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Thausand

  • Sr. Member
  • ****
  • Posts: 457
Re: All Things SynFacilSyn
« Reply #17 on: August 27, 2019, 05:12:12 am »
Really...
No, not really. It was reply for Jamie.

Quote
1) There is no english docs
Yes, is there: https://github.com/t-edson/SynFacilSyn/blob/1.21/Docs/Technical%20documentation%20-%20Rev1.odt

Quote
2) I am using the examples in the download... which doesn't address my particular issues
Oh, you have want some one hold hand ? Have look picture (*).

(*) i already know (in end) you no want this and have new complain :-)

Quote
3) I know how to do tokens/lex... made one in VB.NET that worked.
Please have read technical document. It explain how use SynFacilSyn (use code or use xml or combine as do you code)

Quote
4) I am already making my own XML...
Now only make use good commands that do as want  ;D

Quote
5) Did you download my project... I have my own code and xml
Yes, i did.

Quote
Don't you people read my posts above.
I understand you have frustrate because you not achieve goal. Why make accuse some one else ?

Quote
Just using the most basic XML still doesn't work.
Sorry i say wrong, picture make show is no true.

Quote
And what about the developers hard-coded code that makes my projects to not look right.
Highlighter is special in how parse and how handle tokens. In basic what you want is afaik no possible (not make it work 100% work like you want because is limitation).

Parser have default color and default (special) tokens and can only make override when you make define and change how work for default.

(*)
What I need to get to is.. everything in between the "[]"s will be red.... not the brackets, I want those white
afaik match token is always include in highlight color. See explain above paragraph.

« Last Edit: August 27, 2019, 06:05:26 am by Thausand »

Edson

  • Hero Member
  • *****
  • Posts: 1326
Re: All Things SynFacilSyn
« Reply #18 on: August 27, 2019, 06:11:22 am »
As I play with the samples... its difficult with out English documentation

Attached is a project file

1) I get an error box when the project loads, but can't read it. Something to do with Tokens I assume.
That message must be in the developed pas file because it isn't in unit one.

2) Numbers automatically turn fuchsia color even though I am not specifying it in my code.
Can't find where this is being set as a default

3) All I want to do is highlight red all music chords in between "[ ]"
And make the "[]" white to hide them but still keep it there for spacing issues if I were to remove it.

See screen below and project

You are using SynFileSyn (SynHighlighterFile). It's not SynFacilSyn. It's an old highlighter I developed previous to SynFacilSyn. I recommend not to use this.

SynFacilSyn is here: https://github.com/t-edson/SynFacilSyn You can obtain it from Online Package Manager too.

I posted a simple solution with SynFacilSyn to highlight tokens between [], including the brackets: https://forum.lazarus.freepascal.org/index.php/topic,45046.msg317563.html#msg317563

A chord could be as simple as "Ab" or "[A#]"
to as complex as...  "[A#sus7]"
What I need to get to is.. everything in between the "[]"s will be red.... not the brackets, I want those white

This is not so easy in SynFacilSyn, because tokens will need to consider external delimiters.

One solution would be to use blocks and change the background for this tokens, using delimiters with the same color of block background. Something like in the picture.

Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Thausand

  • Sr. Member
  • ****
  • Posts: 457
Re: All Things SynFacilSyn
« Reply #19 on: August 27, 2019, 06:11:58 am »
xml define for SynFacilSyn is only complicate when highlight 'language' is complicate.


@Thausand
Does this library except custom file types.... My xml is just plain text... it's not a language?

Yes it can accept custom file type. That why i make use quote "language".

Can be batch, SQL, or anything that can SynFacilSyn parse (and highlight by SynEdit). That mean you 'language' must have some kind of structure (Keywords/identifiers) and tokens that can be recognised/handled. As i wrote in previous post there is limitation.

Edson

  • Hero Member
  • *****
  • Posts: 1326
Re: All Things SynFacilSyn
« Reply #20 on: August 28, 2019, 05:37:15 am »
This is frustrating.

See screen. Red squares are text that are highlighted and Italicized... I don't even specify these tokens.

So, I am guessing that the developer hard coded the STRING behavior.
The only color I specify is KEYWORD...
Why is keyword RED... I thought keywords are a different attribute than a string

Code: Pascal  [Select][+][-]
  1. hlt2.KeywordAttribute.Foreground:=clRed;
  2.  

Also, the developer has hard-coded the "#" as a comment... and it italicizes
Why?
So, now How can I use a # for anything but a comments or number??

I'm afraid you're using other highlighter. SynFacilSyn can custom comments, strings, identifiers, numbers, ...

As I understand what you want to do, cannot be done directly with a SynFacilSyn. But you can modify the Highlighter to get the expected behaviour.

The following code, define a Highlighter derived from SynFacilSyn, that mark the brackets as "Numbers" and the interior as "Keyword":

Code: Pascal  [Select][+][-]
  1.   THL = class(TSynFacilSyn)
  2.   public
  3.     inBrackets: boolean;
  4.     procedure Next; override;
  5.   end;
  6.  
  7. procedure THL.Next;
  8. begin
  9.   posIni := posFin;
  10.   if inBrackets then begin  
  11.     posFin := posEx(']', fLine, posIni)-1;
  12.     if posFin = -1 then posFin := tamLin;
  13.     fTokenID:=tnKeyword;
  14.     inBrackets := false;
  15.   end else begin
  16.     charIni:=fLine[posFin];
  17.     fProcTable[charIni];
  18.     if GetToken = '[' then inBrackets := true;
  19.   end;
  20. end;
  21.  

Then you can define a simple syntax by code, like:

Code: Pascal  [Select][+][-]
  1.   hlt1 := THL.Create(self);  //my highlighter
  2.   hlt1.ClearSpecials;
  3.   hlt1.CreateAttributes;
  4.   hlt1.ClearMethodTables;
  5.   hlt1.DefTokIdentif('[$A-Za-z_]', '[A-Za-z0-9_]*');
  6.   hlt1.AddSymbSpec('[', hlt1.tnNumber);
  7.   hlt1.AddSymbSpec(']', hlt1.tnNumber);
  8.   hlt1.Rebuild;
  9.  

Changing the attributes of "Number" you can make brackets invisible.
 
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #21 on: August 28, 2019, 04:33:30 pm »
Thanks for all the suggestions.

I didn't  want to have to install OpenOfficer, but the translated version in html was missing some wording.

So, I installed OP / converted it to PDF and will use that

Thanks
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #22 on: August 28, 2019, 04:46:48 pm »
afaik match token is always include in highlight color. See explain above paragraph.


Thanks for the suggestion, but this won't work because I can NOT hard code chords because a user can create their own chords.

Thanks
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #23 on: August 28, 2019, 04:57:46 pm »
As I play with the samples... its difficult with out English documentation

Attached is a project file

1) I get an error box when the project loads, but can't read it. Something to do with Tokens I assume.
That message must be in the developed pas file because it isn't in unit one.

2) Numbers automatically turn fuchsia color even though I am not specifying it in my code.
Can't find where this is being set as a default

3) All I want to do is highlight red all music chords in between "[ ]"
And make the "[]" white to hide them but still keep it there for spacing issues if I were to remove it.

See screen below and project

You are using SynFileSyn (SynHighlighterFile). It's not SynFacilSyn. It's an old highlighter I developed previous to SynFacilSyn. I recommend not to use this.

SynFacilSyn is here: https://github.com/t-edson/SynFacilSyn You can obtain it from Online Package Manager too.

I posted a simple solution with SynFacilSyn to highlight tokens between [], including the brackets: https://forum.lazarus.freepascal.org/index.php/topic,45046.msg317563.html#msg317563

A chord could be as simple as "Ab" or "[A#]"
to as complex as...  "[A#sus7]"
What I need to get to is.. everything in between the "[]"s will be red.... not the brackets, I want those white

This is not so easy in SynFacilSyn, because tokens will need to consider external delimiters.

One solution would be to use blocks and change the background for this tokens, using delimiters with the same color of block background. Something like in the picture.

Nope.. I used the same files from your download SynFacilEdit example. I just changed the name (prueba.xml) and edited it.

Never used SynEdit highlighter with an XML.

The only SynEdit I used was the 2 simple and context PASs files
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #24 on: August 28, 2019, 05:21:09 pm »
As I play with the samples... its difficult with out English documentation

Attached is a project file

1) I get an error box when the project loads, but can't read it. Something to do with Tokens I assume.
That message must be in the developed pas file because it isn't in unit one.

2) Numbers automatically turn fuchsia color even though I am not specifying it in my code.
Can't find where this is being set as a default

3) All I want to do is highlight red all music chords in between "[ ]"
And make the "[]" white to hide them but still keep it there for spacing issues if I were to remove it.

See screen below and project

You are using SynFileSyn (SynHighlighterFile). It's not SynFacilSyn. It's an old highlighter I developed previous to SynFacilSyn. I recommend not to use this.

SynFacilSyn is here: https://github.com/t-edson/SynFacilSyn You can obtain it from Online Package Manager too.

I posted a simple solution with SynFacilSyn to highlight tokens between [], including the brackets: https://forum.lazarus.freepascal.org/index.php/topic,45046.msg317563.html#msg317563

A chord could be as simple as "Ab" or "[A#]"
to as complex as...  "[A#sus7]"
What I need to get to is.. everything in between the "[]"s will be red.... not the brackets, I want those white

This is not so easy in SynFacilSyn, because tokens will need to consider external delimiters.

One solution would be to use blocks and change the background for this tokens, using delimiters with the same color of block background. Something like in the picture.


I am trying your suggestion. However, I am getting and error and my code isn't highlighting

I may not have the pascal code right to load.
It loads find, but doesn't hight

Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.   hlt1 : TSynFileSyn;
  4.  
  5.  
  6.  
  7. procedure TForm1.FormCreate(Sender: TObject);
  8. begin
  9.   hlt1 := TSynFileSyn.Create(self);
  10.  
  11.   ed1.Highlighter := hlt1;
  12.  
  13.   hlt1.LoadFromFile('lex_lyr.xml');
  14.   LoadTestFile('test.lyr');
  15.  
  16. end;
  17.  
  18. procedure TForm1.LoadTestFile(arch: string);
  19. begin
  20.   ed1.Lines.LoadFromFile(arch);
  21. end;
  22.  
  23. procedure TForm1.FormDestroy(Sender: TObject);
  24. begin
  25.   hlt1.Free;
  26. end;  
  27.  
  28.  

Also, why am I getting this message and what does it say or mean?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #25 on: August 28, 2019, 05:37:11 pm »
The following code, define a Highlighter derived from SynFacilSyn, that mark the brackets as "Numbers" and the interior as "Keyword":

Code: Pascal  [Select][+][-]
  1.   THL = class(TSynFacilSyn)
  2.   public
  3.     inBrackets: boolean;
  4.     procedure Next; override;
  5.   end;
  6.  
  7. procedure THL.Next;
  8. begin
  9.   posIni := posFin;
  10.   if inBrackets then begin  
  11.     posFin := posEx(']', fLine, posIni)-1;
  12.     if posFin = -1 then posFin := tamLin;
  13.     fTokenID:=tnKeyword;
  14.     inBrackets := false;
  15.   end else begin
  16.     charIni:=fLine[posFin];
  17.     fProcTable[charIni];
  18.     if GetToken = '[' then inBrackets := true;
  19.   end;
  20. end;
  21.  

Then you can define a simple syntax by code, like:

Code: Pascal  [Select][+][-]
  1.   hlt1 := THL.Create(self);  //my highlighter
  2.   hlt1.ClearSpecials;
  3.   hlt1.CreateAttributes;
  4.   hlt1.ClearMethodTables;
  5.   hlt1.DefTokIdentif('[$A-Za-z_]', '[A-Za-z0-9_]*');
  6.   hlt1.AddSymbSpec('[', hlt1.tnNumber);
  7.   hlt1.AddSymbSpec(']', hlt1.tnNumber);
  8.   hlt1.Rebuild;
  9.  

Changing the attributes of "Number" you can make brackets invisible.

I am trying your suggestion... get two errors

THL = class(TSynFacilSyn);

Error: Identifier not found "TSynFacilSyn"

procedure Next: override;
Error: Fields cannot appear after a method or property definition, start a new visibility section first

My code...

Code: Pascal  [Select][+][-]
  1.  
  2. unit Unit1;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, Forms, Controls, Graphics, StdCtrls, SynEdit, SynEditHighlighter,
  10.   SynHighlighterPHP, SynHighlighterFile;
  11.  
  12. type
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     ed1: TSynEdit;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormDestroy(Sender: TObject);
  19.   private
  20.     procedure LoadTestFile(arch: string);
  21.     { private declarations }
  22.     THL = class(TSynFacilSyn);
  23.   public
  24.     inBrackets: boolean;
  25.     procedure Next: override;
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31.  
  32. implementation
  33. {$R *.lfm}
  34. var
  35.   hlt1 : TSynFileSyn;
  36.  
  37. { TForm1 }
  38.  
  39. procedure THL.Next;
  40. begin
  41.   posIni := posFin;
  42.   if inBrackets then begin
  43.     posFin := posEx(']', fLine, posIni)-1;
  44.     if posFin = -1 then posFin := tamLin;
  45.     fTokenID:=tnKeyword;
  46.     inBrackets := false;
  47.   end else begin
  48.     charIni:=fLine[posFin];
  49.     fProcTable[charIni];
  50.     if GetToken = '[' then inBrackets := true;
  51.   end;
  52. end;
  53. procedure TForm1.FormCreate(Sender: TObject);
  54. begin
  55.  
  56.   hlt1 := THL.Create(self);  //my highlighter
  57.   hlt1.ClearSpecials;
  58.   hlt1.CreateAttributes;
  59.   hlt1.ClearMethodTables;
  60.   hlt1.DefTokIdentif('[$A-Za-z_]', '[A-Za-z0-9_]*');
  61.   hlt1.AddSymbSpec('[', hlt1.tnNumber);
  62.   hlt1.AddSymbSpec(']', hlt1.tnNumber);
  63.   hlt1.Rebuild;
  64.  
  65.   ed1.Highlighter := hlt1;
  66.  
  67.   hlt1.LoadFromFile('lex_lyr.xml');
  68.  
  69.   LoadTestFile('test.lyr');
  70.  
  71. end;
  72.  
  73. procedure TForm1.LoadTestFile(arch: string);
  74. begin
  75.   ed1.Lines.LoadFromFile(arch);
  76. end;
  77.  
  78. procedure TForm1.FormDestroy(Sender: TObject);
  79. begin
  80.   hlt1.Free;
  81. end;
  82.  
  83. end.
  84.  
  85.  
« Last Edit: August 28, 2019, 06:31:37 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #26 on: August 28, 2019, 06:07:47 pm »
I read in the manual that a "#" symbol is not recommended as a token.

So can "#" be treated as string in between "[]"s??
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

Thausand

  • Sr. Member
  • ****
  • Posts: 457
Re: All Things SynFacilSyn
« Reply #27 on: August 28, 2019, 07:14:58 pm »
afaik match token is always include in highlight color. See explain above paragraph.


Thanks for the suggestion, but this won't work because I can NOT hard code chords because a user can create their own chords.

Thanks
That fair.

Unfortunate that can make problem. Best advise is use 'regular expression' (valid tokens) as example Edson make. Problem then comes when user can make chord that is no valid. Is many difficult make correct 'filter' because depend token order.

Maybe some one else on forum have a (good) solution for that ?

Thausand

  • Sr. Member
  • ****
  • Posts: 457
Re: All Things SynFacilSyn
« Reply #28 on: August 28, 2019, 07:25:38 pm »
Nope.. I used the same files from your download SynFacilEdit example. I just changed the name (prueba.xml) and edited it.

Never used SynEdit highlighter with an XML.

The only SynEdit I used was the 2 simple and context PASs files
Please have again good look at github link example i have post before.

You code make use of (very) old (and outdate) Facil unit that not work same as SynFacilSyn.

Github SynFacilSyn Directory: https://github.com/t-edson/SynFacilSyn
Gitthub simple SynFacil Example: https://github.com/t-edson/SynFacilSyn/tree/1.21/Sample_Project

Code: Pascal  [Select][+][-]
  1. ...
  2. interface
  3.  
  4. uses
  5.   SysUtils, Forms, Menus, Dialogs,  SynEdit,
  6.   // Make note this unit below
  7.   SynFacilHighlighter;  
  8.  
  9. ...
  10.  
  11. implementration
  12.   // make note type TSynFacilSyn
  13.   var hlt1 : TSynFacilSyn;
  14.  
  15. procedure TForm1.FormCreate(Sender: TObject);
  16. var
  17.   it: TMenuItem;
  18.   fResult: LongInt;
  19.   fFile: TSearchRec;
  20. begin
  21.   //configure highlighters
  22.   hlt1 := TSynFacilSyn.Create(self);  // my highlighter
  23.   ed1.Highlighter := hlt1;
  24.   hlt1.LoadFromFile('ObjectPascal.xml');
  25.   ed1.Lines.LoadFromFile('ObjectPascal_sample.txt');
  26.  
  27.   // Above is all what is need
  28.   // 1. Have a SynEdit Component on your form
  29.   // 2. declare TSynFacilSyn var
  30.   // 3. create TSynFacil instance.
  31.   // 4. 'link' highlighter with SynEdit
  32.   // 5. Load XML highlight descript from file (or memory)
  33.   // 6. Load 'language' (text with chords) in SynEdit Editor component.
  34.   ...
  35.  
  36. end;
  37.  

Edson have post example how modify TSynFacilSyn class to make TSynFacilSyn work more like you want (you can add that example from Edson to example if want)

Final, if  not like create xml file (on disk or memory) then can add highlight in program-code (like in document technical reference and like you set color in you own example that you show before). I make suggest use xml because can easy edit and reload (and when make error then can see and correct error fast)
« Last Edit: August 28, 2019, 08:04:40 pm by Thausand »

Thausand

  • Sr. Member
  • ****
  • Posts: 457
Re: All Things SynFacilSyn
« Reply #29 on: August 28, 2019, 07:38:50 pm »
I am trying your suggestion. However, I am getting and error and my code isn't highlighting

I may not have the pascal code right to load.
It loads find, but doesn't hight

You (stil) use wrong component. You use SynFileSyn and no SynFacilSyn Higlight.


Quote
Also, why am I getting this message and what does it say or mean?
The error is generate by xml parser (that has special meaning for SynFacilSyn). The only way to can tell what wrong is to see xml file. But rules SynFileSyn and SynFacilSyn are not same.

The error you get  with example Edson in you later post is because you no use unit SynFacilHighlighter but 'SynEditHighlighter,  SynHighlighterPHP, SynHighlighterFile;'.

Again they are not same and the 3 unit you use must not be use any more (please Edson make correct if  i say wrong).

So i make kind advise to have good olok example github and start over you project. I can make suggest to have two button (i post pic my example that have also two button). 1 button to (re-)load example text with chords and 1 button to (re-)load xml highlight descript file. Then you can edit the example and xml file, save to disk and reload them while you have you application for test running. Then can quick test xml highlight configuration and test what you have read in technical information reference.

Have good luck !

 

TinyPortal © 2005-2018