Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Whitespace validator in XText (Resolving the excessive whitespace at the end of a model or a parser rule by raising a validator)
Whitespace validator in XText [message #1806836] Thu, 16 May 2019 04:22 Go to next message
Vishal Balaji is currently offline Vishal BalajiFriend
Messages: 4
Registered: March 2019
Junior Member
Hi,
I am currently using XText 2.17. My issue is that I have to validate the excess whitespace at the end of a parser rule.

My current XText code is as below:
--------------------------------------------------------------------------------
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden()

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
greetings+=Greeting* ;

Greeting hidden(WS):
'Hello' name=ID WS*'!';

--------------------------------------------------------------------------------
Output Expected:

A warning using validator for :
Hello XText !

But instead it works fine.
The issue is I don't want to use hidden and should parse white space with a warning. The current code doesn't allow me to do it. It just allows me to write with as many whitespace as possible. Thanks in advance.

Note: The space which I gave between XText and ! is hidden in the message.
Re: Whitespace validator in XText [message #1806837 is a reply to message #1806836] Thu, 16 May 2019 04:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13149
Registered: July 2009
Senior Member
Hi, is there any reason not to use the nodemodel


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Whitespace validator in XText [message #1806959 is a reply to message #1806837] Mon, 20 May 2019 05:27 Go to previous messageGo to next message
Vishal Balaji is currently offline Vishal BalajiFriend
Messages: 4
Registered: March 2019
Junior Member
Hi Dietrich,
Its really delightful to see you responding to my post. I am a beginner in XText, hence I can't get to your point of using nodemodel. Also I found in web that even Formatter will be useful to implement my requirement of White space validation . May I have your guidelines in this case.

Thanks,
Vishal.
Re: Whitespace validator in XText [message #1806960 is a reply to message #1806959] Mon, 20 May 2019 06:15 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13149
Registered: July 2009
Senior Member
in xtext there is not a AST only but a parse tree too.
this is mapped to the so called node model
which contains the hidden tokens as well.

the class NodeModelUtils might be a good entry point to start and research


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Semicolon optional at end of line
Next Topic:Deprecating keywords
Goto Forum:
  


Current Time: Tue Oct 15 03:31:35 GMT 2019

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

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

Back to the top