Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Unordered Groups - any Alternatives?
Unordered Groups - any Alternatives? [message #1795610] Wed, 26 September 2018 04:24 Go to next message
Eclipse UserFriend
I am working on an xtext-based project with a rather large grammar. I essentially use this grammar to have a textual way of describing a complex emf-model. Essentially, the language allows to specify nested objects with certain properties:
ParentObject name {
       Property1 = "Test";
       Property2 = "Test2";
       // ...

       ChildObject name {
               PropertyA = "ABC";
               PropertyB = "CDE";
               // ...
       }
}

Of course, every property setting is meant to occur only once or not at all. The current grammar is available here [0].

So far it is working fine, but it requires the user to know the expected "order" of the properties in the grammar. Sure, code completion helps a lot, but I would like to allow for more flexibility for the novice user. For instance, I would like to allow a specification like this one (order of properties is reversed):
ParentObject name {
       Property2 = "Test";
       Property1 = "Test2";
       // ...

       ChildObject name {
               PropertyB = "ABC";
               PropertyA = "CDE";
               // ...
       }
}

I tried with unordered groups, but pretty quickly the xtext generator in the mwe2 workflow required more than 16GB of heap space - even without adding the full flexibility in the grammar. This approach is not viable, because it does not fit the ressources of our CI environment.

As an alternative approach, I stumbled over this [1], which allows more flexibilty in the grammar, but uses a checker to enforce single occurance of properties. However, going this route would require a major redesign of the meta-model to have "generic property lists" in all places, which could be checked. I feel this would not help the longterm maintainability and readability of my xcore model [2] - just for the sake of more flexibility in the input language.

Are there any other approaches I could try? I like the idea of having a more flexible grammar and implement a checker on top of that, but I would like to minimize the effect on the meta-model.

Thank you -
Robert

[0]: https://github.com/RobertHilbrich/assist-public/blob/master/ch.hilbri.assist.mapping.dsl/src/ch/hilbri/assist/mapping/dsl/MappingDSL.xtext
[1]: https://stackoverflow.com/questions/23701169/free-order-of-rules-in-xtext
[2]: https://github.com/RobertHilbrich/assist-public/blob/master/ch.hilbri.assist.model/model/ASSIST-Model.xcore
Re: Unordered Groups - any Alternatives? [message #1795614 is a reply to message #1795610] Wed, 26 September 2018 04:46 Go to previous messageGo to next message
Eclipse UserFriend
The only additional option I see besides the mentioned ones is to provide any order of property tuple explicitly as an option. Bloats the grammar and explodes with any further property type. So likely no alternative in your case.

The generic approach would be my favorite. Of course this comes with the need for changing the metamodel.
Re: Unordered Groups - any Alternatives? [message #1795626 is a reply to message #1795614] Wed, 26 September 2018 05:25 Go to previous messageGo to next message
Eclipse UserFriend
Hmm ... this was not what I was hoping for ... sigh. Just in case, how would you redesign the meta-model?

Currently I have in my Xcore model:
class ParentObject {
        String propertyA
        int   propertyB
}

and in the grammar:
ParentObject:
      'ParentObject' name=ID '{'
               'PropertyA' '=' propertyA=STRING ';'
               'PropertyB' '=' propertyB=INT ';'
      '}';


In this case, do you think it would be wise to change the Xcore model to:
class Property {
       String name
}

class StringProperty extends Property {
        String value
}

class IntProperty  extends Property {
        int value
}

class PropertyA extends StringProperty {}

class PropertyB extends IntProperty {}

class ParentObject {
      contains Property[*] properties
}

and the corresponding Xtext grammar:
ParentObject:
      'ParentObject' name=ID '{'
               (PropertyA | PropertyB)*
      '}';
PropertyA:   name='PropertyA' value=STRING;
PropertyB:   name='PropertyB' value=INT;

If this is the recommended way to go, then suddenly the usage of the new meta model is way more complicated (I think), because instead of simply accessing PropertyA with
modelObject.propertyA
, I have to filter the entire list of properties, like:
modelObject.properties.filter[it instanceof PropertyA].head.value

This cannot be good for performance.

What do you think? Is there any better way to achieve this? I appreciate your feedback.
Re: Unordered Groups - any Alternatives? [message #1795629 is a reply to message #1795626] Wed, 26 September 2018 05:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi

I tried unordered groups but like you found them unhelpful.

Realistically you need to design a grammar so that the editor is friendly with tooling to make it sound. Having the grammar impose an exactly once rule, and worse an ordering dependency is not friendly; the user is faced with potentially badly diagnosed errors until the text is 'just right'.

Much easier to just parse a bag of legal options and make duplicate diagnosis a semantic warning, not a syntax error.

Regards

Ed Willink
Re: Unordered Groups - any Alternatives? [message #1795630 is a reply to message #1795626] Wed, 26 September 2018 05:34 Go to previous messageGo to next message
Eclipse UserFriend
am not sure if you should switch metalevels and have a "instances of eclasses" dsl that references eclasses and eattributes/references
Re: Unordered Groups - any Alternatives? [message #1795636 is a reply to message #1795630] Wed, 26 September 2018 06:26 Go to previous messageGo to next message
Eclipse UserFriend
I am not sure what you mean. Could you provide a brief example for the use-case above?
Re: Unordered Groups - any Alternatives? [message #1795637 is a reply to message #1795636] Wed, 26 September 2018 06:28 Go to previous messageGo to next message
Eclipse UserFriend
i mean something like

Instance: class=[ecore::EClass] name=ID "{"
properties+=Property*
"}"

Property: feature=[ecore::EStructuralFeature] "=" value=Expression

with references pointing to your xcore file
Re: Unordered Groups - any Alternatives? [message #1795638 is a reply to message #1795626] Wed, 26 September 2018 06:32 Go to previous messageGo to next message
Eclipse UserFriend
You could shortcut this expression in Xtend
def getPropertyA (ParentObject modelObject) {
   modelObject.properties.filter[it instanceof PropertyA].head.value
}


The access would not change and still read as
modelObject.propertyA


Of course it would slightly affect performance, but you may measure if there is actually a problem or not. Unless you have tons of code to produce I doubt you will experience a huge difference.

Another way would be to encode these navigation methods in Xcore. Hey, that's actually why you may want to use Xcore in favor of Ecore ;-)
Re: Unordered Groups - any Alternatives? [message #1799395 is a reply to message #1795638] Thu, 06 December 2018 03:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi and Happy Nikolaus - if that is a proper greeting!
I did all the refactoring as suggested by Karsten and used the power of Xcore/Xtend to encode this navigation methods. The code is online:

Unfortunately, the serializer stopped working. Serializing a simple model leads to the following exception:
Could not serialize Task via backtracking.
Constraint: Task_Task returns Task: (
  name=ID
  (
        properties+=RAMUtilizationProperty |
        properties+=ROMUtilizationProperty |
        properties+=DurationProperty  |
        ...
  )*
);
Values: name(1), properties(4)
Semantic Object: AssistModel.applications[0]->Application'A1'.tasks[0] ->Task'A1_T1' 
URI: platform:/resource/ExampleSystem/Scheduling/newSpec.sdsl
Context: Task returns Task

To me it seems as if the serializer is unable to determine the specific "property" class (like "DurationProperty") for each object in the list containing generic "property" objects.

Could you provide any hints on how to help the serializer work with this refactoring? Or should I rather try to reproduce this behaviour with a minimal example?

Thanks for any pointers!

Re: Unordered Groups - any Alternatives? [message #1799397 is a reply to message #1799395] Thu, 06 December 2018 03:26 Go to previous messageGo to next message
Eclipse UserFriend
Minimal examples is always what we need (or getting us on board of the project ;-) ). However, I doubt that we find the time to solve your issue.

Regarding the serializer I can't give you links, I don't know much about it. Moritz would be the right person to ask, but he isn't involved with Xtext ATM.
Re: Unordered Groups - any Alternatives? [message #1799401 is a reply to message #1799397] Thu, 06 December 2018 03:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi

I had high hopes that the introduction of unordered groups would solve an OCLinEcore parsing challenge. Multiple 'adjectives' such as ordered / unique / resolveProxies / volatile etc also !ordered / !unique / ... can be specified in any order but ...

[1] reports that I initially encountered a performance problem apparently due to an exponential search space. Later with Xtext 2.8.3 I tried again but got an ISE for comma-separated unordered group elements. I abandoned unordered groups.

My solution is to bundle all adjectives into a single list of String qualifiers property. The true/false/absent setting is mapped during semantic conversion/checking; duplicates/conflicts can be diagnosed as required. A list of String is also extensible. This has worked for me for many years, however there is an open Xtext Bugzilla [2] to the effect that the serialization comment for "(adj1 | adj2 | adj3 | adj4 | ... )*" is unstable since for some reason an arbitrary adjective is cherry picked as a root for the parsing. I have failed to understand the serialization comment but it seems to work; many JUnit tests consistently pass.

Regards

Ed Willink

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=427020
[2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=529333
Re: Unordered Groups - any Alternatives? [message #1799457 is a reply to message #1799401] Fri, 07 December 2018 02:19 Go to previous message
Eclipse UserFriend
Good Morning,
Thanks for the feedback - I tried to reproduce a minimal example which exhibits this behaviour ... and failed to do so. After digging through the serializer and nfa code, I discovered a stupid error in my code.
So, no worries. The serializer is working fine for me.
Previous Topic:Using forms based editor linked to XText
Next Topic:executing mwe2 programmatically within Eclipse plugin
Goto Forum:
  


Current Time: Sat Jun 14 17:22:42 EDT 2025

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

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

Back to the top