Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » End of line grammar difficulty [SOLVED]
End of line grammar difficulty [SOLVED] [message #1186656] Thu, 14 November 2013 20:33 Go to next message
Tom Mealey is currently offline Tom MealeyFriend
Messages: 7
Registered: October 2013
Junior Member
Hello All,

I have a simple language made up of one line statements, necessarily separated by a newline. Here are the relevant segments of the grammar:

Model:
	{Model}
	EOL*
	(includes += Include)*
	(elements += TopLevelElement)*
;

Include:
	'#include' importURI=STRING EOL+
;

TopLevelElement:
	(Macro | Instruction | Label) EOL+
;

EOL:
	NEWLINE | SL_COMMENT;

terminal SL_COMMENT:
	'//' !('\n'|'\r')* ('\r'? '\n')?;
	
terminal NEWLINE:
	('\r'? '\n');


My grammar implementation almost gives me the behavior I want, but the problem is that it requires an EOL character after the last TopLevelElement. I'd like to be able to not have to enter a newline or comment at the end of every document. Is there a way I can revise my grammar to achieve this?

Thanks,
Tom

[Updated on: Mon, 18 November 2013 16:12]

Report message to a moderator

Re: End of line grammar difficulty [message #1187730 is a reply to message #1186656] Fri, 15 November 2013 08:49 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

have you considered *not* making the line breaks explicit? You could simply disallow multi line comments and line breaks in Strings.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: End of line grammar difficulty [message #1194633 is a reply to message #1187730] Mon, 18 November 2013 16:10 Go to previous message
Tom Mealey is currently offline Tom MealeyFriend
Messages: 7
Registered: October 2013
Junior Member
I was able to revise my grammar and achieve the behavior I was looking for. For anyone curious, here is what the grammar looks like now:

Model:
	{Model}
	EOL*
	(includes += Include EOL+)*
	(elements += TopLevelElement EOL+)*
	(elements += TopLevelElement)?
;

Include:
	'#include' importURI=STRING
;

TopLevelElement:
	(Macro | Instruction | Label)
;

EOL:
	NEWLINE | SL_COMMENT;

terminal SL_COMMENT:
	'//' !('\n'|'\r')* ('\r'? '\n')?;
	
terminal NEWLINE:
	('\r'? '\n');

[Updated on: Mon, 18 November 2013 16:11]

Report message to a moderator

Previous Topic:Regular Expression language
Next Topic:Outline View In Xtext
Goto Forum:
  


Current Time: Thu Mar 28 17:06:13 GMT 2024

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

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

Back to the top