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

Bug 362685

Summary: UI Parser Hangs up
Product: [Modeling] TMF Reporter: Christian Dietrich <christian.dietrich.opensource>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: benjamin.schwertfeger, sebastian.zarnekow, sven.efftinge
Version: unspecifiedFlags: sebastian.zarnekow: juno+
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Christian Dietrich CLA 2011-11-02 11:00:32 EDT
Build Identifier: 2.0.0 2.1.0

Having following (largely simplified) grammar

Model:
    elements+=Element+
    ;
    
Element:
    Entity | Test
;

Entity:
    "entity" name=ID
;


Test:
    "test" name=ID "("
    ans=NavStatement
    ")"  
;

NavStatement returns Statement
    :   '(' NavStatement ')'
    |   {IFElseStatement} 'if' cond=Expr 'then' if=NavStatement (=> 'else' else=NavStatement)?
    |   {URLNavigation} 'url' url=Expr
    |   {BackStatement} 'back'
    |   {RefStatement} '#' uebergang=[Entity|ID]
    ;
    
    enum Expr:
        YES | NO        
    ;


and following dummy example model:

entity Uebergang_1

test x (
							if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
							else if YES then #Uebergang_1
						)
							
							

the editor hangs up on invocation of content assist at the end of the file

Reproducible: Always
Comment 1 Benjamin Schwertfeger CLA 2011-11-30 18:25:31 EST
The handling of syntactic predicates leads to duplicate parsing. In the generated Parser is a method like this:
rule__NavStatement__Group_1__5__Impl()
...
if ( (LA5_0==19) ) {
                if ( (synpred6_InternalMyDsl()) ) {
                    alt5=1;
                }
            }
            switch (alt5) {
                case 1 : ...
                    rule__NavStatement__Group_1_5__0();

Where synpred6_InternalMyDsl also calls the rule rule__NavStatement__Group_1_5__0. Because the result is not cached you get a O^2 runtime for each recursive/hierarchical usage of syntactic predicates.

Workaround:
If possible remove the syntactic predicate and ignore the warning while generating.
Comment 2 Sebastian Zarnekow CLA 2011-11-30 18:32:14 EST
Please try to enable memoization for the ui parser.
Comment 3 Benjamin Schwertfeger CLA 2011-11-30 18:43:50 EST
(In reply to comment #2)
> Please try to enable memoization for the ui parser.

For the given example it works like a charm. Thanks for the hint.