Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping in different contexts depending on non-resolved parameters
Scoping in different contexts depending on non-resolved parameters [message #815183] Wed, 07 March 2012 10:25 Go to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Hi @all!

I want to be able to specify a graph like:

Vertex v
Vertex u[1]
Edge u[1] -> v

for(n in {2,3,4}) {
   Vertex u[n]
   Edge u[n] -> v
   Edge u[n] -> u[n-1]
}

Edge u[2] -> u[1]


The edges have to reference to states, s.t. a state can have a qualified name like "v" or "u[1]", which I can write in XText like

IndexedID: id=ID (index=Indexing)?;
Indexing: '[' index = ArithExpr ']';
ArithExpr = ...

(where ArithExpr can be a an arbitrary arithmetic expression consisting of numbers or parameters, like 4+m/(2-x))
My questions are:
(1) Is it somehow possible to create several qualified names for one object, here:
"Edge u[n]" shall create three qualified names "u[2], u[3], u[4]", which can be referenced then like in "Edge u[2] -> u[1]"?

(2) The references shall be context sensitive, for example:
in "Edge u[2] -> u[1]" shall reference to the edges with qualified names u[2] and u[1]
but in "Edge u[n] -> v" the item "u[n]" shall be splitted (value converter?) in "u" and "n", where "u" references to the "u"-ID in "Vertex u[n]" and "n" references to the index "n" in "for(n in {2,3,4})".

A nicer way to solve this problem would be to generate this model into itself, like
Vertex v
Vertex u[1]
Edge u[1] -> v

Vertex u[2]
Edge u[2] -> v
Edge u[2] -> u[1]
Vertex u[3]
Edge u[3] -> v
Edge u[3] -> u[2]
...

Edge u[2] -> u[1]

and do then cross-reference validation in the generated model. But I think, I would need for generation the correct references for the indices described above.

Does anyone has an idea, how I can solve this?
Re: Scoping in different contexts depending on non-resolved parameters [message #816463 is a reply to message #815183] Thu, 08 March 2012 22:08 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
In your example u and u[x] are not the same objects, otherwise it
wouldn't matter if you write
u -> v
or
u[1] -> v
so adding multiple names won't help.

Xtext is meant for statically typed languages, so you cannot just
parameterize a name. Instead, you have to move the instantiation and
parameterization to your execution environment (interpreter or code
generator). From the perspective of Xtext, u[2] cannot be an element in
your example, as its definition requires evaluating an expression (the
for loop).

So your grammar should look like this

VertexDeclaration:
'Vertex' name=ID ('[' index=ArithExpr ']')?;

Edge:
'Edge' source=VertexRef '->' target=VertexRef;

VertexRef:
name=ID ('[' index=ArithExpr ']')?;

and the creation of real Vertices should take place in your execution
environment, which should also be implemented to resolve a VertexRef to
a Vertex instance after evaluating the index expression.


Am 07.03.12 11:25, schrieb Alex G:
> Hi @all!
>
> I want to be able to specify a graph like:
>
>
> Vertex v
> Vertex u[1]
> Edge u[1] -> v
>
> for(n in {2,3,4}) {
> Vertex u[n]
> Edge u[n] -> v
> Edge u[n] -> u[n-1]
> }
>
> Edge u[2] -> u[1]
>
>
> The edges have to reference to states, s.t. a state can have a qualified
> name like "v" or "u[1]", which I can write in XText like
>
>
> IndexedID: id=ID (index=Indexing)?;
> Indexing: '[' index = ArithExpr ']';
> ArithExpr = ...
>
> (where ArithExpr can be a an arbitrary arithmetic expression consisting
> of numbers or parameters, like 4+m/(2-x))
> My questions are:
> (1) Is it somehow possible to create several qualified names for one
> object, here:
> "Edge u[n]" shall create three qualified names "u[2], u[3], u[4]", which
> can be referenced then like in "Edge u[2] -> u[1]"?
>
> (2) The references shall be context sensitive, for example:
> in "Edge u[2] -> u[1]" shall reference to the edges with qualified names
> u[2] and u[1]
> but in "Edge u[n] -> v" the item "u[n]" shall be splitted (value
> converter?) in "u" and "n", where "u" references to the "u"-ID in
> "Vertex u[n]" and "n" references to the index "n" in "for(n in {2,3,4})".
>
> A nicer way to solve this problem would be to generate this model into
> itself, like
>
> Vertex v
> Vertex u[1]
> Edge u[1] -> v
>
> Vertex u[2]
> Edge u[2] -> v
> Edge u[2] -> u[1]
> Vertex u[3]
> Edge u[3] -> v
> Edge u[3] -> u[2]
> ..
>
> Edge u[2] -> u[1]
>
> and do then cross-reference validation in the generated model. But I
> think, I would need for generation the correct references for the
> indices described above.
>
> Does anyone has an idea, how I can solve this?


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:How to get EditingDomain for XText Editor
Next Topic:Scope provider/content assist mismatch
Goto Forum:
  


Current Time: Sat Apr 27 02:46:33 GMT 2024

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

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

Back to the top