Skip to main content



      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 10:44 Go to next message
Eclipse UserFriend
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 10:52 Go to previous messageGo to next message
Eclipse UserFriend
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"
Re: Define a limited string consisting out of figures/digits only [message #1835322 is a reply to message #1835318] Mon, 30 November 2020 11:08 Go to previous messageGo to next message
Eclipse UserFriend
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 11:09] by Moderator

Re: Define a limited string consisting out of figures/digits only [message #1835324 is a reply to message #1835322] Mon, 30 November 2020 11:29 Go to previous message
Eclipse UserFriend
the value converter is a impl feature not a grammar feature.
see DefaultTerminalConverters for examples
Previous Topic:Xtext / Xtend 2.24 release
Next Topic:Redundant usage of =current
Goto Forum:
  


Current Time: Thu May 15 15:21:17 EDT 2025

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

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

Back to the top