Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 347012

Summary: [xtext-ui] content assist parser recovers forever
Product: [Modeling] TMF Reporter: Martin Schnabel <mb0>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: 2.0.0Flags: sebastian.zarnekow: indigo+
Target Milestone: SR2   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
failing test project none

Description Martin Schnabel CLA 2011-05-24 11:46:09 EDT
Build Identifier: 20110218-0911

I try to migrate a backtracking grammar to xtext2 from the zipped update-site tmf-xtext-Update-2.0.0RC1.zip.
When i invoke the parser rule in AbstractContentAssistParser.getFollowElements(AbstractInternalContentAssistParser, AbstractElement, String[], int) on the input
"package a { public class Aa { var name:String|; } }" eclipse freezes (| is the caret position). The input is valid and is parsed without errors by the runtime parser.

The freeze is due to a endless loop:
1. parser.rule__ITypeDirective__Alternatives tries to predict a dfa.
2. fails to predict with a NoViableAltException.
3. recovers the error, stack and input and starts again at 1. without any side effects.

Instead i would expect that the content assist parser simply fails or even better correctly predicts the follow elements.

Reproducible: Always

Steps to Reproduce:
The grammar is huge but i can try to reduce it to a small reproducible example when needed.
Comment 1 Sebastian Zarnekow CLA 2011-05-25 17:45:27 EDT
A reproducable example would be very helpful.
Comment 2 Martin Schnabel CLA 2011-05-26 13:33:57 EDT
Created attachment 196688 [details]
failing test project

1. extract the zip.
2. add the .antlr-generator-3.2.0.jar and a com.ibm.icu_3.4.4.1.jar to the org.xtext.example.mydsl project.
3. launch org.xtext.example.mydsl/GenerateMyDsl.mwe2.launch
4. launch org.xtext.example.mydsl.tests/org.xtext.example.mydsl.tests.launch
5. notice freeze
6. edit MxDsl.xtext so MyAttributes is only parsed when a token is matched:
MyAttributes: (attributes+=MyAttribute)+;
MyField: attr=MyAttributes? 'var' LT* bindings+=MyBinding (LT* ',' LT* bindings+=MyBinding)* VirtualSemi;
7. generate and test again and notice success

so it seems that rules the might not match any tokens make it fail?
Comment 3 Martin Schnabel CLA 2011-05-26 13:57:21 EDT
i changed my main grammar and it seems to work. but i think xtext should analyze this situation and warn the user not to use rules that might not consume any tokens.

otherwise empty rules can be handy for ast construction. i use them to help with default behavior for declaration attributes and as placeholders for empty entries in array literals.

xtext is great. thanks
Comment 4 Sebastian Zarnekow CLA 2011-10-13 17:39:27 EDT
Pushed to master.

Please note that the production parser may get stuck, too. E.g. the following input models will lead to infinite loops:

package a { public class Aa {

package a { public class Aa { var 

package a { public class Aa { var }

package a { public class Aa { var  Name }
Comment 5 Sebastian Zarnekow CLA 2011-10-13 18:06:09 EDT
(In reply to comment #4)

> Please note that the production parser may get stuck, too. 

see bug 360892
Comment 6 Karsten Thoms CLA 2017-09-19 17:45:43 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 17:56:43 EDT
Closing all bugs that were set to RESOLVED before Neon.0