Combining multiple custom languages
Hello,
the following has given me a bit of a headache. Basically, I'm trying to combine multiple custom languages. Let's call them custom language A, B and C.
The Goal
Custom Language A
May contain B and C.
Example
prototype {
test1 = ${FRAGMENT_OF_CUSTOM_LANUGAGE_C}
test2 = afx`
FRAGMENT_OF_CUSTOM_LANUGAGE_B
`
}
Custom Language B
Similar to JSX, based on HTML. May contain C.
Example
<div>{FRAGMENT_OF_CUSTOM_LANGUAGE_C}</div>
Custom Language C
Simple expression language. Has completion and other features, so reusability is desired.
Current Situation
B is not implemented as a custom language, yet. It is just injected HTML. This works for now.
C is extracted from A as a custom language with it's own lexer/parser. Doesn't work yet.
Possible Solutions
1. Using MultiplePsiFilesPerDocumentFileViewProvider
This would be the ideal solution, if my understanding is right. Should I use AbstractTemplateLanguageFileViewProvider for language A?
The parser for language A needs to return a token for the content of language B and C.
The parser for language B needs to return a token for the surrounding content, which is not part of the language and a token for the content of language C.
The parser for language C needs to return a token for the surrounding content, which is not part of the language.
Did I get this right?
2. Using language injection
I feel like this is not an ideal solution. Doesn't have the same degree of integration and might affect performance (?)
I understand that this is a rather complex question, so any feedback is very much appreciated.
What would be your approach to this? Am I on the right track?
The current state of things can be found here: https://github.com/cvette/intellij-neos/pull/37/files
Please sign in to leave a comment.