Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » expressing inheritance in xtext
expressing inheritance in xtext [message #986978] Thu, 22 November 2012 16:49 Go to next message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
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 #986994 is a reply to message #986978] Thu, 22 November 2012 17:45 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2500
Registered: July 2009
Senior Member
On 2012-22-11 17:49, Robert Wild wrote:
> Is there a way to express inheritance in the xtext language itself?
>
No
> 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.
>
yes

> So, is there a way to express this in xtext directly. Or any other way
> to get this behaviour with less java code?

You may want to base your language on Xbase/Xtend as it already does
these things with "Java semantics". Will save you tons of time.

If you invent your language from scratch, you naturally also have to
invent the overloading mechanism (what and how does methods get
overloaded; on name alone, on parameter types, and what is a type in the
first place, does the language have generics, etc. etc.

There is no way this can be solved by some simple flags in a grammar; it
is much too complex for that.

- henrik
Re: expressing inheritance in xtext [message #987012 is a reply to message #986994] Thu, 22 November 2012 21:09 Go to previous messageGo to next message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
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.

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...

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.
Re: expressing inheritance in xtext [message #987021 is a reply to message #987012] Thu, 22 November 2012 22:35 Go to previous message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2500
Registered: July 2009
Senior Member
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
Previous Topic:Xtext generated Java Main
Next Topic:Qualified Quick Fix labels
Goto Forum:
  


Current Time: Sat Oct 25 04:24:14 GMT 2014

Powered by FUDForum. Page generated in 0.01998 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software