Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Setting multiple EMF elements based on one grammar element.
Setting multiple EMF elements based on one grammar element. [message #950524] Sat, 20 October 2012 00:19
Robert Heath is currently offline Robert HeathFriend
Messages: 12
Registered: October 2012
Location: San Mateo
Junior Member
Hi, I'm struggling to find a solution for a problem I am trying to solve using Xtext and would appreciate any insight the community may have for my issue. I am currently trying to use Xtext to model a language and want to use some external libraries in the validation of my model instance. In the EMF model for the element I would like to validate I have an empty class called validatorRef which is extended in the external validation library. Using only the Xtext generated text editor I used a scoping rule to link the external reference to the model if a reference can be found. If a reference isn't found it shows up as an error in the text editor which is expected, and I'm still able to save the file. My problem comes when trying to transform the model through a separate interface and serialize it to the grammar defined in my .xtext file.

The class looks something like this:

entity validator{
}

entity item{
    name: EString
    typeName: EString
    validatorRef: validator
}   

The grammar rule looks like:

Item:
  {item}
  'item' name=EString 'type' validatorRef=[validator|EString]


As mentioned, in the text editor, there is no trouble saving this. Even when the scope is empty the correct name is still saved.

Question/Comment #1: This doesn't seem like a very clean way to accomplish what I'm trying to do. I don't actually want the validator to be serialized because it is external to the data being captured by the grammar, but I need to link a reference to the appropriate external validator to be used during scoping/validation/content assist. Is there a better way to do this using a rule like the one below and linking the reference after parsing?

Item:
  {item}
  'item' name=EString 'type' typeName=EString


Question #2: The solution I'm considering is to use the rule listed above, and modify the code generated by EMF to link to the appropriate validator when setTypeName() is called. Again, this doesn't seem like a clean solution, is it a reasonable way to approach the problem?

Question #3: Is there a way to set the validatorRef AND the typeName from the same string in the grammar and not worry about serializing the validatorRef (null is fine)?

Thanks for any insights, I have not worked with Java or Eclipse before this so it's all somewhat new to me. I am used to writing parsers that allow you to perform arbitrary actions on the data model based on the elements in the rule, but I understand that the xtext implementation allows automation of a serialization method for the data model to the define grammar.

Previous Topic:How to register my DSL to Java code generator?
Next Topic:Cross-referencing
Goto Forum:
  


Current Time: Fri Apr 23 15:28:03 GMT 2021

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

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

Back to the top