Need suggestion on how to create unique ids for tokens (or rules) [message #650927] |
Thu, 27 January 2011 08:22 |
Missing name Mising name Messages: 13 Registered: December 2010 |
Junior Member |
|
|
I was wondering if there was a best practice or a generic way to cause unique ids to be associated with tokens.
Like in the fowler example:
Statemachine:
{Statemachine}
'events' (events+=Event)* 'end'
'commands' (commands+=Command)* 'end'
(states+=State)*;
Let us say that we use xpand to generate java code, we need events, commands, and states to have unique ids. That the ids are unique accross all three types, meaning that an event with unique id "1" cannot have a command with the id "1".
I want these unique ids generated in xpand and be able to be passed around in the defines/templates.
Is there an example of how to do this?
I know one can iterate events and then commands and add a large number to the iterator index in the case of events to make it unlikely to have the same id for commands.
But I want to be able to assign a unique id to an event when it is first detected and for it have that id in the java code that is created through out.
As in I don't want a unique id generated for them every time they are iterated. If this is not clear I will respond to questions to clarify.
[Updated on: Thu, 27 January 2011 08:26] Report message to a moderator
|
|
|
|
Re: Need suggestion on how to create unique ids for tokens (or rules) [message #650987 is a reply to message #650927] |
Thu, 27 January 2011 11:22 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Just a sidenote: In textual modeling you usually avoid such technical
IDs but use qualified names to refer to elements instead. As technical
IDs are not persisted they might change if the model changes, probably
causing static references using that ID to point to nothing or something
completely different. Finding a robust strategy to derive these IDs can
be difficult.
Am 27.01.11 09:22, schrieb ocean5h@gmail.com:
> I was wondering if there was a best practice or a generic way to cause
> unique ids to be associated with tokens.
>
> Like in the fowler example:
>
> Statemachine:
> {Statemachine}
> 'events' (events+=Event)* 'end'
> 'commands' (commands+=Command)* 'end'
> (states+=State)*;
>
>
> Let us say that we use xpand to generate java code, we need events,
> commands, and states to have unique ids. That the ids are unique accross
> all three types, meaning that an event with unique id "1" cannot have an
> event with the id "1".
> I want these unique ids generated in xpand and be able to be passed
> around in the defines/templates.
>
> Is there an example of how to do this?
>
> I know one can iterate events and then commands and add a large number
> to the iterator index in the case of events to make it unlikely to have
> the same id for commands.
>
> But I want to be able to assign a unique id to an event when it is first
> detected and for it have that id in the java coded that is created
> through out.
>
>
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Powered by
FUDForum. Page generated in 0.03411 seconds