Injecting Ruby code to custom language
Hi,
I have a file that follows next pattern:
__DATA
{some code written using custom DSL language, lets call it MyLang}
__CODE
{some Ruby code}
__END
I already created custom plugin that highlights MyLang syntax, and now want to inject Ruby highlighting.
There is two solutions for this:
1) Inject MyLang to Ruby, and consider such files as Ruby code with injected MyLang
2) Inject Ruby to MyLang, and consider such files as MyLang code with injected Ruby
But in both ways, I need some mechanism to inject language based on prefix and suffix.
I tried to use ItelliLang and LanguageInjectionContributor with LanguageInjectionPerformer but my attempts weren't successful.
Could you please suggest how I can resolve such an issue?
I will be very grateful if you provide examples highlighting similar files that have two languages separated by a special separator. I think LanguageInjectionContributor EP should work in my case but I can't find any working example of such an injection. The example from doc unfortunately isn't described enough.
请先登录再写评论。
Hi,
It's unclear to me what is the main file type. I mean "__DATA", "__CODE", and "__END" tokens are part of some language too, right?
It seems to me that you should have a "main" language that injects MyLang and Ruby languages. I understand that the main file is neither Ruby, nor MyLang file.
Hi Karol, thanks for your reply
I got your point that I have to create some MainLang and define "__DATA", "__CODE", and "__END" tokens as part of MainLang.
But it's still unclear to me how the implementation of injection based on prefix and suffix will look like.
If I need that everything in between "__CODE" and "__END" tokens described as Ruby code, for example, what approach should I use?
Hi,
I would try implementing the following approach: