Skip to main content



      Home
Home » Modeling » TMF (Xtext) » cross reference on terminals/
cross reference on terminals/ [message #500722] Fri, 27 November 2009 12:54 Go to next message
Eclipse UserFriend
Hi, I am a newcomer. I'm trying a simple grammar to parse statements like:

class man( name:string, age:integer, father:man)

Here the grammar:

Model:
classes+=Class+;

terminal CLASS_NAME:
('a'..'z') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*;


Class :
'class' name= CLASS_NAME
'(' (attributes+=Attribute (',' attributes+=Attribute )* ) ')';

Attribute:
name=CLASS_NAME ':' type=[Type];

Type:
BuiltinType|Class;

BuiltinType:
name='integer'|'string';

On the input:

class place(name:string)

I have the error: "mismatched input 'string' expecting RULE_ID"

also on: class man(father:man)

"mismatched input 'man' expecting RULE_ID"

I'd like to have crossReference working if [Type] is actually a Class and no error if it is actually a terminal as 'integer'.
Also, I was expecting code completion working providing the words 'integer' 'string' when CTRL+Space where a Type is needed.

Any help is appreciate.
Thanks


[Updated on: Fri, 27 November 2009 12:54] by Moderator

Re: cross reference on terminals/ [message #500737 is a reply to message #500722] Fri, 27 November 2009 15:23 Go to previous messageGo to next message
Eclipse UserFriend
The terminal rule CLASS_NAME shadows the rule ID.
ID is used for crossreferences by default.

You'll either have to remove the CLASS_NAME rule and use ID instead,

e.g.

Class :
'class' name=ID '(' ...

or you'll have to use CLASS_NAME everywhere where you would have used ID


e.g.
Attribute :
name=CLASS_NAME ':' type=[Type|CLASS_NAME]


Cheers,
Sven

giovanni schrieb:
> Hi, I am a newcomer. I'm trying a simple grammar to parse statements like:
>
> class man( name:string, age:integer, father:man)
>
> Here the grammar:
>
> Model:
> classes+=Class+;
>
> terminal CLASS_NAME:
> ('a'..'z') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*;
>
> Class :
> 'class' name= CLASS_NAME '(' (attributes+=Attribute (','
> attributes+=Attribute )* ) ')';
> Attribute:
> name=CLASS_NAME ':' type=[Type];
>
> Type:
> BuiltinType|Class;
>
> BuiltinType:
> name='integer'|'string';
>
> On the input:
>
> class place(name:string)
> I have the error: "mismatched input 'string' expecting RULE_ID"
>
> also on: class man(father:man)
>
> "mismatched input 'man' expecting RULE_ID"
>
> I'd like to have crossReference working if [Type] is actually a Class
> and no error if it is actually a terminal as 'integer'.
> Also, I was expecting code completion working providing the words
> 'integer' 'string' when CTRL+Space where a Type is needed.
>
> Any help is appreciate.
> Thanks
>
>
>


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: cross reference on terminals/ [message #500998 is a reply to message #500737] Mon, 30 November 2009 11:18 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sven and thank you for your help.
I have removed the CLASS_NAME terminal rule and I am using ID.
Now references works on types( e.g. class man(father:man))
but I have the same problem before on the input:

class man(age:integer)

mismatched input 'integer' expecting RULE_ID.

Also code completion does not propose me 'integer' and 'string' but just the type man.
My language is very similar to the tutorial one:

entity Session {
property Title: String
property IsTutorial : Bool
}

but without type declaration

type String
type Bool

that are considered as primitive (builtin) types.
Of course I don't expect CTRL-click works on these terminals, but code completion I think could work.
Thanks again,
Giovanni
Re: cross reference on terminals/ [message #501041 is a reply to message #500998] Mon, 30 November 2009 13:42 Go to previous messageGo to next message
Eclipse UserFriend
Since 'integer' (as well as 'string') is a keyword your can't use it as
an identifier. Keywords shadow any terminal rules.
If you want to allow keywords you'll have to declare a datatype rule.

Identifier :
ID |'string'|'integer';

and use it where you've used ID before:

e.g.
Attribute :
name=Identifier ':' type=[Type|Identifier]


giovanni schrieb:
> Hi Sven and thank you for your help.
> I have removed the CLASS_NAME terminal rule and I am using ID.
> Now references works on types( e.g. class man(father:man))
> but I have the same problem before on the input:
>
> class man(age:integer)
> mismatched input 'integer' expecting RULE_ID.
>
> Also code completion does not propose me 'integer' and 'string' but just
> the type man.
> My language is very similar to the tutorial one:
>
> entity Session {
> property Title: String
> property IsTutorial : Bool
> }
>
> but without type declaration
> type String
> type Bool
>
> that are considered as primitive (builtin) types.
> Of course I don't expect CTRL-click works on these terminals, but code
> completion I think could work.
> Thanks again,
> Giovanni
>


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: cross reference on terminals/ [message #501191 is a reply to message #501041] Tue, 01 December 2009 08:36 Go to previous messageGo to next message
Eclipse UserFriend
Thanks again. Sorry for bother you; I'm sure that I'm missing something, but does still not work.
To be clearer, forget my example and consider the Entities example grammar we get when a new Xtext project is created.

Property:
'property' name=ID ':' type=[Type] (many?='[]')?;

suppose I want allow the type to be a Type (hence declared in the model) or a keyword like 'integer', but without declaring a Type 'integer' in the model
(the same happens between Classes and primitive types in java).

You suggested me to introduce a datatype rule

Identifier :
ID |'string'|'integer';

then property becomes

Property:
'property' name=ID ':' type=[Type|Identifier] (many?='[]')?;

but on the input

entity dummy{
property p:integer
}

I get the error "couldn't resolve reference to Type integer"... also code completion does not propose (integer,string) but only the entitiy dummy.
Should I work on these changing the validator and the scope provider?
Thanks
Giovanni

Re: cross reference on terminals/ [message #501556 is a reply to message #501191] Wed, 02 December 2009 14:05 Go to previous messageGo to next message
Eclipse UserFriend
If you really want to have built-in types, I would introduce a TypeRef
rule, like so :

Property :
'property' name=ID ':' type=TypeRef;

TypeRef :
(BuiltInTypeRef | RealTypeRef) many?='[]'?;

BuiltInTypeRef :
name=('integer'|'string');

RealTypeRef :
type=[Type];

Haven't tested it, though.
You'll typically have multiple places, where you use type references, so
extracting the whole thing in its own rule is a good idea.
In addition, you'll notice that working with the model becomes easier
when you have a type hierarchy for the different kind of type references.

Cheers,
Sven


giovanni schrieb:
> Thanks again. Sorry for bother you; I'm sure that I'm missing something,
> but does still not work.
> To be clearer, forget my example and consider the Entities example
> grammar we get when a new Xtext project is created.
>
> Property:
> 'property' name=ID ':' type=[Type] (many?='[]')?;
>
> suppose I want allow the type to be a Type (hence declared in the model)
> or a keyword like 'integer', but without declaring a Type 'integer' in
> the model
> (the same happens between Classes and primitive types in java).
>
> You suggested me to introduce a datatype rule
> Identifier :
> ID |'string'|'integer';
>
> then property becomes
>
> Property:
> 'property' name=ID ':' type=[Type|Identifier] (many?='[]')?;
>
> but on the input
> entity dummy{
> property p:integer
> }
>
> I get the error "couldn't resolve reference to Type integer"... also
> code completion does not propose (integer,string) but only the entitiy
> dummy.
> Should I work on these changing the validator and the scope provider?
> Thanks
> Giovanni
>
>


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: cross reference on terminals/ [message #501636 is a reply to message #501556] Thu, 03 December 2009 03:15 Go to previous messageGo to next message
Eclipse UserFriend
I did something similar:

Type: basic=('int' | 'boolean' | 'String') |
classref=[Class]
;

Field:
type=Type name=ID ';'
;

and it works

hope it helps
Lore

Sven Efftinge wrote:
> If you really want to have built-in types, I would introduce a TypeRef
> rule, like so :
>
> Property :
> 'property' name=ID ':' type=TypeRef;
>
> TypeRef :
> (BuiltInTypeRef | RealTypeRef) many?='[]'?;
>
> BuiltInTypeRef :
> name=('integer'|'string');
>
> RealTypeRef :
> type=[Type];
>
> Haven't tested it, though.
> You'll typically have multiple places, where you use type references, so
> extracting the whole thing in its own rule is a good idea.
> In addition, you'll notice that working with the model becomes easier
> when you have a type hierarchy for the different kind of type references.
>
> Cheers,
> Sven
>
>
> giovanni schrieb:
>> Thanks again. Sorry for bother you; I'm sure that I'm missing
>> something, but does still not work.
>> To be clearer, forget my example and consider the Entities example
>> grammar we get when a new Xtext project is created.
>>
>> Property:
>> 'property' name=ID ':' type=[Type] (many?='[]')?;
>>
>> suppose I want allow the type to be a Type (hence declared in the
>> model) or a keyword like 'integer', but without declaring a Type
>> 'integer' in the model
>> (the same happens between Classes and primitive types in java).
>>
>> You suggested me to introduce a datatype rule
>> Identifier :
>> ID |'string'|'integer';
>>
>> then property becomes
>>
>> Property:
>> 'property' name=ID ':' type=[Type|Identifier] (many?='[]')?;
>>
>> but on the input
>> entity dummy{
>> property p:integer
>> }
>>
>> I get the error "couldn't resolve reference to Type integer"... also
>> code completion does not propose (integer,string) but only the entitiy
>> dummy.
>> Should I work on these changing the validator and the scope provider?
>> Thanks
>> Giovanni
>>
>>
>
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Re: cross reference on terminals/ [message #501675 is a reply to message #501556] Thu, 03 December 2009 06:57 Go to previous messageGo to next message
Eclipse UserFriend
Thanks! Nice solution..now works.
Giovanni
Re: cross reference on terminals/ [message #502085 is a reply to message #501675] Sat, 05 December 2009 06:23 Go to previous messageGo to next message
Eclipse UserFriend
Works like a charm indeed, Sven. Nice to see that I run into the same issues as other people (so it "isn't me").

Next step is getting the generator right, but that should be peanuts now.
Re: cross reference on terminals/ [message #503718 is a reply to message #501556] Tue, 15 December 2009 03:34 Go to previous message
Eclipse UserFriend
Hi Sven,
as previously said, your solution works for the proposal, but seems that does not work in template proposal.
Given that template

entity ${entityName} {

property ${propName} : ${type:CrossReference('Property.type')}

}

the CrossReferenceResolver is unable to resolve the cross reference, (maybe needs to looking at the classes that actually implements TypeRef).

In fact, if I use just

${type:CrossReference('RealTypeRef.type')

works well, but of course the BuiltInTypeRef (integer, string) entries are missing in the drop donw list.
Maybe, would be enough to have a template variable resolver that rely on the proposal provider that actually works well.
Any idea?
Thanks
Giovanni
Previous Topic:Advanced examples for the declarative Java validator
Next Topic:Enum literals and case sensitivity
Goto Forum:
  


Current Time: Mon Jun 16 08:56:54 EDT 2025

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

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

Back to the top