ATSynEdit: Assign a lexer

All questions regarding lexer highlighting schemes are discussed here...
Post Reply
ruma1974
Posts: 11
Joined: 23.08.2019 16:12

ATSynEdit: Assign a lexer

Post by ruma1974 »

I am trying to add a lexer defined in a cpp.lcf file to ATsynedit.

On a wiki page it says that TATAdapterEControl can be added to a ATsynedit.:
Adapter:= TATAdapterEControl.Create(Self);
ed.AdapterForHilite:= Adapter;

However, I assume that I have to load the definition of the highlighter. However, the method "Adapter.Lexer.LoadFromFile" cannot load *.lcf files.

I tried to follow the CudaText code:

an:=TecSyntAnalyzer.Create(self);
an.LoadFromFile('../lex/cpp.lcf');

This works but I have trouble finding a simple way to assign this "an" object to a ATsynedit. The CudaText code is more complex and works for multiple lexers, but I am looking for something simple and currently I only need one lexer.

btw. lex.lib.demo on Linux Mint 19.2 did not work for me. It fails to compile "F.edSample.Gutter[F.edSample.GutterBandBm].Visible:= false; " on line 229 in unit formlexerprop. Another issue I have is that most of the packages does not appear on the component palette. Nevertheless, CudaText compiles and works fine.


Thanks,

Rune
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

demo_econtrol_lexer_lib is now fixed. thanks for report, my mistake.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

AFAIR, you cannot load only one .lcf file without using LexerManager TecLexerList. use LexerManager (create new one) and load .lcf files into it.
then assign LexerManager-s items to your ATSynEdit adapter.

example loads lexermanager AppManager. example from CudaText.
file formmain.pas
function procedure TfmMain.DoOps_LoadLexerLib

Code: Select all

    for i:= 0 to ListFiles.Count-1 do
    begin
      an:= AppManager.AddLexer;
      //an.Name:= '_lx_'+LexerFilenameToComponentName(ListFiles[i]);
      an.LoadFromFile(ListFiles[i]);

      //load *.cuda-lexops
      fn_ops:= GetAppLexerOpsFilename(an.LexerName);
      if FileExistsUTF8(fn_ops) then
        DoLoadLexerStylesFromFile_JsonLexerOps(an, fn_ops, UiOps.LexerThemes);
    end; 
ruma1974
Posts: 11
Joined: 23.08.2019 16:12

Post by ruma1974 »

Excellent, I got it working but I needed to import some units from CudaText that I guess ideally should be part of the components.

Thanks also for making ATsynedit available and for fixing demo_econtrol_lexer_lib.

best,

Rune
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

what units of CudaText should be part of the component? it is separate project.
ruma1974
Posts: 11
Joined: 23.08.2019 16:12

Post by ruma1974 »

I am not sure if it is good idea but it would be nice if one could just specify a lexer directory for ATSynEdit and then the lexers auto load. However, now where I know how it works it is not a big deal to use the component as it is.

Thanks,

Rune
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

We cannot just set the directory. we must find all .lcf files in directory, then add files one by one to the LexerManager, then-- correct inter-lexer links. (using files *.cuda-lexmap).
Post Reply