Skip to main content



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


Current Time: Mon Jul 07 16:16:06 EDT 2025

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

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

Back to the top