|
Re: Xtext Crossreference shadowing ID [message #902702 is a reply to message #902688] |
Sun, 19 August 2012 23:25 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
On 2012-19-08 18:08, paolo pinkel wrote:
> NonLiteral: name=[glaSpecs::TokenName] | ID;
Seems to be the problem - remember that [glaSpecs::TokenName] really is
short hand for [glaSpecs::TokenName | ID] - which reads "if you see an
ID, this is a reference to a glaSpecs::TokenName with a name equal to
the ID".
Clearly, your construct is ambiguous, the second part "| ID" is never
reached. Your "NonLiteral" can't both be a reference to something via
ID, and have a name that is an ID at the same time. How to solve this
depends on what you want to do. If you just remove the "| ID" - the
grammar will naturally accept an ID, if it can't find what it is
referencing, your model will have an unresolved reference.
Some other observations:
Secondly, it is not so good to use "name" as the name of a feature to a
reference, as "name" is the default primary key for the default linking.
Also noticed that you are using terminals for operators - that is
generally not a good idea - the lexer is greedy, and you may need to
turn on backtracking in the lexer. (There are probably other unwanted
things that happens). i.e. suggest that you change use or say
REP_OPERATOR to simply ('*' | '-'). As an example, your ALT_OPERATOR
accepts '/', and it has higher precedence than DEL_OPERATOR '//'. My
guess is that you will see to ALT_OPERATOR tokens if input is "//". If
you change the order (ALT_OPERATOR first), you will instead get an error
when input is "/" because the lexer wants the next char to be a "//" to
satisfy ALT_OPERATOR. If you instead use keywords, this is automatically
sorted out for you. (You have the same issue with '|' and '||')
You have a P_STRING terminal for your type of string. Since you are also
overriding the default terminals, you may run into some surprises.
Since P_STRING has higher precedence, you will get P_STRING instances
for single quoted strings, and STRING for double-quoted strings. The set
of escapable special characters is different in P_STRING (do you have a
converter?).
Hope that helps.
Regards
- henrik
|
|
|
Re: Xtext Crossreference shadowing ID [message #906824 is a reply to message #902688] |
Sun, 02 September 2012 17:38 |
paolo pinkel Messages: 10 Registered: July 2012 |
Junior Member |
|
|
Thank you for your reply, I didn't realizie someone answered here, thats why i am responding so late.
Thanks for the other observations I think this shows me that I still lack some basics of xtext and I am trying to implement your annotations.
Quote:Clearly, your construct is ambiguous, the second part "| ID" is never
reached. Your "NonLiteral" can't both be a reference to something via
ID, and have a name that is an ID at the same time. How to solve this
depends on what you want to do. If you just remove the "| ID" - the
grammar will naturally accept an ID, if it can't find what it is
referencing, your model will have an unresolved reference.
However regarding my main problem with a nonTerminal being a Reference of an identifier I am still at the startpoint. I do realize that this grammar is ambigious, but how can i be able to resolve it, without introducing keywords.
I am not allowed to remove ID since this is a context-free-grammar specification which refers to Terminals(defined in the glaFile). Since a contextFree Grammar can contain Terminals or Nonterminals on the righthand side I am not able to remove either one of them.
I am currently trying to use the solution which is described by (url cant be shown cause of my few posts )
The Blog describes how something like
MyCrossReference: refThis=[This] | refThat=[ext::That]
Can be used by simply making the following changes
MyCrossReference: ref=[ecore::EObject];
IScope scope_MyCrossReference_ref (Model model, EReference eRef) {
List<EObject> crossRefTargets = new ArrayList<EObject>(model.getThings());
Iterable<That> allThat =
com.google.common.collect.Iterables.filter(
model.getExternalModel().getStuff(), That.class);
com.google.common.collect.Iterables.addAll(crossRefTargets, allThat);
return org.eclipse.xtext.scoping.Scopes.scopeFor(crossRefTargets);
}
however I don't quite manage to transform the given code into something which works for me
Thank you
Paolo
[Updated on: Sun, 02 September 2012 19:43] Report message to a moderator
|
|
|
Re: Xtext Crossreference shadowing ID [message #907058 is a reply to message #906824] |
Mon, 03 September 2012 08:21 |
paolo pinkel Messages: 10 Registered: July 2012 |
Junior Member |
|
|
I just came across another possibility, which is to deactivate the error message being displayed when a cross reference could not be resolved, which would result in accepting an ID Token.
google says, i have to implement the ILinkingDiagnosticsMessageProvider and let it return null. That said , I tried to do the following
public class MyLinkingDiagnosticMessageProvider extends
LinkingDiagnosticMessageProvider {
public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
return null;
}
}
which doesnt quite work for, me what am I doing wrong?
Thank you guys
Best wishes Paolo
[Updated on: Mon, 03 September 2012 08:43] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03548 seconds