Couldn't resolve reference to ... [message #1753036] |
Wed, 01 February 2017 10:13 |
chris yo Messages: 146 Registered: February 2013 |
Senior Member |
|
|
I have this 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| Test)*;
Greeting:
'Hello' test=[Test] 'age' age=INT '!';
Test:
'Bye' sName=ID '!' 'see' 'you' date=ID ';'
;
But I get an error with this configuration:
Hello sample age 2!
Bye sample ! see you sept;
The error is:
Description Resource Path Location Type
Couldn't resolve reference to Test 'sample'. test.mydsl /sample line: 1 /sample/test.mydsl MyDsl Problem
I need to use the variable sName, any hints how to configure xtext to accept sName instead of name?
[Updated on: Wed, 01 February 2017 10:14] Report message to a moderator
|
|
|
|
Re: Couldn't resolve reference to ... [message #1753116 is a reply to message #1753039] |
Thu, 02 February 2017 02:42 |
chris yo Messages: 146 Registered: February 2013 |
Senior Member |
|
|
Hi Christian,
I am still getting the same error.
package org.xtext.example.mydsl;
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.xtext.example.mydsl.myDsl.Greeting;
import org.xtext.example.mydsl.myDsl.Test;
public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {
QualifiedName qualifiedName(Greeting e) {
Test p = (Test) e.eContainer();
return QualifiedName.create(p.getSName(), e.getSample().getSName());
}
}
My xtext is this:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greetings+=(Greeting| Test)*;
Greeting:
'Hello' sample=[Test] 'age' age=INT '!';
Test:
'Bye' sName=ID '!' 'see' 'you' date=ID ';'
;
I have also modified the Runtime Module.
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
override Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return MyDslQNP;
}
}
And I have added the scopeProvider in my mwe workflow.
scopeProvider = scoping.ImportNamespacesScopingFragment2 {
}
Am I missing something?
[Updated on: Thu, 02 February 2017 03:54] Report message to a moderator
|
|
|
|
|
Re: Couldn't resolve reference to ... [message #1753132 is a reply to message #1753128] |
Thu, 02 February 2017 07:07 |
chris yo Messages: 146 Registered: February 2013 |
Senior Member |
|
|
Thanks, it works perfectly now. But I am encountering some problem.
There are some entries that are added only during generator part as the user does not need to specify it.
Hello admin age 99!
Hello sample age 2!
Bye sample ! see you sept;
I manually add the "admin" during generator part by default. However, this gives me an error "Couldn't resolve reference to Test 'admin'". How can I make xtext aware that admin is a valid reference? Is there a way to add it before the references are checked?
[Updated on: Thu, 02 February 2017 07:40] Report message to a moderator
|
|
|
|
Re: Couldn't resolve reference to ... [message #1753152 is a reply to message #1753148] |
Thu, 02 February 2017 09:20 |
|
there are multiple options that depend on your scenario
- pack the admin definition and put it as jar to the classpath (if the model project is a java project)
- adapt e.g. global scope provder and add the libary defintions there
(both options have up and downsides and if possible/feasible id go the first way
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: Couldn't resolve reference to ... [message #1753187 is a reply to message #1753036] |
Thu, 02 February 2017 14:41 |
chris yo Messages: 146 Registered: February 2013 |
Senior Member |
|
|
It works now! I had encountered another error though.
I have to different files:
File 1 is in d:\test\sample\a\trial1
It contains this:
File 2 is in d:\test\sample\b\trial2
Bye sample! See you sept;
I am getting an error because the sample reference couldn't be resolved.
Do I need to set something in my myDslQNP class? I followed the qualifiedname method that neeraj has given as I have more than one grammar to cross-reference.
[Updated on: Thu, 02 February 2017 15:15] Report message to a moderator
|
|
|
|
Re: Couldn't resolve reference to ... [message #1753249 is a reply to message #1753192] |
Fri, 03 February 2017 02:36 |
chris yo Messages: 146 Registered: February 2013 |
Senior Member |
|
|
Hi Christian,
I am using a Runnable JAR file to read the files. I export it as Runnable JAR and copy required libraries to subfolder next to the generated JAR. I run it as:
java -jar test.jar ..\a\trial1\test1.mydsl ..\b\trial2\test2.mydsl
How can I make it "wait" for all files to be processed before checking for the cross-references? I have no problem if I am running an Eclipse application and do the configurations there with the steps you mentioned.
[Updated on: Fri, 03 February 2017 03:29] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04498 seconds