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

Bug 360834

Summary: Infinite Loop on unordered groups if all elements are optional
Product: [Modeling] TMF Reporter: Daniel Mising name <danielku15>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: 2.1.0Flags: sebastian.zarnekow: indigo+
Target Milestone: SR2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
A demo grammar causing the problem
none
A second grammar without recursive rule calls. none

Description Daniel Mising name CLA 2011-10-13 10:11:31 EDT
Build Identifier: 20110615-0604

If you define an unordered group where all elements are optional (like class modifiers in Java) it leads into an infinite/endless loop if you hit code-completion.  

If you test the sample you will notice that the endless loop is caused by the ui.InternalMyDslParser.rule__ClassDeclaration__MembersAssignment_4 method. It starts searching for proposals within it's nested rule and this leads to an infinite recursion. 


Reproducible: Always

Steps to Reproduce:
1. Create a new empty xtext project
2. Copy the grammar from the attachment into the project and run the MWE2
3. Start Eclipse
4. Create a new empty DSL file 
5. Place the cursor on the first line and hit CTRL+Space
6. The proposal provider will end up in an endless loop.
Comment 1 Daniel Mising name CLA 2011-10-13 10:13:33 EDT
Created attachment 205128 [details]
A demo grammar causing the problem
Comment 2 Daniel Mising name CLA 2011-10-13 10:23:30 EDT
I added a second sample grammar which demonstrates the problem. This time there's no recursion in the grammar but the error is caused by the unordered group. The Parser tries to find all available proposals but gets stuck because all elements are optional. (That's how it seems to be)

The parser loops within rule__ClassDeclaration__Group__4__Impl because the input.LA(1) always returns EOF in this case the rule__ClassDeclaration__MembersAssignment_4 is called over and over. 
Somehow the empty group causes the parser to never change the alt3 value and there the problem starts. 

To test the second grammar: Simply add an empty file and hit ctrl+space
Comment 3 Daniel Mising name CLA 2011-10-13 10:23:52 EDT
Created attachment 205129 [details]
A second grammar without recursive rule calls.
Comment 4 Sebastian Zarnekow CLA 2011-10-13 11:06:23 EDT
Good catch.

Things like

Foo:
  {Foo} (a | b?);

can cause an infinite recursion.
Comment 5 Sebastian Zarnekow CLA 2011-10-13 16:40:59 EDT
Pushed to master.
Comment 6 Karsten Thoms CLA 2017-09-19 16:57:35 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 17:08:51 EDT
Closing all bugs that were set to RESOLVED before Neon.0