Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Keyword with whitespace
Keyword with whitespace [message #1836212] Thu, 24 December 2020 06:07 Go to next message
Eclipse UserFriend
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 02:27 Go to previous messageGo to next message
Eclipse UserFriend
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 05:47 Go to previous messageGo to next message
Eclipse UserFriend
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 10:40 Go to previous message
Eclipse UserFriend
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: Sun Sep 21 18:41:41 EDT 2025

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

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

Back to the top