0

i have to make a type curve that is a curve plot , the data is given by a CSV file (The interpreter is who read the data file). i have two type of values , x-axis, time (i think INT:INT) minutes:seconds format ; and y-axis voltage ( double ) . My grammar datatypes are the following :

Model:
elements+=Element*;

Element:
     DataType /* | Operation | Control*/ ;

DataType : 
     Text | Real 
;
Text: 
    ("String" | "Text") name=ID (value=STRING)?
;
Double returns ecore::EDouble:
     INT ('.' INT)?
;
Real: 
     ("Double" | "Real") name=ID (value=Double)?
;

I was traying to make a map in my grammar with this format : Curve(Double voltage,time INT:INT) but i dont know why it doesnt work . what do you think guys ? should i define a new type for the type time ? or how make the map properly? Thanks for your time

   CurveCollection : 
        'Curve['keys+=[Real]*','values+=Time*']'
;
 Time: 
     INT':'INT
 ;

I tried to define the structure , but i dont know if is going to work like to arrays of (keys , values ) like a Map in java

Aikas
  • 67
  • 2
  • 7
  • can you please give a complete sample grammar that does not work – Christian Dietrich Mar 29 '17 at 07:04
  • The given example contains code that is commented out and the spacing is off. Cleaning it up would make the code more clear and help people answer your question. Another thing is that Text and Real have the same structure, just the type of initial value change. I would check this type consistency through typesystem rules, not enforcing that in the grammar because it would lead to confusing error messages – Federico Tomassetti Mar 29 '17 at 07:33
  • @ChristianDietrich i typed the code i was traying , but i dont know if is going to work like i expect – Aikas Mar 29 '17 at 10:54
  • @FedericoTomassetti Thanks for the suggestion i'll try to make it more clear . On the other hand with Text and Real i try to make differents variables definitions , one for String and the other for double , i dont understand where is the problem with the consistency . maybe is there another better way to defining variables ? Thanks ^^ – Aikas Mar 29 '17 at 10:58
  • i still dont get the problem you have with time. what is bad about `Time: INT':'INT;`. maybe the concept you are looking for is `IValueConverter` – Christian Dietrich Mar 29 '17 at 11:25
  • @ChristianDietrich My main problem is that you can give the same name of a datatype even decrare the same . For example : Real n Real n Curve[n n ,4:4 5:5] I dont know why i can do that , only can exist one n :S – Aikas Mar 30 '17 at 15:43
  • what do you mean by you cant? what prevents you from doing so? what are your scoping rules? – Christian Dietrich Mar 30 '17 at 15:52
  • @ChristianDietrich Because i need that only exist one with the same name , and with my rules you can have many with the same name . When i try to put cardinality to the types definition , i have a lot of errors when i generate the source . What am i trying to get is a array of reals or other type but in the array the names cant be same . Sorry for my bad explianing and thank you so much for the help – Aikas Mar 30 '17 at 17:01
  • so your question is: how can i prevent the user for modeling multiple elements with the same name? – Christian Dietrich Mar 30 '17 at 17:02
  • @ChristianDietrich yes, and in the Curve you cant repeate elements in the time , because you cant have two diferents values in the same time – Aikas Mar 30 '17 at 17:08

1 Answers1

1

you can enable a default unique name validation by uncommenting in and rerunning the language workflow

validator = {
    composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}

alternatively you can implement a own unique name validation in <YourDsl>Validator

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32
  • Thank you so much ,that solution solves my problem , i was trying to do through the syntax of my grammar and i was getting a lot of errors and problems , your solution worked perfectly , thank you. – Aikas Mar 30 '17 at 17:23