AvaloniaUI / AvaloniaEdit

Avalonia-based text editor (port of AvalonEdit)
MIT License
746 stars 148 forks source link

How to make own grammar ? #385

Open michalss opened 10 months ago

michalss commented 10 months ago

Hi is there any docs or sample how to make own grammer please ? I would need modify c# grammer and made some changes. How to do it pls ? There is not any docs.. :(

Regards

danipen commented 10 months ago

Grammars are provided by TextmateSharp repository.

michalss commented 10 months ago

Grammars are provided by TextmateSharp repository.

are you sure ?? https://github.com/danipen/TextMateSharp/issues/20 .. btw i dont know where to even start :( please make valuable docs or sample, since there is really nothing useful out there. I would preferer use json or xml from existing grammar...

danipen commented 10 months ago

What do you need, please describe.

michalss commented 10 months ago

Okay, please, I need to create my own grammar. I did develop a language very similar to C#, but it will include new keywords. My idea is to take the existing grammar of C# and modify it or simply add some new keywords to existing grammer somehow.

danipen commented 10 months ago

Yes so you'd need to base on the existing TextmateSharp c# grammar and make your changes from there. No docs are provided 😔

michalss commented 10 months ago

Yes so you'd need to base on the existing TextmateSharp c# grammar and make your changes from there. No docs are provided 😔

ok thx this is i know i guess but how to load this to AvaloniaEdit without recompile whole lib ? I did not find any way to load custom grammar to AvaloniEdit. There is not such a options or at least i did not find one.. :(

even I use IRegistryOption

 internal class ResmGrammer : IRegistryOptions
 {
     public IRawTheme GetDefaultTheme()
     {
         throw new NotImplementedException();
     }

     public IRawGrammar GetGrammar(string scopeName)
     {
         throw new NotImplementedException();
     }

     public ICollection<string> GetInjections(string scopeName)
     {
         throw new NotImplementedException();
     }

     public IRawTheme GetTheme(string scopeName)
     {
         throw new NotImplementedException();
     }
 }

this is all you get and this does not lead to any custom load or anything else.. So basically i have no idea how to use it in AvaloniaEdit, how to load...

danipen commented 10 months ago

Yes you need to build custom IRegistryOptions see LocaRegistryOptions usage here.