Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Crossreference shadowing ID
Xtext Crossreference shadowing ID [message #902688] Sun, 19 August 2012 16:08 Go to next message
paolo pinkel is currently offline paolo pinkelFriend
Messages: 10
Registered: July 2012
Junior Member
Hi, I am quite new to text, so i came across a problem I am not able to solve.
I got a grammar which has a cross reference to another Grammar
grammar de.sabram.upb.specs.Con with org.eclipse.xtext.common.Terminals hidden (WS, ML_COMMENT, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate con "sabram.de/upb/specs/Con"
import "sabram.de/upb/specs/Gla" as glaSpecs

ConSpec hidden(WS, ML_COMMENT, SL_COMMENT): rules+=Rule*;

Rule: (RuleName '=')?  nonTerminalName=NonTerminal SEP_OPERATOR rule=RHS '.';

RHS: ALT (DEL_OPERATOR terminalList+=Terminal)*;

ALT: elementList+=ElemList ( ALT_OPERATOR elementList+=ElemList)*;
ElemList: (elements+=Elem | connection+=Connection | modifications+=Modification)*;

Elem: ElemExpression;
ElemExpression: TerminalOrNonTerminal | OptElem | '(' RHS ')' | REP_OPERATOR ;

OptElem: '[' RHS ']';
Modification: MOD_OPERATOR Terminal;
Connection: '&' P_STRING;

Terminal: Literal | NonLiteral;
TerminalOrNonTerminal: Literal | NonLiteral;

Literal: name=P_STRING;
NonLiteral: name=[glaSpecs::TokenName] | ID;
NonTerminal: name=ID;
RuleName : name=ID;

/**********************************************
 ****** TERMINALS 
 **********************************************/
terminal SEP_OPERATOR: ':' | '::=';
terminal ALT_OPERATOR: '/' | '|';
terminal DEL_OPERATOR: '//'| '||';
terminal MOD_OPERATOR: '$' | '@' ;
terminal REP_OPERATOR: '*' | '+';
terminal P_STRING: "'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'" ;

/*
 * DEFAULT TERMINALS
 */ 
terminal ML_COMMENT	: '/*' -> '*/';
terminal SL_COMMENT 	: '#' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS			: (' '|'\t'|'\r'|'\n')+;

The refrenced grammar part
Specification:
	 (tokenName=TokenName ':')?
	 pattern=Pattern
	 ('('auxiliaryScannerName=AuxiliaryScannerName')')? 
	 ('['tokenProcessorName=TokenProcessorName']')?
;
TokenName: name=ID;


However testing the con plugin. I get the error message
Quote:
../de.sabram.upb.specs.con/src-gen/de/sabram/upb/specs/parser/antlr/internal/InternalCon.g:715:1: Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(201): ../de.sabram.upb.specs.con/src-gen/de/sabram/upb/specs/parser/antlr/internal/InternalCon.g:715:1: The following alternatives can never be matched: 2

how am i able to resolve this issue?

Hope one of you awesome guys can help me.

Best wishes paolo.
Re: Xtext Crossreference shadowing ID [message #902702 is a reply to message #902688] Sun, 19 August 2012 23:25 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2501
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 Go to previous messageGo to next message
paolo pinkel is currently offline paolo pinkelFriend
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 Go to previous messageGo to next message
paolo pinkel is currently offline paolo pinkelFriend
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

Re: Xtext Crossreference shadowing ID [message #907075 is a reply to message #907058] Mon, 03 September 2012 08:58 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 322
Registered: July 2009
Location: Gothenburg
Senior Member
Hi!

This should work, did you configure your module to inject your class for ILinkingMessageProvider?

regards,
Vlad
Re: Xtext Crossreference shadowing ID [message #907270 is a reply to message #907075] Mon, 03 September 2012 16:29 Go to previous messageGo to next message
paolo pinkel is currently offline paolo pinkelFriend
Messages: 10
Registered: July 2012
Junior Member
Vlad Dumitrescu wrote on Mon, 03 September 2012 04:58
Hi!

This should work, did you configure your module to inject your class for ILinkingMessageProvider?

regards,
Vlad

How exactly do I have to do this?

Thank you for youer help!
Re: Xtext Crossreference shadowing ID [message #907276 is a reply to message #907270] Mon, 03 September 2012 16:35 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 322
Registered: July 2009
Location: Gothenburg
Senior Member
Your language plugin has a MyDslModule class where the Guice configuration is made, that is where you specify which classes shall implement certain interfaces. By default, the default Xtext classes are used and you have to add a method like

    public Class<? extends ILinkingDiagnosticMessageProvider> bindILinkingDiagnosticMessageProvider() {
        return MyLinkingDiagnosticMessageProvider.class;
    }


/Vlad
Re: Xtext Crossreference shadowing ID [message #907286 is a reply to message #907276] Mon, 03 September 2012 17:04 Go to previous message
paolo pinkel is currently offline paolo pinkelFriend
Messages: 10
Registered: July 2012
Junior Member
Words can't describe how much I love you!
Thank you very much. It finally works as I want it to!
Previous Topic:OCLInEcore documentation
Next Topic:Inter grammar communication issue
Goto Forum:
  


Current Time: Sun Dec 21 23:23:16 GMT 2014

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

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