Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » extraneous input '}' expecting EOF
extraneous input '}' expecting EOF [message #892688] Fri, 29 June 2012 08:46 Go to next message
Andrew A is currently offline Andrew AFriend
Messages: 9
Registered: June 2012
Junior Member
I have a simple template language grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "url here"

Model:
	statements+=Statement*;
	
Statement: (Text | Var);

Var :  '${' name=ID '}';
	
Text: v=(ID | ANY_OTHER );


When I tried to create test.dsl file:
test ${megavar} !@#$%^
testing{}


Eclipse underlines the last "}" with the error message "extraneous input '}' expecting EOF".

I don't understand why. Could you explain this point, please?

[Updated on: Fri, 29 June 2012 08:46]

Report message to a moderator

Re: extraneous input '}' expecting EOF [message #892696 is a reply to message #892688] Fri, 29 June 2012 09:18 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

'}' is a keyword in your grammar and hence is not covered by ANY_OTHER.

Text: v=(ID| ANY_OTHER| '}');

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: extraneous input '}' expecting EOF [message #892699 is a reply to message #892688] Fri, 29 June 2012 09:22 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 430
Registered: July 2009
Location: Gothenburg
Senior Member
Hi!

ANY_OTHER is tricky. It means "any other character not mentioned anywhere else", but '}' is not such a character, it is already a grammar symbol.

If you change the definition of Var to end with '}$' (for example), you will see it works.

In practice, you don't really want to use ANY_OTHER except in special cases. Instead, specify the range of accepted characters. It may be longer to write, but it's more resilient to change.

regards,
Vlad

Re: extraneous input '}' expecting EOF [message #892860 is a reply to message #892699] Sat, 30 June 2012 16:28 Go to previous messageGo to next message
Andrew A is currently offline Andrew AFriend
Messages: 9
Registered: June 2012
Junior Member
Thanks, Alexander and Vlad.

this works:
Text: v=(ID| ANY_OTHER| '}');

but this don't:
Model:
	statements+=Statement*;

Statement: Var | Text | WsText ;

Text: val=(PUNCTUATION|IDENT);
	
Var: '${' name=IDENT '}';

WsText: val=WS;
	
terminal IDENT: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;

terminal WS: (' ' | '\r' | '\n' | '\t')+;

terminal PUNCTUATION: ('(' | ')' | '.' | ',' | '=' | '{' | '}' | '*' | ';' | '+' | '-')*;


Should I update my Text rule every time I change keywords?
Re: extraneous input '}' expecting EOF [message #892864 is a reply to message #892860] Sat, 30 June 2012 19:00 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

you have overlapping definitions. '}' is covered by the keyword in the Var-rule and the terminal Punctuation rule. The lexer will produce exactly one token (the keyword) which you do not allow in in the Text-rule.

The simplest way could be to make PUNCTUATION a datatype rule instead of a terminal rule.

Punctuation: ('(' | ')' | '.' | ',' | '=' | '{' | '}' | '*' | ';' | '+' | '-')+;

In this case the single elements will be tokenized as sequence of single keywords rather than as single punctuation token.

Alex
Previous Topic:How xtext Lexer and Parser works?
Next Topic:How to write a DSL which is able to add "things" to a cross reference?
Goto Forum:
  


Current Time: Thu Feb 20 13:41:38 GMT 2020

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

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

Back to the top