Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Consistent Datatype for values
Consistent Datatype for values [message #1779336] Fri, 05 January 2018 14:47 Go to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 37
Registered: December 2014
Member
Hello,

I would like to check for an "in" operator, that always consistent data types are included in the values:

e.g.

only Strings
in(attr,("A","B")



only numbers
in(attr,1,2.0)


The xtext grammar:
In:
	'in' '(' attribute=FIELD_VALUE ',' '(' values+=Literal (',' values+=Literal)* ')' ')';


Can I do that directly in the grammar?

Re: Consistent Datatype for values [message #1779337 is a reply to message #1779336] Fri, 05 January 2018 15:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5625
Registered: July 2009
Senior Member
Hi

You can but your users won't thank you. Every typo will be a syntax error. If instead you have a semantic validation, you can provide a much more informative warning and maybe even a quick fix. Subsequent maintainers won't thank you either since your grammar will have excessive complexity.

Regards

Ed Willink
Re: Consistent Datatype for values [message #1779347 is a reply to message #1779337] Fri, 05 January 2018 16:34 Go to previous messageGo to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 37
Registered: December 2014
Member
Hi,

thanks for the quick answer.

But i have no UI, so the User cannot use a quickfix ;).
Re: Consistent Datatype for values [message #1779360 is a reply to message #1779347] Fri, 05 January 2018 17:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11726
Registered: July 2009
Senior Member
well even then a simple validation with an error message like: "please use the same type" would be better than "parse error"
never do such things in the grammar


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Consistent Datatype for values [message #1779363 is a reply to message #1779360] Fri, 05 January 2018 17:44 Go to previous messageGo to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 37
Registered: December 2014
Member
Christian Dietrich wrote on Fri, 05 January 2018 17:27
well even then a simple validation with an error message like: "please use the same type" would be better than "parse error"
never do such things in the grammar


Okay thanks. Then i will do that in AbstractValidator, or?

[Updated on: Fri, 05 January 2018 17:47]

Report message to a moderator

Re: Consistent Datatype for values [message #1779364 is a reply to message #1779363] Fri, 05 January 2018 17:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11726
Registered: July 2009
Senior Member
you have already a MyDslValidator pregenerated. yes

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Consistent Datatype for values [message #1779365 is a reply to message #1779364] Fri, 05 January 2018 17:48 Go to previous messageGo to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 37
Registered: December 2014
Member
Christian Dietrich wrote on Fri, 05 January 2018 17:45
you have already a MyDslValidator pregenerated. yes


Okay thanks :)

Antoher related question. A attribute (like in Java) should always start with a character. My solution is:
terminal FIELD_VALUE:
	('A'..'Z' | 'a'..'z') ('A'..'Z' | 'a'..'z' | '0'..'9' | '.' | '_' | '-')*;


Is this ok? Or should i create a validation as well?

[Updated on: Fri, 05 January 2018 17:51]

Report message to a moderator

Re: Consistent Datatype for values [message #1779366 is a reply to message #1779365] Fri, 05 January 2018 17:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11726
Registered: July 2009
Senior Member
that's ok, depends on other places you use similar IDs.

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Consistent Datatype for values [message #1779368 is a reply to message #1779366] Fri, 05 January 2018 17:52 Go to previous message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 37
Registered: December 2014
Member
Christian Dietrich wrote on Fri, 05 January 2018 17:50
that's ok, depends on other places you use similar IDs.


Okay, then i will try to create a validation

EDIT: okay now i have the same issue like in my other thread all values are strings ;). So i cannot check the data type. First i have to fix this, before i can create a validation

[Updated on: Fri, 05 January 2018 18:08]

Report message to a moderator

Previous Topic:Connecting to a non-xtext language from Eclipse: Binding ResourceDescriptionStrategy
Next Topic:BIRT Pie Chart
Goto Forum:
  


Current Time: Mon Feb 19 14:51:16 GMT 2018

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

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