Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Why the cross-reference does not work?
Why the cross-reference does not work? [message #854738] Tue, 24 April 2012 03:46 Go to next message
Eclipse UserFriend
Hi, all,

In my simple grammar (see the code below), I want to reference attributes of some entities, e.g., the age of a people. But when I use the grammar, an error occurs as below:

Couldn't resolve reference to Attribute 'age'.

My grammar is below:

Model:
	entity += Entity+
	expr += Expr*
;

Entity: 'entity' name=ID '{' attrs+=Attribute* '}';
	
Attribute: Type name=ID;

Expr: ref=[Attribute];

Type: 'int' | 'string';


and the instance is below:
entity People {
    int age	
}
age


What is the problem?

Thanks.

Robin

[Updated on: Tue, 24 April 2012 03:47] by Moderator

Re: Why the cross-reference does not work? [message #854761 is a reply to message #854738] Tue, 24 April 2012 04:07 Go to previous messageGo to next message
Eclipse UserFriend
From outside the Entity, the age attribute has to be referred to with
the fully qualified name, i.e. 'People.age'. Unfortunately, you specify
the cross-reference as being
[Attribute]
which is equivalent to
[Attribute|ID]
and the ID rule does not allow to the separator char '.'



Am 24.04.12 09:46, schrieb Robin Zhou:
> Hi, all,
>
> In my simple grammar (see the code below), I want to reference
> attributes of some entities, e.g., the age of a people. But when I use
> the grammar, an error occurs as below:
>
> Couldn't resolve reference to Attribute 'age'.
>
> My grammar is below:
>
>
> Model:
> entity += Entity+
> expr += Expr*
> ;
>
> Entity: 'entity' name=ID '{' attrs+=Attribute* '}';
>
> Attribute: Type name=ID;
>
> Expr: ref=[Attribute];
>
> Type: 'int' | 'string';
>
>
> and the instance is below:
>
> entity People {
> int age
> }
> age
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Why the cross-reference does not work? [message #854800 is a reply to message #854761] Tue, 24 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
Jan Kohnlein wrote on Tue, 24 April 2012 04:07
From outside the Entity, the age attribute has to be referred to with
the fully qualified name, i.e. 'People.age'. Unfortunately, you specify
the cross-reference as being
[Attribute]
which is equivalent to
[Attribute|ID]
and the ID rule does not allow to the separator char '.'





So, how to solve this problem?

Thanks.
Re: Why the cross-reference does not work? [message #854835 is a reply to message #854800] Tue, 24 April 2012 05:18 Go to previous message
Eclipse UserFriend
I sovled the problem using a format of
Expr: attr=[Attribute|QualifiedAttributeName];

QualifiedAttributeName: ID ('.' ID)*;


The question here is how to replace the '.' by '@' if the last ID is an attribute, so that I can gain the following elments like:

People.Child
People.Child@name

Of couse, I changed the grammar to allow entity nesting.

Thanks.

Robin
Previous Topic:Single File Generation - IFileSystemAccess/JavaIoFileSytemAccess
Next Topic:[Solved]Problem in a constrain
Goto Forum:
  


Current Time: Sun Jul 27 15:25:39 EDT 2025

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

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

Back to the top