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 15:33 Go to next message
Tom Mealey is currently offline Tom Mealey
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 11:12]

Report message to a moderator

Re: End of line grammar difficulty [message #1187730 is a reply to message #1186656] Fri, 15 November 2013 03:49 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1151
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 11:10 Go to previous message
Tom Mealey is currently offline Tom Mealey
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 11:11]

Report message to a moderator

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


Current Time: Mon Sep 01 10:05:40 EDT 2014

Powered by FUDForum. Page generated in 0.09504 seconds