Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Conversion from oaw to tmf xtext - Access values of Datatype refs
Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58657] Wed, 15 July 2009 06:44 Go to next message
Martin Kuhn is currently offline Martin KuhnFriend
Messages: 49
Registered: July 2009
Member
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 #58681 is a reply to message #58657] Wed, 15 July 2009 06:51 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
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.

Consider the following grammar:

Model:
"type" "=" type = Datatype;

Datatype: "string" | "integer";

and this input:

type = string

The meta model for your grammar will be

eClass Model {
eAttribute 'type': String;
}

As you can see, type is a simple string attribute, thus any operation on
strings can be performed.

Did I get your question wrong? What was your actual problem. I cannot
find an EntityAttribute in your grammar snippet nor do can I find
(cross) references to data types.

Regards,
Sebastian

Am 15.07.2009 8:44 Uhr, schrieb Martin Kuhn:
> 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 #58707 is a reply to message #58681] Wed, 15 July 2009 07:28 Go to previous messageGo to next message
Martin Kuhn is currently offline Martin KuhnFriend
Messages: 49
Registered: July 2009
Member
> 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 #58732 is a reply to message #58707] Wed, 15 July 2009 07:38 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
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 #58756 is a reply to message #58732] Wed, 15 July 2009 08:07 Go to previous messageGo to next message
Martin Kuhn is currently offline Martin KuhnFriend
Messages: 49
Registered: July 2009
Member
Sebastian,

I changed the def to:

DtoDataType returns EString: ("string"|"long"|"integer");

But I'm still not available to get the type in my template (the «p.type»
leads to NO output):

Property «p.name» Type: «p.type»


And in my Extension I get the error "EString expected" what it is
understandable but different from OAW behaviour (how can I fix this?)

String getType(DtoProperty dtoProperty):
switch(dtoProperty.type) {
case "string": "is a string"
default: "nix wissen"
}
;
Re: Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58806 is a reply to message #58756] Wed, 15 July 2009 08:39 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Martin,

did you add the import of the ecore meta model, too?

// this line is new
import "http://www.eclipse.org/emf/2002/Ecore"

Regards,
Sebastian

Am 15.07.2009 10:07 Uhr, schrieb Martin Kuhn:
> Sebastian,
>
> I changed the def to:
>
> DtoDataType returns EString: ("string"|"long"|"integer");
>
> But I'm still not available to get the type in my template (the «p.type»
> leads to NO output):
>
> Property «p.name» Type: «p.type»
>
>
> And in my Extension I get the error "EString expected" what it is
> understandable but different from OAW behaviour (how can I fix this?)
>
> String getType(DtoProperty dtoProperty):
> switch(dtoProperty.type) {
> case "string": "is a string"
> default: "nix wissen"
> } ;
>
>
>
>
Re: Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58880 is a reply to message #58806] Wed, 15 July 2009 09:05 Go to previous messageGo to next message
Martin Kuhn is currently offline Martin KuhnFriend
Messages: 49
Registered: July 2009
Member
Sebastian Zarnekow wrote:

> Martin,

> did you add the import of the ecore meta model, too?

> // this line is new
> import "http://www.eclipse.org/emf/2002/Ecore"

Sebastian,

where do I have to place the import?

When I try to import "http://www.eclipse.org/emf/2002/Ecore" in my model I
get an error "Imported resource can not be found"
Re: Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58929 is a reply to message #58880] Wed, 15 July 2009 09:35 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Martin,

please have a second look at one of my previous answers:

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" // <-- it is here!!!

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 11:05 Uhr, schrieb Martin Kuhn:
> Sebastian Zarnekow wrote:
>
>> Martin,
>
>> did you add the import of the ecore meta model, too?
>
>> // this line is new
>> import "http://www.eclipse.org/emf/2002/Ecore"
>
> Sebastian,
>
> where do I have to place the import?
>
> When I try to import "http://www.eclipse.org/emf/2002/Ecore" in my model
> I get an error "Imported resource can not be found"
>
>
Re: Conversion from oaw to tmf xtext - Access values of Datatype refs [message #58954 is a reply to message #58929] Wed, 15 July 2009 09:47 Go to previous messageGo to next message
Martin Kuhn is currently offline Martin KuhnFriend
Messages: 49
Registered: July 2009
Member
Sebastian,

yeah it works. Thank you very much.

Regards,
Martin

> Hi Martin,

> please have a second look at one of my previous answers:

> 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" // <-- it is here!!!

> 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 11:05 Uhr, schrieb Martin Kuhn:
>> Sebastian Zarnekow wrote:
>>
>>> Martin,
>>
>>> did you add the import of the ecore meta model, too?
>>
>>> // this line is new
>>> import "http://www.eclipse.org/emf/2002/Ecore"
>>
>> Sebastian,
>>
>> where do I have to place the import?
>>
>> When I try to import "http://www.eclipse.org/emf/2002/Ecore" in my model
>> I get an error "Imported resource can not be found"
>>
>>
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
Sven Efftinge is currently offline Sven EfftingeFriend
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"
>> } ;
>>
>
Previous Topic:[XText] Cross Reference - Custom
Next Topic:Using xtext for comprehensive languages
Goto Forum:
  


Current Time: Sun Jun 30 13:49:04 GMT 2024

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

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

Back to the top