Cross Reference and Value in the same time [message #1719940] |
Wed, 13 January 2016 11:22 |
Missing name Mising name Messages: 25 Registered: February 2010 |
Junior Member |
|
|
Hi guys,
I am trying something tricky, may be for experience people not so tricky but it is for me
I have the following definition
Transition:
'transition' name=ID
'=>' target = [State]
'{'
('trigger' '{' trigger = Event '}')
'}';
Event:
'event' name=ID;
and the following snippet from the model.
state CUSTOMERSEARCH_RUNNING {
transition CustomerFound => CUSTOMER_FOUND {
trigger {
event onCustomerFound
}
}
}
state CUSTOMER_FOUND {
transition CustomerFound => CUSTOMER_AUTHENTICATED {
trigger {
event onCustomerAuthenticated
}
}
}
state CUSTOMER_AUTHENTICATED {
transition CustomerJoined => CUSTOMER_JOINED {
trigger {
event onCustomerJoined
}
}
transition OrdersLoading => ORDERS_LOADING {
trigger {
event onCustomerJoined
}
}
}
If you look to the CustomerAuthenticated State, you will see that it has 2 transition objects and they are both react to the same trigger event 'onCustomerJoined' (later in the full implementation they will distinguish them selfs with guard conditions) so when I model this way, later XTend complains that 'onCustomerJoined' Event is already created, which is completely valid while I use same ID twice.
Now what I want to achieve is that if an Event object is first time defined in the model, first time should create the object, 2nd time should reference the object.
Of course, I can create the Event objects some other place and reference them explicitly later on but I don't find this intuitive, I rather prefer that and user defines its events and system should be clever enough to figure out it is a reference or a new creation.
To reach this goal I change the grammar little bit,
Transition:
'transition' name=ID
'=>' target = [State]
'{'
('trigger' '{' trigger = EventBase '}')
'}';
EventReference:
typeRef=[Event]
;
EventCreation:
event=Event;
Event:
'event' name=ID;
and the notation at the model also (actually I don't want to but I don't see any other way, if someone can point me a way to do this without changing the notation I will be grateful).
state CUSTOMER_AUTHENTICATED {
transition CustomerJoined => CUSTOMER_JOINED {
trigger {
event onCustomerJoined
}
}
transition OrdersLoading => ORDERS_LOADING {
trigger {
onCustomerJoined
}
}
}
but now it complains about 'Couldn't resolve reference to Event 'onCustomerJoined'.' , I am guessing the notation 'event onCustomerJoined' created the event but it can still not find the 'onCustomerJoined' to reference.
Can anybody give me tips about whats going or better how would you solve this problem?
|
|
|
Re: Cross Reference and Value in the same time [message #1720048 is a reply to message #1719940] |
Thu, 14 January 2016 07:15 |
|
If you want to treat the first appearance as the declaration and the following as references to that, you need to
1) use a cross reference in the grammar
2) turn off cross reference validation for the given EReference (special implementation of LinkingDiagnosticMessageProvider)
3) Implement a QualifiedName provider and use the node model to get the text from the model.
Note that language-design wise this is not a good idea, as every little typo will create a new declaration instead of a linking error.
To improve this a bit, it may be a good idea, to have very different syntax coloring fro declarations and links.
Avoiding this kind of design is the best solution
Cheers,
Sven
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03153 seconds