Recent

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

Edson

  • Hero Member
  • *****
  • Posts: 1325
Re: All Things SynFacilSyn
« Reply #30 on: August 29, 2019, 05:48:48 am »
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. procedure TForm1.FormCreate(Sender: TObject);
  6. begin
  7.   hlt1 := TSynFileSyn.Create(self);
  8.  
  9.   ed1.Highlighter := hlt1;
  10.  
  11.   hlt1.LoadFromFile('lex_lyr.xml');
  12.   LoadTestFile('test.lyr');
  13.  
  14. end;
  15.  
  16. procedure TForm1.LoadTestFile(arch: string);
  17. begin
  18.   ed1.Lines.LoadFromFile(arch);
  19. end;
  20.  
  21. procedure TForm1.FormDestroy(Sender: TObject);
  22. begin
  23.   hlt1.Free;
  24. end;  
  25.  
  26.  

Also, why am I getting this message and what does it say or mean?

Why are you still using "TSynFileSyn"?   >:( >:( >:( I told you. This is not SynFacilSyn   >:D >:D >:D

I repeat "SynFacilSyn is here: https://github.com/t-edson/SynFacilSyn You can obtain it from Online Package Manager too."
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Edson

  • Hero Member
  • *****
  • Posts: 1325
Re: All Things SynFacilSyn
« Reply #31 on: August 29, 2019, 07:37:32 am »
I read in the manual that a "#" symbol is not recommended as a token.

So can "#" be treated as string in between "[]"s??

"#" it's a symbol by default, but you can define it as string, number, keyword, or a any new custom token type you want.

I am trying your suggestion... get two errors

THL = class(TSynFacilSyn);

Error: Identifier not found "TSynFacilSyn"


That's because you're not using SynFacilSyn  :o
When using SynFacilSyn, you have to include the units:  SynFacilHighlighter.pas and probably SynFacilBasic.pas.

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

My code...

I think you need to declare the class THL in a type section, not inside the class TForm1.  :-[

Check the attached project.

If you want to change the colors, change the attributes programatically like indciated in Technical Documentation, Section 5.4.

If you want to read the token inside brackets, you can get the token in the method THL.Next:

Code: Pascal  [Select][+][-]
  1. procedure THL.Next;
  2. begin
  3.   posIni := posFin;
  4.   if inBrackets then begin
  5.     posFin := posEx(']', fLine, posIni)-1;
  6.     if posFin = -1 then posFin := tamLin;
  7.     fTokenID:=tnKeyword;
  8.     inBrackets := false;
  9.     // -----> Here the text inside the brackets can be obtained with GetToken()  <-----
  10.   end else begin
  11.     charIni:=fLine[posFin];
  12.     fProcTable[charIni];
  13.     if GetToken = '[' then inBrackets := true;
  14.   end;
  15. end;
  16.  
  17.  
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #32 on: August 29, 2019, 01:30:26 pm »
Why are you still using "TSynFileSyn"?   >:( >:( >:( I told you. This is not SynFacilSyn   >:D >:D >:D

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

Dude... hold on here...
Go back and read... I was already told that i had the wrong one
Give me a chance to work on it.

 :-[

Here is my code.

Code: Pascal  [Select][+][-]
  1.  
  2. unit Unit1;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils, Forms, Menus, Dialogs,  SynEdit,
  10.   SynFacilHighlighter;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     ed1: TSynEdit;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure FormDestroy(Sender: TObject);
  20.     procedure itClick(Sender: TObject);
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27. {$R *.lfm}
  28. //crea espacio para almacenar token
  29. var hlt1 : TSynFacilSyn;
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.FormCreate(Sender: TObject);
  34. var
  35.   it: TMenuItem;
  36.   fResult: LongInt;
  37.   fFile: TSearchRec;
  38. begin
  39.   //configure highlighters
  40.   hlt1 := TSynFacilSyn.Create(self);  //my highlighter
  41.   ed1.Highlighter := hlt1;
  42.   //hlt1.LoadFromFile('ObjectPascal.xml');
  43.   //ed1.Lines.LoadFromFile('ObjectPascal_sample.txt');
  44.   hlt1.LoadFromFile('lex_lyr.xml');
  45.   ed1.Lines.LoadFromFile('test.lyr');
  46.  
  47.   //load the syntax files
  48.   fResult :=  FindFirst('*.xml', faAnyFile, fFile );
  49.   while fResult = 0 do begin
  50.     it := TMenuItem.Create(self);
  51.     it.Caption:=fFile.Name;
  52.     it.OnClick:=@itClick;
  53.     fResult := FindNext(fFile);
  54.   end;
  55.   FindClose(fFile);
  56. end;
  57.  
  58. procedure TForm1.FormDestroy(Sender: TObject);
  59. begin
  60.   hlt1.Free;
  61. end;
  62.  
  63. procedure TForm1.itClick(Sender: TObject);
  64. begin
  65.   hlt1.LoadFromFile(TMenuItem(Sender).Caption);
  66.   ed1.Invalidate;
  67. end;
  68.  
  69. end.
  70.  
  71.  

Here is the download... for 1.2
« Last Edit: August 29, 2019, 01:39:48 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 #33 on: August 29, 2019, 01:50:42 pm »
And.. here is my basic XML to start... it does work.

Code: Pascal  [Select][+][-]
  1. <?xml version="1.0"?>
  2. <Language>
  3. <symbols>
  4. </symbols>
  5.     <Keyword>
  6.     Lord
  7.     pray
  8.     We
  9.     </Keyword>
  10. </Language>

Now I have to figure out how to make all the chords red in between the "[]"s WITHOUT hard-coding the chords....
PLUS... be able to use # as a chord string

THEN... I have to find a way to make all the "[]"s either a space or white. They cannot be removed as that is what keep the chord in alignment and in the right place.
« Last Edit: August 29, 2019, 01:52:44 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 #34 on: August 29, 2019, 02:06:08 pm »
Issue#1

I am trying to figure our where "[]"s belong.

I out them in key and symbols, but error.... invaild text

What are these "[]"s considered to be??


1) Need to make them white or sapces
2) Need them to figure out chord inbetween
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 #35 on: August 29, 2019, 02:18:07 pm »
Edson... I am trying your example again from thread...
https://forum.lazarus.freepascal.org/index.php/topic,46529.msg332072.html#msg332072


However, again it is generating two errors because you only gave me partial code.
I believe things are in the worng place in my code.

Errors
unit1.pas(20,3) Error: Fields cannot appear after a method or property definition, start a new visibility section first
unit1.pas(20,7) Fatal: Syntax error, ":" expected but "=" found

All my code...
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, Forms, Menus, Dialogs,  SynEdit,
  9.   SynFacilHighlighter;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     ed1: TSynEdit;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormDestroy(Sender: TObject);
  19.     procedure itClick(Sender: TObject);
  20.   THL = class(TSynFacilSyn)                     // <----- ERROR
  21.   public
  22.     inBrackets: boolean;
  23.     procedure Next; override;
  24.   end;
  25.  
  26. end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32. {$R *.lfm}
  33. //crea espacio para almacenar token
  34. var hlt1 : TSynFacilSyn;
  35.  
  36. { TForm1 }
  37. procedure THL.Next;
  38. begin
  39.   posIni := posFin;
  40.   if inBrackets then begin
  41.     posFin := posEx(']', fLine, posIni)-1;
  42.     if posFin = -1 then posFin := tamLin;
  43.     fTokenID:=tnKeyword;
  44.     inBrackets := false;
  45.   end else begin
  46.     charIni:=fLine[posFin];
  47.     fProcTable[charIni];
  48.     if GetToken = '[' then inBrackets := true;
  49.   end;
  50. end;
  51.  
  52. procedure TForm1.FormCreate(Sender: TObject);
  53. var
  54.   it: TMenuItem;
  55.   fResult: LongInt;
  56.   fFile: TSearchRec;
  57. begin
  58.   hlt1 := THL.Create(self);  //my highlighter
  59.   hlt1.ClearSpecials;
  60.   hlt1.CreateAttributes;
  61.   hlt1.ClearMethodTables;
  62.   hlt1.DefTokIdentif('[$A-Za-z_]', '[A-Za-z0-9_]*');
  63.   hlt1.AddSymbSpec('[', hlt1.tnNumber);
  64.   hlt1.AddSymbSpec(']', hlt1.tnNumber);
  65.   hlt1.Rebuild;
  66.  
  67.   hlt1.LoadFromFile('lex_lyr.xml');
  68.   ed1.Lines.LoadFromFile('test.lyr');
  69.  
  70.   //load the syntax files
  71.   fResult :=  FindFirst('*.xml', faAnyFile, fFile );
  72.   while fResult = 0 do begin
  73.     it := TMenuItem.Create(self);
  74.     it.Caption:=fFile.Name;
  75.     it.OnClick:=@itClick;
  76.     fResult := FindNext(fFile);
  77.   end;
  78.   FindClose(fFile);
  79. end;
  80.  
  81. procedure TForm1.FormDestroy(Sender: TObject);
  82. begin
  83.   hlt1.Free;
  84. end;
  85.  
  86. procedure TForm1.itClick(Sender: TObject);
  87. begin
  88.   hlt1.LoadFromFile(TMenuItem(Sender).Caption);
  89.   ed1.Invalidate;
  90. end;
  91.  
  92. end.
  93.  


Please, provide the entire code or just the project you worked out.
That would save time then dealing with these errors.

People forget... if your a pro at pascal this is easy... but I am not.

Don't know what to do with that THL = class() line
« Last Edit: August 29, 2019, 02:22:08 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 #36 on: August 29, 2019, 02:30:23 pm »
Also, FYI... I think i prefer to doing this in code instead of using XML... I don't want user to mess with the XML.
I am reading more of the manual now
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 #37 on: August 29, 2019, 02:44:10 pm »
Confused...

The Spanish version of DOC says Rev 7
The ODT (English version) says Rev 1 (1.20)

Is this older version up to date with newer SynFacilcSyn??
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 #38 on: August 29, 2019, 03:24:18 pm »
Boy this is tough

This is what i have for coding... going by manual... NO XML involved.

I get error on this line...     atribKeyword: TSynHighlighterAttributes;
unit1.pas(36,17) Error: Identifier not found "TSynHighlighterAttributes"

Just trying to get keywords (which work -ya-hoo) to be red instead of the default green
What am I missing?

Code: Pascal  [Select][+][-]
  1.  
  2. uses
  3.    SynFacilHighlighter;
  4.  
  5. //crea espacio para almacenar token
  6. var hlt1 : TSynFacilSyn;
  7.  
  8. procedure TForm1.FormCreate(Sender: TObject);
  9. var
  10.   it: TMenuItem;
  11.   fResult: LongInt;
  12.   fFile: TSearchRec;
  13.   atribKeyword: TSynHighlighterAttributes;  //<!-- ERROR HERE
  14. begin
  15.   //configure highlighters
  16.   hlt1 := TSynFacilSyn.Create(self);
  17.   ed1.Highlighter := hlt1;
  18.   hlt1.ClearMethodTables;
  19.   hlt1.CreateAttributes;
  20.  
  21.   {cannot use "[]"s or # here}
  22.   hlt1.AddKeyword('Lord');      
  23.   hlt1.AddKeyword('pray');
  24.  
  25.   hlt1.KeywordAttri.Foreground: =clRed;  // eorr here also if i comment out the other attr code
  26.   atribKeyword:= hlt1.tkKeyword;
  27.   atribKeyword.Foreground: =clRed;
  28.  
  29.   hlt1.Rebuild;
  30.   ed1.Lines.LoadFromFile('test.lyr');
  31.  
  32. end;
  33.  
  34.  
  35.  

UPDATE:
Using this line (from manual) doesn't work either - identifier not found
hlt1.KeywordAttri.Foreground: =clRed;

That means i am missing a "uses" or var someplace.
And I have everything the manual says... I believe
« Last Edit: August 29, 2019, 03:45:30 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: 1325
Re: All Things SynFacilSyn
« Reply #39 on: August 29, 2019, 04:13:43 pm »
Boy this is tough

This is what i have for coding... going by manual... NO XML involved.

I get error on this line...     atribKeyword: TSynHighlighterAttributes;
unit1.pas(36,17) Error: Identifier not found "TSynHighlighterAttributes"

Just trying to get keywords (which work -ya-hoo) to be red instead of the default green
What am I missing?

UPDATE:
Using this line (from manual) doesn't work either - identifier not found
hlt1.KeywordAttri.Foreground: =clRed;

That means i am missing a "uses" or var someplace.
And I have everything the manual says... I believe

You need to use:

  hlt1.tkKeyword.Foreground := clRed;

And you need to include the unit "Graphics", in order to use the constant for colors (clRed, clGreen, ...).

Please check the sample project I included in my previous post.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #40 on: August 29, 2019, 04:36:44 pm »
Boy this is tough

This is what i have for coding... going by manual... NO XML involved.

I get error on this line...     atribKeyword: TSynHighlighterAttributes;
unit1.pas(36,17) Error: Identifier not found "TSynHighlighterAttributes"

Just trying to get keywords (which work -ya-hoo) to be red instead of the default green
What am I missing?

UPDATE:
Using this line (from manual) doesn't work either - identifier not found
hlt1.KeywordAttri.Foreground: =clRed;

That means i am missing a "uses" or var someplace.
And I have everything the manual says... I believe

You need to use:

  hlt1.tkKeyword.Foreground := clRed;

And you need to include the unit "Graphics", in order to use the constant for colors (clRed, clGreen, ...).

Please check the sample project I included in my previous post.

Perfect... didn't know Graphics was required for colors because every time you create a new project that uses is automatically inserted.
You may want to add that note to your manuals. Newbies won't know that... which I am.  :)

Okay... now. On to how I deal with "[]"'s

Did you read my thread #35 above??
« Last Edit: August 29, 2019, 04:47:20 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: 1325
Re: All Things SynFacilSyn
« Reply #41 on: August 29, 2019, 04:51:01 pm »
Okay... now. On to how I deal with "[]"'s

What way can I use those brackets?

Since they don't work as keywords or symbols... what, a token or defidentifier?

You can define brackets in any type of token.

Check the sample I attached (This is the third time I told you). There, brackets is defined as "Numbers" (what is a token type), but you can define it in any other type. The text inside brackets (whatever it is) is defined as Keyword, but you can define it in any other type.

If you want to compare firsts the interior of the brackets, you can use GetToken() as I indicated in a previous post.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: All Things SynFacilSyn
« Reply #42 on: August 29, 2019, 05:17:44 pm »
Okay... now. On to how I deal with "[]"'s

What way can I use those brackets?

Since they don't work as keywords or symbols... what, a token or defidentifier?

You can define brackets in any type of token.

Check the sample I attached (This is the third time I told you). There, brackets is defined as "Numbers" (what is a token type), but you can define it in any other type. The text inside brackets (whatever it is) is defined as Keyword, but you can define it in any other type.

If you want to compare firsts the interior of the brackets, you can use GetToken() as I indicated in a previous post.

Okay.. sorry didn't see that attachment.

I wish this forum system made those more prominent... hard to see sometime among all the text.


I had a stroke back in JAn, so my brain and focus sometimes misses stuff, more than usual for a 57 year old man.

Thanks... I will work on all this.
You have been a BIG help
« Last Edit: August 29, 2019, 05:36:57 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 #43 on: August 29, 2019, 06:29:59 pm »
Quick Q... What attribute syntax do I use for the default green of that demo you provided??

Code: Pascal  [Select][+][-]
  1. hlt1.DefTokIdentif('[$A-Za-z_]', '[A-Za-z0-9_]*');

I tried to change the chord color from green, but don't know what type of sttribute to use.

I got this list from your english manual, but none of them work for those chord colors.

Code: Pascal  [Select][+][-]
  1. //hlt1.tkEol.Foreground := clBlue;
  2.   //hlt1.tkSpace.Background := clBlue;
  3.   //hlt1.tkSymbol.Foreground := $FCFCFC;
  4.   //hlt1.tkIdentif.Foreground := clBlack;
  5.   hlt1.tkNumber.Foreground := $FCFCFC;
  6.   //hlt1.tkKeyword.Foreground := clBlue;
  7.   hlt1.tkString.Foreground := clBlue;    
  8.   //hlt1.tkComment.Foreground := clBlue;      
  9.  

How do you make it bold too.

I tired this, but makes all my text bold... I don't know what type the chords are.
I think its an identifier, per below, doesn't work on my chords.

Code: Pascal  [Select][+][-]
  1.  
  2. hlt1.tkiDentif.Style:=[FsBold];
  3.  
  4.  
« Last Edit: August 29, 2019, 06:43:58 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: 1325
Re: All Things SynFacilSyn
« Reply #44 on: August 29, 2019, 07:00:52 pm »
Quick Q... What attribute syntax do I use for the default green of that demo you provided??

Code: Pascal  [Select][+][-]
  1. hlt1.DefTokIdentif('[$A-Za-z_]', '[A-Za-z0-9_]*');

I tried to change the chord color from green, but don't know what type of sttribute to use.


Use

Code: Pascal  [Select][+][-]
  1.   hlt1.tkKeyword.Foreground := clGray;
  2.   hlt1.tkKeyword.Style := [fsBold];
  3.  

Brackets are defined as tkNumber.
Interior is defined as tkKeyword.

You can use ANY OTHER TOKEN TYPE (predefined or creating new ones).  This is just a sample.


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

 

TinyPortal © 2005-2018