eclipse / xtext

Eclipse Xtext™ is a language development framework
http://www.eclipse.org/Xtext
Eclipse Public License 2.0
766 stars 319 forks source link

RuntimeException in LookAheadPreservingNodeModelBuilder.replaceAndTransferLookAhead #2345

Open cdietrich opened 7 years ago

cdietrich commented 7 years ago
java.lang.RuntimeException
    at org.eclipse.xtext.xbase.parser.LookAheadPreservingNodeModelBuilder.replaceAndTransferLookAhead(LookAheadPreservingNodeModelBuilder.java:44)
    at org.eclipse.xtext.xbase.parser.TokenSequencePreservingPartialParsingHelper.reparse(TokenSequencePreservingPartialParsingHelper.java:127)
    at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doReparse(AbstractAntlrParser.java:138)
    at org.eclipse.xtext.parser.AbstractParser.reparse(AbstractParser.java:50)
    at org.eclipse.xtext.resource.XtextResource.update(XtextResource.java:253)
    at org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy.doReconcile(XtextDocumentReconcileStrategy.java:150)
    at org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy.reconcile(XtextDocumentReconcileStrategy.java:67)
    at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.doRun(XtextReconciler.java:442)
    at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.access$3(XtextReconciler.java:422)
    at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler$1.process(XtextReconciler.java:363)
    at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler$1.process(XtextReconciler.java:1)
    at org.eclipse.xtext.util.concurrent.IUnitOfWork$Void.exec(IUnitOfWork.java:37)
    at org.eclipse.xtext.resource.OutdatedStateManager.exec(OutdatedStateManager.java:98)
    at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:428)
    at org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:162)
    at org.eclipse.xtext.ui.editor.reconciler.XtextReconciler.run(XtextReconciler.java:360)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
cdietrich commented 7 years ago

Reproducing grammar and test model

problem happens when delete the ln from println and save

thing Xxxxx {

    blocka {
    }

    blockb {
        println("hello")
        //xxx.execute();
//        xxx2.execute();
        //xxx3.execute();
    }
}
import "http://www.eclipse.org/xtext/xbase/Xbase"
import "http://www.eclipse.org/xtext/common/JavaVMTypes"
import "http://www.eclipse.org/Xtext/Xbase/XAnnotations"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model:
    thing=Thing;

Thing:
    {Thing}
    'thing' name=ID
    '{'
    (a=BlockA? & b=BlockB?)
    '}';

BlockA:
    {BlockA}
    'blocka' '{'

    '}';

BlockB:
    'blockb' body=XBlockExpression;

XCastedExpression returns XExpression:
    XPostfixOperation;

    // remove 'instanceof' operator
XRelationalExpression returns XExpression:
    XOtherOperatorExpression
    (=> ({XBinaryOperation.leftOperand=current} feature=[JvmIdentifiableElement|OpCompare])
    rightOperand=XOtherOperatorExpression)*;

// reduced set of primary expressions
XPrimaryExpression returns XExpression:
    XLiteral | XBlockExpression | XIfExpression | XForLoopExpression | XParenthesizedExpression |
    => XFeatureCall;

// reduced set of literals
XLiteral returns XExpression:
    XStringLiteral;

// no "val" expressions
// initializer is required
XVariableDeclaration returns XExpression:
    {XVariableDeclaration} "var" name=ID "=" right=XExpression;

JvmSimpleFormalParameter returns JvmFormalParameter:
    name=ValidID;

XForLoopExpression returns XExpression:
    =>({XForLoopExpression}
    'for' '(' declaredParam=JvmSimpleFormalParameter ':') forExpression=XExpression ')'
        eachExpression=XExpression;

FeatureCallID:
    ValidID | 'blockb';
cdietrich commented 7 years ago

it seem to help to reorder the primary expressions

XPrimaryExpression returns XExpression:
    XFeatureCall | XLiteral | XBlockExpression | XIfExpression | XForLoopExpression | XParenthesizedExpression
;
szarnekow commented 7 years ago

It appears to be related to the predicate on XFeatureCall in your initial grammar. The predicate should not appear on the last but on the first alternative.

knutwannheden commented 6 years ago

Seems like Xtext could do with sone validations on the placement of predicates.