Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Define a limited string consisting out of figures/digits only
Define a limited string consisting out of figures/digits only [message #1835316] Mon, 30 November 2020 15:44 Go to next message
Nils K. is currently offline Nils K.Friend
Messages: 13
Registered: November 2020
Junior Member
Hello,

I was asked to post the question here.

I want to define a string in my grammar that consists of figures only and is limited in length. In best case I want to verify further rules and if that figure matches a certain type (e.g. matches type long or is within the range of 100 to 2000). How can I do that in xtext?

I thought about something like the following rule, but to be honest I have still issues defining that grammar for all requirements here. Hints? Ideas?

terminal FIGURESTRING returns ecore::EString: '"' ('0'..'9')* '"' | "'" ('0'..'9')* "'";
Re: Define a limited string consisting out of figures/digits only [message #1835318 is a reply to message #1835316] Mon, 30 November 2020 15:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14025
Registered: July 2009
Senior Member
why not doing this in a semantic validation or value converter.
both will allow you to get much better error messages
than "no viable alt at x" or "expected x but got y"


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Define a limited string consisting out of figures/digits only [message #1835322 is a reply to message #1835318] Mon, 30 November 2020 16:08 Go to previous messageGo to next message
Nils K. is currently offline Nils K.Friend
Messages: 13
Registered: November 2020
Junior Member
Well, I'm new to xtend so I don't know most of its features yet.

Unfortunately, I'm limited on defining some sort of type, since other parts in the source code of the generator require me to provide it.

Right now, it is working fine with general strings except for the required rules for those numbers that I'd like to add by defining my own string type as shown above.

how can i integrate your mentioned converter in the code line above? I don't see where I am in need of a converter here and just need a simple rule permitting figures with a range for that string only.


[Updated on: Mon, 30 November 2020 16:09]

Report message to a moderator

Re: Define a limited string consisting out of figures/digits only [message #1835324 is a reply to message #1835322] Mon, 30 November 2020 16:29 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14025
Registered: July 2009
Senior Member
the value converter is a impl feature not a grammar feature.
see DefaultTerminalConverters for examples


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext / Xtend 2.24 release
Next Topic:Redundant usage of =current
Goto Forum:
  


Current Time: Tue Jul 27 16:18:44 GMT 2021

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

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

Back to the top