Skip to main content



      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
Eclipse UserFriend
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] by 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
Eclipse UserFriend
Hi,

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

Alex
Re: End of line grammar difficulty [message #1194633 is a reply to message #1187730] Mon, 18 November 2013 11:10 Go to previous message
Eclipse UserFriend
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] by Moderator

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


Current Time: Wed Jul 23 14:37:43 EDT 2025

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

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

Back to the top