Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Integrating Xbase in my DSL. How to activate scoping and validation?
Integrating Xbase in my DSL. How to activate scoping and validation? [message #1743395] Wed, 14 September 2016 22:49 Go to next message
Florian König is currently offline Florian KönigFriend
Messages: 30
Registered: June 2014
Member
Hi,

I want to create an extension for my DSL that can integrate Xbase code for special behavior. The new DSL shall :
- import EClasses from an ecore model file in the workspace (this works)
- specify methods with parameters, return values and a Xbase expression block

My current prototype can do this, but the scoping and validation of the Xbase block does not work.

The following is my example code:
grammar examplesystem.dsl.MyDsl with org.eclipse.xtext.xbase.Xbase

generate myDsl "http://www.dsl.examplesystem/MyDsl"
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Operations:
	'import' importURI=STRING
	('domain' domains+=[ecore::EPackage])*
	'operations' '{'
	operations+=MyOperation*
	'}';

MyOperation:
	'operation' name=ID '(' (parameters+=Parameter (',' parameters+=Parameter)*)? ')' 'returns' type=[ecore::EClassifier]
	body=XBlockExpression;

Parameter:
	{Parameter}
	type=[ecore::EClassifier] name=ID;


Example model:
index.php/fa/27071/0/

Xtext with broken scoping and validation:
index.php/fa/27073/0/

Now my question: What do I have to change to fix the problems? Is there a proper guide or tutorial for Xtext 2.10?

I have added my example projects as attachment to this post.

Thanks in advance,
Florian
Re: Integrating Xbase in my DSL. How to activate scoping and validation? [message #1743402 is a reply to message #1743395] Thu, 15 September 2016 06:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
you did not implement the JvmModelInferrer.
the jvmmodelinferrer is THE keypart to get xbase running.

you map your dsl concepts to java types
and your expression places to expression places in java like field initializers and method bodys.

http://www.eclipse.org/Xtext/documentation/104_jvmdomainmodel.html


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Integrating Xbase in my DSL. How to activate scoping and validation? [message #1743443 is a reply to message #1743402] Thu, 15 September 2016 13:51 Go to previous messageGo to next message
Florian König is currently offline Florian KönigFriend
Messages: 30
Registered: June 2014
Member
Well you are correct, I didn't implement the JvmModelInferrer. I also haven't encountered this tutorial before. Thanks for the link Smile
I recreated my example project using the tutorial. The imports and the validation and scoping now works correctly in the XBlockExpression.

grammar examplesystem.dsl.MyDsl with org.eclipse.xtext.xbase.Xbase

generate myDsl "http://www.dsl.examplesystem/MyDsl"
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Operations:
	{Operations}
	importSection=XImportSection?
	operations+=MyOperation*;

MyOperation:
	'operation' name=ValidID '(' (parameters+=FullJvmFormalParameter (',' parameters+=FullJvmFormalParameter)*)? ')'
	'returns' type=JvmTypeReference
	body=XBlockExpression;


However now I have to generate java code for my models to import them using XImportSection. How can I import the EClasses to use them in the XBlockExpression and parameters? Is this possible without code generation?
Re: Integrating Xbase in my DSL. How to activate scoping and validation? [message #1743448 is a reply to message #1743443] Thu, 15 September 2016 14:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
i am not sure of what you are talking.

import section is for jvm imports only. if you put the javaclasses of the metamodel on the classpath your should be able to work with them.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Integrating Xbase in my DSL. How to activate scoping and validation? [message #1743450 is a reply to message #1743448] Thu, 15 September 2016 14:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13879
Registered: July 2009
Senior Member
=> you would need a separate import section for the eclasses or reference them by qualified name

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to use @Flaky annotation
Next Topic:Resolving references to elements in mixed DSL (Xbase and other models)
Goto Forum:
  


Current Time: Mon Apr 12 16:46:16 GMT 2021

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

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

Back to the top