0

I need to declare an integer array in a domain specific language using xtext.

PolyLine:
'polyline' color = Color '{'                    Line1
'points number' n = INT                         Line2
'x points'                                      Line3
'y ponts'                                       Line4
'}';

In above rule declaration, I need to get several x and y points which indicate some coordination (theirs number is equal to n property in line2). But I can't find any document that help me to answer my question "How I can declare a array in xtext"? Can somebody help please?

Azad
  • 407
  • 1
  • 9
  • 22

1 Answers1

0

I am not quite sure what your questions targets but you can have lists of things basically using the += operator

points+=INT+

(points+=INT ("," points+=INT)*)

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32
  • I dont understand this question since i dont understand which code you want to generate. f.points is a list of integers. – Christian Dietrich Apr 02 '14 at 18:42
  • I want to generate a method for this rule in java using xtend. Points is a list of integers in my DSL, but I expect, this list transforms to an array in the java class that will be generate later. Is it possible using Terminal rules or I should use xbase and try to handle this problem by choosing JVMTyeReference? – Azad Apr 02 '14 at 19:18
  • please give me a sample model and the corresponding output – Christian Dietrich Apr 03 '14 at 17:54
  • i just wanted to know a sample model and a sample java output. it is hard to give advice on how to generate without knowing what to generate – Christian Dietrich Apr 03 '14 at 18:47
  • so what about `def compile(PolyLine p) '''g.drawPolyline(new int[]{«p.xpoints.join(",")»},new int[]{«p.ypoints.join(",")»},«p.n»);'''` – Christian Dietrich Apr 03 '14 at 18:59
  • Thank you so much Christian.It works and it's exactly what I wanted. – Azad Apr 03 '14 at 19:17