expressing inheritance in xtext [message #986978] |
Thu, 22 November 2012 11:49  |
Eclipse User |
|
|
|
Is there a way to express inheritance in the xtext language itself?
This minimalistic example basically does what I want to do. Assuming 'override' should work like the Java annotation does, it would require a lot of code in ContentAssist and Validation to make this work.
Class:
"class" name=ID "extends" super=[Class] "{"
(methods+=Method)+
"}"
;
Method:
(override?="override")? "void" name=ID
;
Validation would have to check if the overridden method exists in the superclass and if one method shadows another without having override specified. ContentAssist would have to look in the superclass to display suggestions for methods after override was specified. And all this recursively through the whole hierachy.
So, is there a way to express this in xtext directly. Or any other way to get this behaviour with less java code?
|
|
|
|
|
Re: expressing inheritance in xtext [message #987021 is a reply to message #987012] |
Thu, 22 November 2012 17:35  |
Eclipse User |
|
|
|
On 2012-22-11 22:09, Robert Wild wrote:
> I'm not actually building a Java-like language. I've just used this as
> an example to illustrate the semantics I need. These semantics cover
> most of what I need plus a few variations.
>
I would use Xbase/Xtend as the base for a new language just to avoid
having to do all the work even if my language did not expose all of the
functionality of Xtend.
Your language does not have to be Java like at all; but you benefit
greatly from having a comprehensive implementation of a language that
has all the java concepts even if your language has a different concrete
syntax.
> As I understood it, Xbase/Xtend is just for using jvm types in xtext,
> right? Or would it help it in any way. I've actually no clue for what I
> could use Jvm types in my dsl. Or is there more to it? But maybe it just
> doesn't help my particular problem...
>
Well, what do you overload on? Only name (like Ruby), or name and
argument types (like Java). Is your language object oriented? How do you
bind instance to method; on actual type, or declared type, how do you do
the same if using parameter overloading? (Just to mention a few things
where you can decide to use Xtend's semantics for this rather that
figuring out a working scheme of your own).
> Btw. I found a Project called FJ-eclipse that has a DSL that's basically
> a simple Java. I haven't looked very deeply into it yet, but their
> validator, contentAssist and ScopeProvider don't contain all that much
> code.
If you have a simple enough language, it is not that difficult to do it
on your own. If you find that you need a type system; then I can highly
recommend using Xbase/Xtend.
- henrik
|
|
|
Powered by
FUDForum. Page generated in 0.03318 seconds