Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » TemplateProposal leads to endless loop
TemplateProposal leads to endless loop [message #1780195] Thu, 18 January 2018 14:18 Go to next message
Tobias W. is currently offline Tobias W.Friend
Messages: 10
Registered: May 2017
Junior Member
Hi everybody,

today I stumbled across a really strange problem. Everytime I try to use CodeCompletion via ctrl+space in a certain place the AntlrProposalConflictHelper hangs in an endless loop in the equalTokenSequence(TokenSource first, TokenSource second) method.

My DSL grammar is this:

Method: 'method' name=ID fireAndForget?=FireAndForget? '(' methodArguments+=MethodArgument? (',' methodArguments+=MethodArgument)* ')';

FireAndForget: '[fireAndForget]';

MethodArgument: InArgument | OutArgument | InOutArgument;

InArgument: direction='in' type=PATH name=ID;

OutArgument: direction='out' type=PATH name=ID;

InOutArgument: direction='inout' type=PATH name=ID;

terminal fragment DIGIT: '0'..'9';

terminal fragment LOWERCASE_LETTER: 'a'..'z';

terminal fragment UPPERCASE_LETTER: 'A'..'Z';

terminal ID: (LOWERCASE_LETTER|UPPERCASE_LETTER|'_') (LOWERCASE_LETTER|UPPERCASE_LETTER|DIGIT|'_')*;

terminal PATH: ('/' ID)+;

But when I now type: "method MyMethod ()" with the cursor between the brackets and trying to use CodeCompletion via ctrl+space the application hangs.

This is what the data in the equalTokenSequence(TokenSource first, TokenSource second) looks like when it happens:
first data [$, {, i, n, }, , $, {, t, y, p, e, }, , $, {, n, a, m, e, }]
token [@-1,0:-1='',<9>,1:0]
text
second data [(, $, {, i, n, }, , $, {, t, y, p, e, }, , $, {, n, a, m, e, }]
token [@-1,1:0='',<9>,1:1]
text
The method reads in the next token in a while loop but the next token is always the same like written above.

Any idea what the problem could be? Is there something wrong with my grammar?

Greetings
Tobias
Re: TemplateProposal leads to endless loop [message #1780211 is a reply to message #1780195] Thu, 18 January 2018 15:51 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 608
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Tobias,

I tried your sample that you gave and do not experience a problem with my Xtext 2.14 developer workspace. Which Xtext version do you use? I suppose you printed only the relevant part of your grammar, but not the complete. The grammar I took is:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	methods+=Method*;
	

Method: 'method' name=ID fireAndForget?=FireAndForget? '(' methodArguments+=MethodArgument? (',' methodArguments+=MethodArgument)* ')';

FireAndForget: '[fireAndForget]';

MethodArgument: InArgument | OutArgument | InOutArgument;

InArgument: direction='in' type=PATH name=ID;

OutArgument: direction='out' type=PATH name=ID;

InOutArgument: direction='inout' type=PATH name=ID;

terminal fragment DIGIT: '0'..'9';

terminal fragment LOWERCASE_LETTER: 'a'..'z';

terminal fragment UPPERCASE_LETTER: 'A'..'Z';

terminal ID: (LOWERCASE_LETTER|UPPERCASE_LETTER|'_') (LOWERCASE_LETTER|UPPERCASE_LETTER|DIGIT|'_')*;

terminal PATH: ('/' ID)+;


If you can give a reproducing example with Xtext 2.13 please file a bug.

~Karsten
Re: TemplateProposal leads to endless loop [message #1780215 is a reply to message #1780211] Thu, 18 January 2018 16:37 Go to previous messageGo to next message
Tobias W. is currently offline Tobias W.Friend
Messages: 10
Registered: May 2017
Junior Member
Hi Karsten,

we are currently working with Xtext 2.12.0. The grammar is too long to post here but the complete relevant parts are the following (we don't use org.eclipse.xtext.common.Terminals):

grammar com.example.dsl.Ara hidden(WS, ML_COMMENT, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate ara "http://www.example.com/dsl/Ara"

Domainmodel:
{Domainmodel}
declarations+=AbstractDeclaration*
;
AbstractDeclaration:
Interface
;
Interface:
'Interface' name=PATH '{'
methods+=Method*
'}'
;
Method:
'method' name=ID fireAndForget?=FireAndForget? '('
methodArguments+=MethodArgument*
')'
;
FireAndForget:
'[fireAndForget]'
;
MethodArgument:
InArgument | OutArgument | InOutArgument
;
InArgument:
'in' type=PATH name=ID
;
OutArgument:
'out' type=PATH name=ID
;
InOutArgument:
'inout' type=PATH name=ID
;
terminal fragment DIGIT:
'0'..'9'
;
terminal fragment LOWERCASE_LETTER:
'a'..'z'
;
terminal fragment UPPERCASE_LETTER:
'A'..'Z'
;
terminal ID:
(LOWERCASE_LETTER|UPPERCASE_LETTER|'_') (LOWERCASE_LETTER|UPPERCASE_LETTER|DIGIT|'_')*
;
terminal PATH:
('/' ID)+
;
terminal ML_COMMENT:
'/*' -> '*/'
;
terminal SL_COMMENT:
'//' !('\n'|'\r')* ('\r'? '\n')?
;
terminal WS:
(' '|'\t'|'\r'|'\n')+
;

As you can see I tweaked the Method-ParserRule a little bit but also with no success. But in all other places in our DSL CodeCompletion works just fine. If we remove the Templates for the 3 Arguments from the TemplateStore at least it doesn't get into the endless loop, but also the Templates are not available of course. The only proposals are then 'in' 'out' and 'inout'.

Has there something changed in the handling of Antlr and Tokens between 2.12.0 and 2.13/2.14?

I will try to test it with Xtext >2.12.0 and see if this changes anything

Greetings
Tobias

[Updated on: Thu, 18 January 2018 16:39]

Report message to a moderator

Re: TemplateProposal leads to endless loop [message #1780216 is a reply to message #1780215] Thu, 18 January 2018 16:42 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 608
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Quote:
Has there something changed in the handling of Antlr and Tokens between 2.12.0 and 2.13/2.14?


Nothing I'm aware of. I just can't reproduce your problem.
Re: TemplateProposal leads to endless loop [message #1780220 is a reply to message #1780216] Thu, 18 January 2018 17:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12190
Registered: July 2009
Senior Member
you are talking about "TemplateProposal" but did not post any

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: TemplateProposal leads to endless loop [message #1780222 is a reply to message #1780220] Thu, 18 January 2018 17:48 Go to previous messageGo to next message
Tobias W. is currently offline Tobias W.Friend
Messages: 10
Registered: May 2017
Junior Member
Nothing special about the templates. They look like this:

Method:
method ${name} ${fireAndForget} (${methodArguments})

InArgument:
${in} ${type} ${name}

OutArgument:
${out} ${type} ${name}

InOutArgument:
${inout} ${type} ${name}

and after I tweaked the grammar a little bit they look like this:

InArgument:
in ${type} ${name}

...like above...


Templates get generated generically from the grammar file. Therefor we extend the XtextTemplateStore and walk through all the rules in the grammar and add them to the store after some formatting.
Re: TemplateProposal leads to endless loop [message #1780284 is a reply to message #1780222] Fri, 19 January 2018 15:36 Go to previous messageGo to next message
Tobias W. is currently offline Tobias W.Friend
Messages: 10
Registered: May 2017
Junior Member
We tested today with an older version of our tool and there is no issue.

With AntlrWorks I couldn't see any issues in the grammar, so that should be fine.

I think the problem lies somewhere else, probably in our own way of handling the workflow and generating the DSL.

I will dig into that and see if we can come up with a solution.


Re: TemplateProposal leads to endless loop [message #1780288 is a reply to message #1780284] Fri, 19 January 2018 15:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12190
Registered: July 2009
Senior Member
it would help to have something reproducible....


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: TemplateProposal leads to endless loop [message #1780494 is a reply to message #1780288] Tue, 23 January 2018 11:10 Go to previous message
Tobias W. is currently offline Tobias W.Friend
Messages: 10
Registered: May 2017
Junior Member
Ok we resolved the issue. The problem was a terminal rule for an ipv6 address.
Our terminals were defined like this:

terminal fragment DIGIT:
'0'..'9'
;
terminal fragment LOWERCASE_LETTER:
'a'..'z'
;
terminal fragment UPPERCASE_LETTER:
'A'..'Z'
;
terminal ANY:
'ANY'
;
terminal VERSION_ID returns ecore::EString:
'v' (DIGIT | ANY) ('.' (DIGIT | ANY))?
;
terminal ID:
(LOWERCASE_LETTER|UPPERCASE_LETTER|'_') (LOWERCASE_LETTER|UPPERCASE_LETTER|DIGIT|'_')*
;
terminal BIG_INT returns ecore::EBigInteger:
(DIGIT)+
;
terminal BIG_DECIMAL returns ecore::EBigDecimal:
BIG_INT ('.' BIG_INT)?
;
terminal IP_V4:
BIG_INT ('.' BIG_INT)*
;
terminal fragment IP6_RANGE:
(DIGIT|'a'..'f'|'A'..'F')
;
terminal IP_V6:
(IP6_RANGE | ':' | '.')*
;
terminal ASR_PATH:
('/' ID)+
;
terminal ASR_NAMESPACE:
ID ('::' ID)*
;
terminal ML_COMMENT:
'/*' -> '*/'
;
terminal SL_COMMENT:
'//' !('\n'|'\r')* ('\r'? '\n')?
;
terminal WS:
(' '|'\t'|'\r'|'\n')+
;


There where no complaints by Antlr when generating the language. I know in the mean time that this is not the right way for defining terminals and we switched the specific terminal rules to data type rules.

Thanks for the help.

Best regards
Tobias
Previous Topic:Incorrect "Type mismatch" error due to duplicate type hierarchy in editor
Next Topic:Debugging DSL code
Goto Forum:
  


Current Time: Wed Aug 22 05:48:06 GMT 2018

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

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

Back to the top