1

I want to define grammar in Xtext for the state machine. My rule is that one state machine must have [1.. * ] transitions, [1..1] initial state, [1..1] final state, and [0.. * ] intermediate states.

StateMachine:
    'InitialState' initialstate = InitialState
    'FinalState' finalstate = FinalState
    'States' '{' states+=State* '}' 
    'Transitions' '{' transitions+=Transitions ( "," transitions+=Transitions)* '}' 
    ;

This is how I have written the rules but when I generate the ecore model, I notice that the relation of the initial state and final state with the state machine is [0..1] and not [1..1] as I wanted it, and the relation between transition and statemachine is [0.. * ] and not [1..*]. Can you help me find out where I went wrong?

Thank you

MDE
  • 21
  • 1

1 Answers1

0

Xtext does not put any restrictions on the ecore file based on the concrete syntax. Their constraints would be already validated / guaranteed by the grammar / concrete syntax already.

If you want to have a more constrained ecore, you need to switch from generated to imported metamodel.

Sebastian Zarnekow
  • 6,609
  • 20
  • 23
  • So what you are saying is that the rules are correctly written, but they just do not show on the ecore metamodel? – MDE Jun 25 '20 at 12:36