Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Check Validity of automatically generated instances
Check Validity of automatically generated instances [message #1852196] Wed, 04 May 2022 10:31 Go to next message
Eclipse UserFriend
Hello,

I am young user of xtext and I have some questions about its usage. I defined a grammar, and I try to generate automatically some instances of the grammar but there are no guaranties about the validity of the instances. The automatic generation is done by changing a few tokens (mutation). I am unsure that these local changes do not break my grammar rules. I am wondering if there is a function that can validate the instance automatically.

I have tried to use the "ParseHelper" class but I cannot use it out of the test project.

Thanks in advance

Antoine
Re: Check Validity of automatically generated instances [message #1852200 is a reply to message #1852196] Wed, 04 May 2022 12:37 Go to previous messageGo to next message
Eclipse UserFriend
hi, i cannot follow you. what exactly do you want to validate? syntax? semanctic?
also why cant you use ParseHelper
pase helper just create a resource. you can do the same

[Updated on: Wed, 04 May 2022 12:38] by Moderator

Re: Check Validity of automatically generated instances [message #1852201 is a reply to message #1852200] Wed, 04 May 2022 12:53 Go to previous messageGo to next message
Eclipse UserFriend
Besides that you can do something like (peudo code)

@Inject
Provider<XtextResourceSet> rsp;

XtextResourceSet rs = rsp.get();
Resource r = rs.createResource(URI.createURI("dummy.mydsl"))
r.load(new StringInputStream("Hello World"), null);
Re: Check Validity of automatically generated instances [message #1852229 is a reply to message #1852201] Thu, 05 May 2022 09:20 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

Thanks for your answers.

Sorry for not being precise enough. I will reexplain and I attach an image.

I have two scenarios:

First, I have defined a grammar and I can generate automatically instances. I am currently using the factory class created by xtext and modified the body of the methods according to my grammar rules. This can give me N instances from the grammar, but how can I be sure that they are correct w.r.t. the grammar rules? That is the top part of the image.

Second, I select one of the generated instances and I modify it automatically (by changing some of the tokens, i.e., what we call mutation). I want to know whether this new modified instance is valid w.r.t. the grammar. This is the bottom part of the image.

For instance, you can see that the modification inserted "pooling" token after the "conv" one. It is supposedly valid, but I would like to check it with the grammar rules. Is that possible?

I hope it is clearer now.

Thanks.

Antoine

[Updated on: Thu, 05 May 2022 09:20] by Moderator

Re: Check Validity of automatically generated instances [message #1852242 is a reply to message #1852229] Thu, 05 May 2022 12:46 Go to previous message
Eclipse UserFriend
this should work with my snippet.
Previous Topic:Xtext 2.27.0.M2 is out
Next Topic:Error: "Message could not be parsed" in Socket Mode
Goto Forum:
  


Current Time: Mon May 12 13:33:21 EDT 2025

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

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

Back to the top