Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Passing XExpressions as arguments outside of an XBlockExpression
Passing XExpressions as arguments outside of an XBlockExpression [message #1722587] Sat, 06 February 2016 09:12 Go to next message
Larry LeBron is currently offline Larry LeBronFriend
Messages: 124
Registered: October 2015
Senior Member
I'm writing a language using XBase, using the JVMModelInferrer.

In my language, I have entities which define parameters much like a java method:

Entity:
	'entity' name=ID  '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)* )? 


Elsewhere in my code, I reference these entities and want to be able to pass arguments to them from outside of XBlockExpressions. Current grammar:

EntityReference:
	'entRef' entity=[Entity] '(' (args+=XExpression (',' args+=XExpression)*)? ')' ';'
;


These are not standard function calls, so would not work in a standard XBlockExpression. In my generated code, I need to obtain these arguments as a list of Java Expressions.

What is the best approach here? I've tried getting an instance of the XBaseCompiler and calling toJavaExpression(), but it's getting a null pointer exception which seems to be because the argument XExpression has a null type. Perhaps I've just got it set up wrong? I haven't yet been able to find an example.

I did find a reference to this post, which mentions the delegate pattern. However, I'd love a more concise option, if one exists.



Re: Passing XExpressions as arguments outside of an XBlockExpression [message #1722590 is a reply to message #1722587] Sat, 06 February 2016 09:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
Id use the inferrer as much as i can

Thus for a ref with 2 Params id inferr 3 things

One method getArgs1 with body = expression1
One getArgs2 with bod = expression2

One invokation that is pure text

Body = '''invoke(getArg1(),getArgs2())'''


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: Passing XExpressions as arguments outside of an XBlockExpression [message #1722592 is a reply to message #1722590] Sat, 06 February 2016 09:50 Go to previous messageGo to next message
Larry LeBron is currently offline Larry LeBronFriend
Messages: 124
Registered: October 2015
Senior Member
I see, thanks for the quick reply and suggestion.

So, is there no simple way to just get the compilation output of the XExpression, then?

In your example, that would be the generated body of getArgs#().

[Updated on: Sat, 06 February 2016 09:50]

Report message to a moderator

Re: Passing XExpressions as arguments outside of an XBlockExpression [message #1722593 is a reply to message #1722592] Sat, 06 February 2016 10:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
This more a scoping issue. The scope provider will not be able to scope the
expression. Editing and the Compiler heavily rely on scoping. In the
bugizilla there is a longer standing request on build artificial
expressions and or modifying existing ones. And this is exactly your
usecase


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: Passing XExpressions as arguments outside of an XBlockExpression [message #1722606 is a reply to message #1722593] Sat, 06 February 2016 16:22 Go to previous messageGo to next message
Larry LeBron is currently offline Larry LeBronFriend
Messages: 124
Registered: October 2015
Senior Member
I see, thanks for clarifying.

So, is there currently no simple way to retrieve and set a scope for a compiler for my use case?

This seems like the slightly simpler case, since I wouldn't be trying to add anything to the scope during compilation. I would just be trying to get the Java expression String based on a set scope.
Re: Passing XExpressions as arguments outside of an XBlockExpression [message #1722607 is a reply to message #1722606] Sat, 06 February 2016 16:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
I don't know any maybe someone else

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: Passing XExpressions as arguments outside of an XBlockExpression [message #1722664 is a reply to message #1722607] Mon, 08 February 2016 07:11 Go to previous message
Larry LeBron is currently offline Larry LeBronFriend
Messages: 124
Registered: October 2015
Senior Member
I implemented this based on your suggestion and it's working well. It would be nice to keep the generated code more concise by directly invoking the compiler, but this does the trick for now. Thanks!
Previous Topic:Exception in Intellij
Next Topic:xText rename refactor
Goto Forum:
  


Current Time: Fri Sep 24 17:20:42 GMT 2021

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

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

Back to the top