Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with grammar
Problem with grammar [message #769866] Thu, 22 December 2011 20:09 Go to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi,

I have the next grammar.

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

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'h' h=Hello
	'w' w=World
	'Hello' hello=[Hello]'-'
;

Hello:
	name=ID
;

World:
	name=Name
;

terminal ID  		: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal Name  		: '^'?('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'-'|'0'..'9')*;


It gives the problem " mismatched input 'hello-' expecting RULE_ID " when I write:

h hello
w a-b
Hello hello-    


However, it is ok if I write white spaces between [Hello] and '-' :

h hello
w a-b
Hello hello -   


Of course, this issue disappear If the '-' charater is changed for another character in the Name terminal rule.

I have no idea of what to do to solve this.

Thanks!
Re: Problem with grammar [message #769874 is a reply to message #769866] Thu, 22 December 2011 20:33 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

the problem is you name rule => xyz- will be always recognized as a name
=> you have to workaround this e.g. by using the - keyword in a datatype rule

e.g.

Model:
	greetings+=Greeting*;
	
Greeting:
	'h' h=Hello
	'w' w=World
	'Hello' hello=[Hello|ID1]'-'
;

Hello:
	name=ID1
;

World:
	name=Name
;

terminal ID  		: '^'?('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*;

ID1: (ID|'_')+;

Name: ID (ID|'_')*;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Debugging model post processing
Next Topic:xText for an XML-Based DSL
Goto Forum:
  


Current Time: Fri Mar 29 09:52:21 GMT 2024

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

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

Back to the top