Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » alternate between assignment and terminal
alternate between assignment and terminal [message #948796] Thu, 18 October 2012 11:36 Go to next message
Dominik Hirt is currently offline Dominik HirtFriend
Messages: 2
Registered: October 2012
Junior Member
I want to define as part of a grammar, the possibility to define the length of a given parameter with these xtext parser rule:

Length:
    ((min=INT)? ('..')? max=INT) | '#' 
;


Such a rule is syntactically correct and makes the following terms possible:

1..5
..4
3
#

I want to express, that for the case '#' the length isn't defined and set min=max=-1. How can I achieve that ? This is not only important for the unit test which can't check min and max values because they are not defined:

val de = model.segments.head.datenElemente.head as DE
assertEquals("0", de.length.min) <-- NullPointerException

How can I mix the assignments of min and max and this special case with terminal '#' ?

Kind Regards
Dominik
Re: alternate between assignment and terminal [message #948895 is a reply to message #948796] Thu, 18 October 2012 13:49 Go to previous messageGo to next message
Michael Ernst is currently offline Michael ErnstFriend
Messages: 49
Registered: July 2010
Member
It should be easy to define the value in the EMF model as default value. Go to the Eclipse properties view and define a default value!
Re: alternate between assignment and terminal [message #949218 is a reply to message #948895] Thu, 18 October 2012 20:20 Go to previous messageGo to next message
Dominik Hirt is currently offline Dominik HirtFriend
Messages: 2
Registered: October 2012
Junior Member
If I select that part of my grammar in my xtext file and open the properties view ... there isn't any possibility to set a default value ... ?
Re: alternate between assignment and terminal [message #949251 is a reply to message #949218] Thu, 18 October 2012 21:06 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13607
Registered: July 2009
Senior Member
Hi,

for the default value you have to:
- use a postprocessor to change the metamodel (http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/)
- use a manually maintained metamodel

for the NPE you have to take care of the warnings Xtext gives you

Length:
   ((min=INT)? ('..')? max=INT) |{Length}  '#' 
;


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
Previous Topic:Exchange the InputStream
Next Topic:Generating enums with methods (and fields)
Goto Forum:
  


Current Time: Thu Sep 24 00:10:05 GMT 2020

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

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

Back to the top