Home » Modeling » TMF (Xtext) » embedded languages
embedded languages [message #897294] |
Mon, 23 July 2012 14:05 |
Vlad Dumitrescu Messages: 431 Registered: July 2009 Location: Gothenburg |
Senior Member |
|
|
Hi!
I have a faint memory that this was discussed before, but can't find a reference. [Excuse: I just got back from vacation]
Is it possible to handle multiple languages in a single file, assuming they are easily separated lexically (for example, in different document partitions)? One example is javadoc-style comments; another would be code embedded in a string.
Doing syntax highlighting is relatively easy, the comment/string/whatever token can be parsed and the result can be used in the semantic highlight operation. What about full integration (completion, cross-references, etc)?
When I saw the EmbeddedEditor class, I thought this could be it, but I suppose it refers to embedding it in another UI widget than an Editor... Theoretically, maybe it could be possible to use it within a part of an Editor, having all UI elements first detect which language support they should use at the current cursor position.
Maybe the amount of work needed would be prohibitive, but on the other hand for not many years ago I would have said the same about something like Xtext
best regards,
Vlad
|
|
|
Re: embedded languages [message #897313 is a reply to message #897294] |
Mon, 23 July 2012 14:52 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
On 2012-23-07 16:05, Vlad Dumitrescu wrote:
> Hi!
>
> I have a faint memory that this was discussed before, but can't find a
> reference. [Excuse: I just got back from vacation]
>
> Is it possible to handle multiple languages in a single file, assuming
> they are easily separated lexically (for example, in different document
> partitions)? One example is javadoc-style comments; another would be
> code embedded in a string.
>
Possible = yes, but not explicitly supported in any way.
> Doing syntax highlighting is relatively easy, the
> comment/string/whatever token can be parsed and the result can be used
> in the semantic highlight operation. What about full integration
> (completion, cross-references, etc)?
I imagine host language would simply recognize an embedded sequence as
Embedded, and put it in a partition. A second parser for the embedded
language kicks in after model is linked - this validates and links the
second language. ResourceDescription for the host language is extended
to also describe the embedded language. When parsing the embedded
language, it probably needs to understand the imports/visibility in the
host language.
> Maybe the amount of work needed would be prohibitive, but on the other
> hand for not many years ago I would have said the same about something
> like Xtext :)
>
Does not sound too difficult actually...
> best regards,
> Vlad
>
|
|
|
Re: embedded languages [message #897332 is a reply to message #897313] |
Mon, 23 July 2012 15:43 |
Vlad Dumitrescu Messages: 431 Registered: July 2009 Location: Gothenburg |
Senior Member |
|
|
Hi Henrik and thanks for the answer.
It doesn't sound too difficult indeed, but I think it is more difficult than that
There's a difference between manually adding support for language A to embed snippets in language B or C, but generic support has many hard cases (like for example, even language B could embed language D or, horror!, language A).
In addition, there are some semantic question marks too: for example, language A treats each embedded snippet as standalone, but language B might want to group them together...
From a technical point of view, EmbeddedEditor is a good candidate for a starting point: it can use resources that are not files. If one restricts the embedding to one level, I think that the main missing part is an ISourceViewer that links a document partition and doesn't require an own text widget. Or maybe one could define language B/C in a way that sees the language A parts as whitespace and then the same sourceviewer/text widget can be used? Then we "only" need to be able to connect all the languages to the editor and have logic to detect which language is active at each position...
Well, I am just thinking loud. Maybe there isn't enough interest to make this happen, but it certainly would be very cool!
best regards,
Vlad
|
|
|
Re: embedded languages [message #897359 is a reply to message #897332] |
Mon, 23 July 2012 18:29 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Vlad, Henrik,
the preferences page for template proposals actually does something
similar. It mixes velocity-like tokens with your language tokens. You
may want to dive into that code to get an idea on how to achieve that.
Unfortunately it is not API nor documented in a meaningful manner but
more the result of a very small pet project that I did two years ago.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 23.07.12 17:43, schrieb Vlad Dumitrescu:
> Hi Henrik and thanks for the answer.
>
> It doesn't sound too difficult indeed, but I think it is more difficult
> than that :)
> There's a difference between manually adding support for language A to
> embed snippets in language B or C, but generic support has many hard
> cases (like for example, even language B could embed language D or,
> horror!, language A).
> In addition, there are some semantic question marks too: for example,
> language A treats each embedded snippet as standalone, but language B
> might want to group them together...
>
> From a technical point of view, EmbeddedEditor is a good candidate for
> a starting point: it can use resources that are not files. If one
> restricts the embedding to one level, I think that the main missing part
> is an ISourceViewer that links a document partition and doesn't require
> an own text widget. Or maybe one could define language B/C in a way that
> sees the language A parts as whitespace and then the same
> sourceviewer/text widget can be used? Then we "only" need to be able to
> connect all the languages to the editor and have logic to detect which
> language is active at each position...
>
> Well, I am just thinking loud. Maybe there isn't enough interest to make
> this happen, but it certainly would be very cool! :)
>
> best regards,
> Vlad
>
>
>
|
|
| | | | |
Goto Forum:
Current Time: Tue Sep 24 05:15:56 GMT 2024
Powered by FUDForum. Page generated in 0.02681 seconds
|