Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross Referencing to objects containing white spaces(I would like to know how I can use a cross reference to a former declared object in my language that contains white spaces.)
Cross Referencing to objects containing white spaces [message #731522] Sat, 01 October 2011 15:14 Go to next message
Robert Walter is currently offline Robert WalterFriend
Messages: 29
Registered: July 2011
Junior Member
Hi everyone,

I try to figure out how I can use cross references to refer to objects that contain white spaces. An example model could look like this:

-----------------
Persons: John Doe, Patrick Stewart, Maryl Streep.

John Doe once said "I don't like my name."
Patrick Stewart once said "Resistance is futile."
-----------------

Where I would like to define the "Persons" at the beginning and then cross-reference them in the lines below. I tried different things with "hidden(WS)" in my grammar declaration, but with no success. My current attempt looks like this

Persons:
	"Persons" ":" firstPerson=Person ("," furtherPersons+=Person)* '.'
;

Person hidden(WS):
	firstName=ID (lastNames+=ID)*
;

PersonString returns ecore::EString:
	ID (ID)*
;
	
	
Line:
    person=[Person|PersonString] struff=Stuff 
;

Stuff:
	"..."
;


But it does not work, since the references are not resolved correctly (as the error message states.
Any suggestions? Thank you!
Re: Cross Referencing to objects containing white spaces [message #731524 is a reply to message #731522] Sat, 01 October 2011 15:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

did you add a custom iqualifiednamerprovider?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross Referencing to objects containing white spaces [message #731537 is a reply to message #731524] Sat, 01 October 2011 16:03 Go to previous messageGo to next message
Robert Walter is currently offline Robert WalterFriend
Messages: 29
Registered: July 2011
Junior Member
You guessed it: No! But if this is the only way to do it, I guess I need to take a look at the interface.
Re: Cross Referencing to objects containing white spaces [message #731538 is a reply to message #731537] Sat, 01 October 2011 16:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

the qualified name is the name objects are exported with and thus are referenceable
your persons have the QualifiedName null (they have no name attribute) )and are not referenceable at all.

package org.xtext.example.mydsl;

import org.apache.commons.lang.StringUtils;
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.xtext.example.mydsl.myDsl.Person;

public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	QualifiedName qualifiedName(Person p) {
		return QualifiedName.create(p.getFirstName() + " " +  StringUtils.join(p.getLastNames(), " "));
	}

}


public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyQNP.class;
	}
	


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 01 October 2011 16:06]

Report message to a moderator

Re: Cross Referencing to objects containing white spaces [message #731543 is a reply to message #731538] Sat, 01 October 2011 16:31 Go to previous message
Robert Walter is currently offline Robert WalterFriend
Messages: 29
Registered: July 2011
Junior Member
Hi Christian,

very kind of you to provide me the implementation. I'm not that familiar with Guice's internals, but it is always great to see how easy it is to configure an application. Works just great! Thank you.

Robert
Previous Topic:Changing XBase syntax
Next Topic:Referencing models defined in files outside of eclipse
Goto Forum:
  


Current Time: Tue Apr 16 11:45:13 GMT 2024

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

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

Back to the top