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 07:36 Go to next message
Dominik Hirt is currently offline Dominik Hirt
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 09:49 Go to previous messageGo to next message
Michael Ernst is currently offline Michael Ernst
Messages: 46
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 16:20 Go to previous messageGo to next message
Dominik Hirt is currently offline Dominik Hirt
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 17:06 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 4422
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}  '#' 
;
Previous Topic:custom declarative scopes stop to work after dsl extend xbase
Next Topic:Exchange the InputStream
Goto Forum:
  


Current Time: Fri May 24 03:00:27 EDT 2013

Powered by FUDForum. Page generated in 0.01607 seconds