cross reference on terminals/ [message #500722] |
Fri, 27 November 2009 12:54  |
Eclipse User |
|
|
|
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 #501556 is a reply to message #501191] |
Wed, 02 December 2009 14:05   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #503718 is a reply to message #501556] |
Tue, 15 December 2009 03:34  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.06591 seconds