Recent

Author Topic: Folding with TSynFacilSyn (for a JSON highlighter) [SOLVED]  (Read 4470 times)

mike_p

  • New Member
  • *
  • Posts: 20
Folding with TSynFacilSyn (for a JSON highlighter) [SOLVED]
« on: September 27, 2018, 01:19:51 pm »
(Not sure whether I should have posted in Third Party?)

I have started using the excellent TSynFacilSyn extra for TSynedit

I wanted to create a syntax highlighter for JSON that distinguishes 'Keys' from 'Values'. I'd also like folding for JSON Arrays.

It has been really easy to create the definition file for JSON:
Code: XML  [Select][+][-]
  1. <?xml version="1.0"?>
  2. <Language name="JSON" ext="json">
  3.   <Attribute Name="VALUE" ForeCol="#3030ff" Bold="True"></Attribute>
  4.   <Attribute Name="KEY" ForeCol="#a04040" Bold="True"></Attribute>
  5.   <Attribute Name="String" ForeCol="#400000" Bold="False"></Attribute>
  6.   <Attribute Name="StringLiteral" ForeCol="#400080" Bold="True" Italic="True"></Attribute>
  7.  
  8.   <Token CharsStart="0..9" Content = '-0..9.abcdef' Attribute='NUMBER'> </Token>
  9.   <Token Regex="\x22[^:]+\x22 ?:" Attribute='KEY' ></Token>
  10.   <Token Regex=": ?\x22[^\x22]+\x22" Attribute='VALUE'></Token>
  11.  
  12.   <Identifiers CharsStart= "a..z" Content = "a..z">
  13.         <StringLiteral>
  14.                 null true false
  15.         </StringLiteral>
  16.   </Identifiers>
  17.   <!-- Although comments are not valid JSON - I allow in my project and strip before sending -->
  18.   <Comment Start="//" ></Comment>
  19.  
  20.   <Block Name="JSONArray" Start='[' End=']' ></Block>
  21.   <Block Name="JSONObject" Start='{' End='}' ></Block>
  22.  
  23. </Language>
  24.  

My only problem is that folding does not work. The blocks for folding are marked in the left gutter, but don't actually fold.

If I swop to the standard javascript highlighter, folding works. Is this a problem with TSynFacilSyn, TSynEdit or me?
« Last Edit: September 28, 2018, 04:58:26 pm by mike_p »

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Folding with TSynFacilSyn (for a JSON highlighter)
« Reply #1 on: September 28, 2018, 03:31:38 am »
I'm the creator of SynFacilSyn and  I really don't know what is the reason.  :o

It has been working OK but it seems SynEdit has included some changes, in recent versons, that make this feature fails in SynFacilSyn.

I will check but maybe @Martin_fr can help us telling if there are some recent changes in SynEdit that affect the folding.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Folding with TSynFacilSyn (for a JSON highlighter)
« Reply #2 on: September 28, 2018, 04:17:46 am »
I found the problem  :D (I guess).

For some reason the instructions used by SynFacilSyn to manage folding: CodeFoldRange.Add() and CodeFoldRange.Pop() are not working well. I changed  for StartCodeFoldBlock() and EndCodeFoldBlock().

Changes are updated in the GitHub: https://github.com/t-edson/SynFacilSyn.
 
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

mike_p

  • New Member
  • *
  • Posts: 20
Re: Folding with TSynFacilSyn (for a JSON highlighter)
« Reply #3 on: September 28, 2018, 04:55:54 pm »
Thank you Edson! ( I was hoping you'd respond on this thread!)

Thank you not for just fixing my problem, but for sharing TSynFacilSyn in the first place.

I have downloaded the adjusted version from github and can confirm it now works perfectly.

When I wanted to create my syntax highlighter for JSON I looked at making my own highlighter but it looked like a huge task..Your component has made the task really easy.

I'm also going to use it for a small project I have for editing paths in SVG.


 

TinyPortal © 2005-2018