Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Keyword with whitespace
Keyword with whitespace [message #1836212] Thu, 24 December 2020 11:07 Go to next message
Alex Gor is currently offline Alex GorFriend
Messages: 157
Registered: November 2014
Location: Russia
Senior Member
Dears

XText is able to support keyword with whitespaces

In case I write in grammar something like :
MY_KEYWORD:
	"KeywordStart KeywordSecond"
;


Xtext suggests me to rewrite as

MY_KEYWORD:
	"KeywordStart"  "KeywordSecond"
;


But seems to me it is not fully corresponded

Thank you in advance
Re: Keyword with whitespace [message #1836230 is a reply to message #1836212] Fri, 25 December 2020 07:27 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
I think it is because the parser
treats multiple whitespace characters as one.
So the suggested one is more meaninful.

Happy new year, Uli
Re: Keyword with whitespace [message #1836234 is a reply to message #1836212] Fri, 25 December 2020 10:47 Go to previous messageGo to next message
Alex Gor is currently offline Alex GorFriend
Messages: 157
Registered: November 2014
Location: Russia
Senior Member
There is more common question. Lexer and parser take whitespace into account as delimiter and remove it .

So if we using xtext as platform can we create a grammar where keyword will contains whitespace
Re: Keyword with whitespace [message #1836237 is a reply to message #1836234] Fri, 25 December 2020 15:40 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6993
Registered: July 2009
Senior Member
Hi

If you really really want precise sequences of whitespace in keywords you can probably do it, but make sure that you do not inherit the default hidden WS and beware that you will have to manually handle token separation yourself.

If you really want arbitrary whitespace in keywords you may choose to use a datatype rule to treat the compound letters and whitespace as a production. You will still need to handle all WS explicitly.

If there are a few multi-word keywords then you can simply specify e.g. 'abstract' 'static' in your grammar and work as normal. More likely the multiples have subtle semantics and you should sit back and reconsider what made you think you ever wanted whitespace in keywords in the first place.

Happy Xmas

Ed Willink
Previous Topic:ID and Fully Qualified name problem
Next Topic:Incremental updates on editor models
Goto Forum:
  


Current Time: Sat Jan 23 15:37:39 GMT 2021

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

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

Back to the top