Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Semicolon optional at end of line
Semicolon optional at end of line [message #1806908] Fri, 17 May 2019 12:20 Go to next message
Lutz Wrage is currently offline Lutz WrageFriend
Messages: 144
Registered: July 2009
Senior Member
I would like to define a language that uses semicolons to separate statements form each other. However, I want semicolons optional at the end of a line only. If two statements (or more) are on the same line the semicolon should be required between statement 1 and 2, but not after statement 2. (Line breaks should still be allowed everywhere where whitespace is allowed.)

For example, with the trivial greeting language:

Valid:
Hello X!;
Hello Y!
Hello Z!

Hello A!; Hello B!; Hello C!

Hello K
!; Hello L!

Hello M!; Hello
N!


Invalid:
Hello X! Hello Y!
Hello A! Hello B!;


How do I do this in Xtext? It seems like I need to treat '\n' as non whitespace, but then I'd have to insert explicit '\n' everywhere in the grammar. Is there an easier way to do this?
Re: Semicolon optional at end of line [message #1806909 is a reply to message #1806908] Fri, 17 May 2019 12:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13159
Registered: July 2009
Senior Member
what about allow it everywhere in grammar and validate that it is used at line end only?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Semicolon optional at end of line [message #1806919 is a reply to message #1806909] Fri, 17 May 2019 15:43 Go to previous messageGo to next message
Lutz Wrage is currently offline Lutz WrageFriend
Messages: 144
Registered: July 2009
Senior Member
I guess you mean: Make it optional everywhere and validate that it's there when not at a line end. That would match what I want.
That may be an option but looks a bit tedious because the validation would need to look at the node model to check for end of line. I was hoping there was something that could be done in the grammar.
Re: Semicolon optional at end of line [message #1806923 is a reply to message #1806919] Fri, 17 May 2019 15:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13159
Registered: July 2009
Senior Member
explicit whitespace in Xtext grammars is very slugggish and tedious so i personally would avoid it at all cost

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:Completeness of the .ecore generated by Xtext
Next Topic:Whitespace validator in XText
Goto Forum:
  


Current Time: Fri Oct 18 00:01:54 GMT 2019

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

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

Back to the top