Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » use of EOF
use of EOF [message #1743966] Wed, 21 September 2016 07:42 Go to next message
Nils B. is currently offline Nils B.Friend
Messages: 10
Registered: July 2016
Junior Member
Hello,

i want to use EOF in my grammar, but got the error: "mismatched input '<EOF>' expecting RULE_END".

i transferred the problem to the greetings grammar:

grammar org.xtext.example.mydsl.MyDsl 
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting hidden(WS):
	'Hello' name=ID '!' (NL|END);
	
terminal NL: (('\r'|'\n')+);
terminal END: EOF;
terminal ID  		: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal WS: (' '|'\t')+;


i want, that in the end of every statement is either a new line or the end of the file, because otherwise the line "Hello name! Hello name2!" would be valid.

Is there another/ right way to use EOF in this case?

Thanks for help
Re: use of EOF [message #1743974 is a reply to message #1743966] Wed, 21 September 2016 08:58 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Think somewhere in the documentation you will find an example for a comma-separated list-of-xxx,
looks like you can use this as a base for your NL-separated one:

'fields=' fields += Field? (',' fields+= Field)*
Re: use of EOF [message #1743980 is a reply to message #1743974] Wed, 21 September 2016 09:42 Go to previous messageGo to next message
Nils B. is currently offline Nils B.Friend
Messages: 10
Registered: July 2016
Junior Member
unfortunately i cannot use commas to separate, only new lines
Re: use of EOF [message #1743984 is a reply to message #1743980] Wed, 21 September 2016 09:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
well i think uli thought of something like+


Model:
(greetings+=Greeting (NL greetings+=Greeting)*)?;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: use of EOF [message #1744004 is a reply to message #1743984] Wed, 21 September 2016 12:02 Go to previous message
Nils B. is currently offline Nils B.Friend
Messages: 10
Registered: July 2016
Junior Member
i have more than one rule, which can appear in unsorted order, so i think to solve it this way could be difficult.

i solved my problem in the way, that i expect the new line at the beginning of the statement. this solved it, because in the top of the file, i have a header which does not depend on the new line.

Thanks for your help and thoughts
Previous Topic:Couldn't resolve reference to Grammar
Next Topic:cross-references without grammar
Goto Forum:
  


Current Time: Fri May 10 22:37:35 GMT 2024

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

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

Back to the top