Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar problem (probably scoping)(conflict with naming)
grammar problem (probably scoping) [message #1067533] Tue, 09 July 2013 09:04 Go to next message
Andreas  Flügge is currently offline Andreas FlüggeFriend
Messages: 26
Registered: July 2009
Junior Member
Hello!

I've got following grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
                                      
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	importSection = XImportSection?
	(elements += AbstractElement)*;
 
PackageDeclaration:
	'package' name = QualifiedName '{'
		(elements += AbstractElement)*
	'}';
 
AbstractElement:
	PackageDeclaration | Entity;
 
Entity:
	'entity' name = ID ('extends' superType = JvmTypeReference)? '{'
		(features += Feature)*
	'}';
	
Feature:
	(type = JvmTypeReference) (name = ID) '{'
		(attributes += Attributes)
	'}';
	
Attributes:
	{Attributes}
	(attributeId = AttributeId)?
	(attributeName = AttributeName)?;
	
AttributeId:
	'id' '=' (id = STRING) ';';

AttributeName:
	'name' '=' (name = STRING) ';';


Everything works fine but with one exception:

You cannot name the feature 'id' or 'name' in conflict to the AttributeId and AttributeName rule.

The following source causes an error "no viable alternative at input 'id'" at line 4!

package de.test.mydsl {
	entity Person {
		
		Long id {
			id = "bla";
			name= "blu";			
		}
		
		String text {
			id = "bli";
			name = "ble";
		}
	}	
}


Is there someone who can explain how to solve this conflict?

Thanks in advance,
Andreas
Re: grammar problem (probably scoping) [message #1067540 is a reply to message #1067533] Tue, 09 July 2013 09:18 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

id is a keyword and cannot be used as an ID. You can escape it in the model (^id ="bla") or you can use a datatype rule allowing keywords as IDs.

Alex

edit: this post suggested escaping in the wrong place.
Long ^id {...
is the place where the keyword id is used illegally.


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

[Updated on: Tue, 09 July 2013 10:27]

Report message to a moderator

Re: grammar problem (probably scoping) [message #1067545 is a reply to message #1067540] Tue, 09 July 2013 09:45 Go to previous messageGo to next message
Andreas  Flügge is currently offline Andreas FlüggeFriend
Messages: 26
Registered: July 2009
Junior Member
Hello Alexander,

ok, 'id' is a bad example, but if you change 'id' to 'xyz':

AttributeId:
	'xyz' '=' (id = STRING) ';';


you cannot name the feature 'xyz' at all!!!

package de.test.mydsl {
	entity Person {
		
		Long xyz {
			xyz = "bla";
			name= "blu";			
		}
		
		String text {
			xyz = "bli";
			name = "ble";
		}
	}	
}


results in "no viable alternative at input 'xyz'" at line 4!

Regards,
Andreas
Re: grammar problem (probably scoping) [message #1067547 is a reply to message #1067545] Tue, 09 July 2013 09:54 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
AttributeId and AttributeName require id and name to be STRING rather than ID, so you'd have to put them in quotes.

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: grammar problem (probably scoping) [message #1067549 is a reply to message #1067547] Tue, 09 July 2013 10:03 Go to previous messageGo to next message
Andreas  Flügge is currently offline Andreas FlüggeFriend
Messages: 26
Registered: July 2009
Junior Member
I don't know if I understand it, can you give an short example?

Thank you,
Andreas
Re: grammar problem (probably scoping) [message #1067555 is a reply to message #1067549] Tue, 09 July 2013 10:17 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Sorry, I should start from scratch. The name attribute in your Feature rule requires an ID.
Long id or Long xyz work only if id or xyz are not keywords in the grammar, which they are in your examples. So you would have to write
Long ^id or Long ^xyz and it will work.

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: grammar problem (probably scoping) [message #1067558 is a reply to message #1067555] Tue, 09 July 2013 10:24 Go to previous message
Andreas  Flügge is currently offline Andreas FlüggeFriend
Messages: 26
Registered: July 2009
Junior Member
Ok, that's it!

Thank you very much,
Andreas
Previous Topic:Xtext project from ECore with abstract types
Next Topic:Questions about scoping
Goto Forum:
  


Current Time: Fri Apr 26 02:41:11 GMT 2024

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

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

Back to the top