Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58657] |
Wed, 15 July 2009 02:44  |
Eclipse User |
|
|
|
Hi,
Another dump question in context of migration regarding to Datatypes:
E.g. we had the following definition in our OAW xtext grammar:
String DataType:("string"|"integer"|"long"|...|"collection");
And changed to
DataType:("string"|"integer"|"long"|...|"collection");
e.g.
Dto :
'dto' name=ID '{'
properties+=DtoProperty*
'}';
Property:
'property' name=ID ':' type=[Type] (many?='[]')?;
DtoProperty:
'property' name=ID ':' type=DtoDataType (many?='[]')?;
DtoDataType:("string"|"long"|"integer");
Now we are not able to do a switch case with string on DataType Ref's:
e.g. the following doesn't work anymore
boolean isStringType(EntityAttribute this) :
// this.type points to a DataType
switch (this.type) {
case "string": true
case "text": true
default: false
};
How can I solve this problem? How can I get the value of a
Is there a documentation how to solve this kind of (common??) problems?
|
|
|
|
|
Re: Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58732 is a reply to message #58707] |
Wed, 15 July 2009 03:38   |
Eclipse User |
|
|
|
Hi Martin,
there seems to be a problem with the type inference. In your case,
DtoDataType has not been recognized as a data type rule. Could you
please file a bugzilla? Please try something like this instead as a
workaround:
grammar org.xtext.example.MyDsl1 with org.eclipse.xtext.common.Terminals
generate myDsl1 "http://www.xtext.org/example/MyDsl1"
// this line is new
import "http://www.eclipse.org/emf/2002/Ecore"
Model :
(dtos+=Dto)*;
Dto :
'dto' name=ID '{'
properties+=DtoProperty*
'}';
DtoProperty:
'property' name=ID ':' type=DtoDataType (many?='[]')?;
// the return statement is new
DtoDataType returns EString: ("string"|"long"|"integer");
Regards,
Sebastian
Am 15.07.2009 9:28 Uhr, schrieb Martin Kuhn:
>> Hi Martin,
>
>> I'm afraid I'm missing the point of your question. As far as I can
>> see, there will be no limitation for switch/case statements when you
>> use data type rules instead of the oAW's string rules.
>
> Hi Sebastian,
>
> thanks for answering and sorry for the example which was a little bit
> confusing (I took a piece of an existing project).
>
> My point is that I'm not able to access (at least with my knowledge) the
> concrete value of a DtoDataType ref (it sounds like a really simple
> problem :-( )
>
> Here is a complete example where I try to resolve the concrete type
> (DtoDataType im my Template) of a DtoProperty referenced in a Dto. This
> means war DtoDataType has a concrete property of my Dto
> (string,integer,long) but I'm not able to get the value.
> Remark -> the piece of code in the Extension part leads to an error (->
> in the switch block -> DtoDataType expected) which works in OAW xtext
> and which we have in use extensively
>
> XText grammar
> -------------
>
> Model :
> (dtos+=Dto)*;
>
> Dto :
> 'dto' name=ID '{'
> properties+=DtoProperty*
> '}';
>
> DtoProperty:
> 'property' name=ID ':' type=DtoDataType (many?='[]')?;
>
> DtoDataType:("string"|"long"|"integer");
>
>
>
> Model:
> ------
> dto PersonDto {
> property name: string
> property age: integer
> property salery: long
> }
>
> Template:
> ----------
> «IMPORT entities»;
>
> «EXTENSION templates::Extensions»
>
> «DEFINE main FOR Model-»
> «FILE "output.txt"-»
>
> «FOREACH this.dtos AS d-»
> DTO «d.name» «FOREACH d.properties AS p»
> «REM»Here I try to resolve the datatype (string,long,integer) -> I don't
> know how to get the value «ENDREM»
> Property «p.name» Type: «p.type» «p.type.toString()» «ENDFOREACH»
> «ENDFOREACH-»
> «ENDFILE-»
> «ENDDEFINE»
>
> Extension:
> ----------
> import entities;
>
> String getType(DtoDataType dtoType):
> switch(dtoType) {
> // THIS is now an ERROR -> DtoDataType expected
> case "string": "is a string"
> default: "nix wissen"
> } ;
>
|
|
|
|
|
|
|
|
Re: Conversion from oaw to tmf xtext - Access values of Datatype refs [message #59421 is a reply to message #58732] |
Thu, 16 July 2009 04:26  |
Eclipse User |
|
|
|
I've entered a corresponding bugzilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=283671
Sebastian Zarnekow schrieb:
> Hi Martin,
>
> there seems to be a problem with the type inference. In your case,
> DtoDataType has not been recognized as a data type rule. Could you
> please file a bugzilla? Please try something like this instead as a
> workaround:
>
> grammar org.xtext.example.MyDsl1 with org.eclipse.xtext.common.Terminals
>
> generate myDsl1 "http://www.xtext.org/example/MyDsl1"
> // this line is new
> import "http://www.eclipse.org/emf/2002/Ecore"
>
> Model :
> (dtos+=Dto)*;
>
> Dto :
> 'dto' name=ID '{'
> properties+=DtoProperty*
> '}';
>
> DtoProperty:
> 'property' name=ID ':' type=DtoDataType (many?='[]')?;
>
> // the return statement is new
> DtoDataType returns EString: ("string"|"long"|"integer");
>
>
> Regards,
> Sebastian
>
> Am 15.07.2009 9:28 Uhr, schrieb Martin Kuhn:
>>> Hi Martin,
>>
>>> I'm afraid I'm missing the point of your question. As far as I can
>>> see, there will be no limitation for switch/case statements when you
>>> use data type rules instead of the oAW's string rules.
>>
>> Hi Sebastian,
>>
>> thanks for answering and sorry for the example which was a little bit
>> confusing (I took a piece of an existing project).
>>
>> My point is that I'm not able to access (at least with my knowledge) the
>> concrete value of a DtoDataType ref (it sounds like a really simple
>> problem :-( )
>>
>> Here is a complete example where I try to resolve the concrete type
>> (DtoDataType im my Template) of a DtoProperty referenced in a Dto. This
>> means war DtoDataType has a concrete property of my Dto
>> (string,integer,long) but I'm not able to get the value.
>> Remark -> the piece of code in the Extension part leads to an error (->
>> in the switch block -> DtoDataType expected) which works in OAW xtext
>> and which we have in use extensively
>>
>> XText grammar
>> -------------
>>
>> Model :
>> (dtos+=Dto)*;
>>
>> Dto :
>> 'dto' name=ID '{'
>> properties+=DtoProperty*
>> '}';
>>
>> DtoProperty:
>> 'property' name=ID ':' type=DtoDataType (many?='[]')?;
>>
>> DtoDataType:("string"|"long"|"integer");
>>
>>
>>
>> Model:
>> ------
>> dto PersonDto {
>> property name: string
>> property age: integer
>> property salery: long
>> }
>>
>> Template:
>> ----------
>> «IMPORT entities»;
>>
>> «EXTENSION templates::Extensions»
>>
>> «DEFINE main FOR Model-»
>> «FILE "output.txt"-»
>>
>> «FOREACH this.dtos AS d-»
>> DTO «d.name» «FOREACH d.properties AS p»
>> «REM»Here I try to resolve the datatype (string,long,integer) -> I don't
>> know how to get the value «ENDREM»
>> Property «p.name» Type: «p.type» «p.type.toString()» «ENDFOREACH»
>> «ENDFOREACH-»
>> «ENDFILE-»
>> «ENDDEFINE»
>>
>> Extension:
>> ----------
>> import entities;
>>
>> String getType(DtoDataType dtoType):
>> switch(dtoType) {
>> // THIS is now an ERROR -> DtoDataType expected
>> case "string": "is a string"
>> default: "nix wissen"
>> } ;
>>
>
|
|
|
Powered by
FUDForum. Page generated in 0.05859 seconds