To make a link or terminal accessible through the same element name in Xtext / Xpand?

I have an Xtext grammar that describes statemachines, and I used references to previously declared events and states to describe transitions:

Event:
 'event' name=ID
 ;

State:
 'state' name=ID
 ;

Transition:
 event=[Event] '=>' state=[State]
    ;

When I use MWE to create an editor, it will check for the existence of reference positions. For example, a record

init => idle

the following will be required:

event init
state idle

to be present somewhere else in the code (btw I use one file for each statemachine, so it must be in one file). In my Xpand code templates, I can access the event and state as transition elements:

«FOREACH statemachine.transitions.event AS event// you get the idea

This works very well and I have been using it for quite some time.

statemachines (init, show, hide, finish ), , , , , .

:

Transition:
 event=( [Event] | ('init'|'show'|'hide'|'finish') ) '=>' state=[State]
    ;

, EventID, :

terminal EventID:
     'init'|'show'|'hide'|'finish'
     ;

:

Transition:
 event=( [Event] | EventID ) '=>' state=[State]
    ;

:

CustomEvent:
    'event' name=ID
    ;

BaseEvent:
    name=EventID
    ;

Event:
    CustomEvent | BaseEvent
    ;

Transition:
    event=[Event] '=>' state=[State]
    ;

.

:

Transition:
    ( event=[Event] | baseevent=EventID ) '=>' state=[State]
    ;

, , , .

, ... , :

?

+3

Source: https://habr.com/ru/post/1786142/


All Articles