[Xtext] Working with array with Xtext pre-defined Java types [message #666648] |
Thu, 21 April 2011 13:06 |
Andrea Santi Messages: 12 Registered: April 2011 |
Junior Member |
|
|
Hi all,
in my grammar I would like to re-use the Java types, so I'm following the istruction reported here . This solution seems not to work with arrays (ex. int[] java.util.Date[]).
I would like to have also support to array types, what is the best way for doing this suing the type support provided by xtext (I have to parse the '[]' and then handle the new type as an array?)?
Even good links to existing documentation will be fine. Indeed I'm having a look also here where it seems that different production are used and not only JvmType... the standard xtext documentation is really poor, a more comprehensive explanation will be really helpfull.
Many thanks.
EDIT: Same things witìh the generics.... are they supported by xtext?
[Updated on: Thu, 21 April 2011 13:21] Report message to a moderator
|
|
|
Re: [Xtext] Working with array with Xtext pre-defined Java types [message #666659 is a reply to message #666648] |
Thu, 21 April 2011 13:33 |
|
Hi,
isn't the cardinality something you should specify in your grammar? I'd do something like
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
elements+=Element*;
Element:
'element' name=ID 'mapsto' ref=TypeRef;
TypeRef:
type=[types::JvmType|FQN] (isArray?="[]")?
;
FQN: ID ("." ID)*;
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: [Xtext] Working with array with Xtext pre-defined Java types [message #666668 is a reply to message #666659] |
Thu, 21 April 2011 13:59 |
Andrea Santi Messages: 12 Registered: April 2011 |
Junior Member |
|
|
Hi, yes I can do in that way. So I will have the information about the type, plus the flag that says if that type is an array or not. But what about JvmArrayType that I just found in the xtext JavaVMTypes? What is this, when is supposed to be used?
PS. what about generics? Even for them you use a "trick" like the one used for the array? I was expecting that both arrays and generic were handled by the JavaVMTypes grammar, but maybe that is not the case.
Many thanks for the help.
EDIT: Probably are just problems related to my lack of knowledge about the use of JavaVMTypes. Does exists any good document/example that explains how to use it?
[Updated on: Thu, 21 April 2011 14:11] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03405 seconds