|
|
|
Re: Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58732 is a reply to message #58707] |
Wed, 15 July 2009 07:38 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Sebastian Zarnekow![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=sebastian.zarnekow%40gmail.com) Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
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 08:26 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Sven Efftinge![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=sven.efftinge%40itemis.de) Messages: 1823 Registered: July 2009 |
Senior Member |
|
|
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.04174 seconds