Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parsing XBase in the inferrer
Parsing XBase in the inferrer [message #1758604] Thu, 30 March 2017 13:57 Go to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
Hi,
i want to parse simple expressions in the inferrer rather than building them by hand. so far i have:
	@Inject ParseHelper<XExpression> parseHelper


then in my code i simply call:
var variable=parseHelper.parse('''123''')

But the result is always null.

I've seen that in the unit test this works perfectly, i even created an injector in the plugin and added:
 @InjectWith(CLangInjectorProvider)

But still is not working.
From the source code of ParseHelper:
	public T parse(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet) {
		resourceHelper.setFileExtension(fileExtension);
		Resource resource = resourceHelper.resource(in, uriToUse, options, resourceSet);
		final T root = (T) (resource.getContents().isEmpty() ? null : resource.getContents().get(0));
		return root;
	}

i see that
resource.getContents().isEmpty()

is always true.
Is there a way to parse a String ans get an XExpression?
Thanks and regards!
Re: Parsing XBase in the inferrer [message #1758605 is a reply to message #1758604] Thu, 30 March 2017 14:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi,

this makes limited sense to me
- you shall not create injectors etc from a running eclipse yourself
- there is currently no support for creating artifical expressions inside the inferrer. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=481992

can you elaborate what you try to achive ?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Parsing XBase in the inferrer [message #1758607 is a reply to message #1758605] Thu, 30 March 2017 14:20 Go to previous messageGo to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
Hi,
i'm trying to modify an XBlockExpression and add one declaration at the start.
I have this code :
def expandBlock(XBlockExpression block){
var variable=XbaseFactory.eINSTANCE.createXVariableDeclaration()
variable.name=name
var sl=XbaseFactory.eINSTANCE.createXStringLiteral
sl.value="123"
variable.right=sl;
block.expressions+=variable
block.expressions.move(0,variable)	
}

but is too verbose and i haven't even put in there what i really want.
So i would like to write:
var variable=parser.parse('''var db=Service.getService(IDBService)''')
block.expressions+=variable
block.expressions.move(0,variable)	


This would be my life much easier, since those init expressions could get really complicated.
I evaluated having two methods, one for initialization calling a second one with the actual user code, but my users rejected it, since they want a more simple translation.
Regards
Re: Parsing XBase in the inferrer [message #1758608 is a reply to message #1758607] Thu, 30 March 2017 14:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
As i said before: this is not possible.

please use following pattern: (generated code)

public <ReturnType>doSomething(<Parameters>) {
// manual code here body='''....'''
someStatement();
someOtherStatement();
doSomethingInternal(params);
}
private <ReturnType>doSomethingInternal(<Parameters>) {
// generated code here body=model.expression
// ....
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Parsing XBase in the inferrer [message #1758609 is a reply to message #1758608] Thu, 30 March 2017 14:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
p.s. : yes there are two methods, but the users should see only the public one.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Parsing XBase in the inferrer [message #1758610 is a reply to message #1758608] Thu, 30 March 2017 14:28 Go to previous messageGo to next message
Rodrigo Ruiz is currently offline Rodrigo RuizFriend
Messages: 28
Registered: March 2017
Junior Member
Creating XExpressions by hand and adding them to the XBlockExpression works fine and nice, i want to spare me the task of creating them manually Wink
I wonder how the unit test works with the ParserHelper, but not my inferrer, i think i may need to setup something else...
Thanks for your fast response
Re: Parsing XBase in the inferrer [message #1758612 is a reply to message #1758610] Thu, 30 March 2017 14:36 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
the problem is the resource. there might be no proper setup

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:deploy xtext language as maven artifact
Next Topic:Custom class reference in inferrer
Goto Forum:
  


Current Time: Fri Jan 03 01:38:09 GMT 2025

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

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

Back to the top