summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-11 14:42:09 (EDT)
committer sefftinge2009-03-11 14:42:09 (EDT)
commit51f4b23ef6921171c14b20453669c52cc957de61 (patch)
treed11054cd08cb344202301f2630bc7c63f03e4c2b
parent50e590c2c804b931176d870b254a0ec59cc90bfc (diff)
downloadorg.eclipse.xtext-51f4b23ef6921171c14b20453669c52cc957de61.zip
org.eclipse.xtext-51f4b23ef6921171c14b20453669c52cc957de61.tar.gz
org.eclipse.xtext-51f4b23ef6921171c14b20453669c52cc957de61.tar.bz2
Fix: yet another infinite loop in DamagerRepairer (this one needs definitly a refactoring and some serious tests ...)
Fix: Bug in Antlr parser with illegal tokens before eof
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextDamagerRepairer.java3
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parseerrorhandling/ParseErrorHandlingTest.java37
2 files changed, 39 insertions, 1 deletions
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextDamagerRepairer.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextDamagerRepairer.java
index 64c856b..a698093 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextDamagerRepairer.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextDamagerRepairer.java
@@ -60,6 +60,7 @@ public class XtextDamagerRepairer extends DefaultDamagerRepairer {
if (node instanceof CompositeNode) {
if (((CompositeNode) node).getChildren().isEmpty())
break;
+ AbstractNode prevNode = node;
for(AbstractNode child: ((CompositeNode) node).getChildren()) {
if (child.getTotalOffset() <= offset && child.getTotalOffset() + child.getTotalLength() >= offset) {
node = child;
@@ -68,6 +69,8 @@ public class XtextDamagerRepairer extends DefaultDamagerRepairer {
break;
}
}
+ if (prevNode == node)
+ start = node;
} else {
throw new IllegalStateException("node is not in expected range but is not a composite.");
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parseerrorhandling/ParseErrorHandlingTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parseerrorhandling/ParseErrorHandlingTest.java
index cfebb06..fe05bc4 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parseerrorhandling/ParseErrorHandlingTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parseerrorhandling/ParseErrorHandlingTest.java
@@ -8,15 +8,22 @@
*******************************************************************************/
package org.eclipse.xtext.parseerrorhandling;
+import java.util.List;
+
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.xtext.XtextGrammarTestLanguageStandaloneSetup;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
+import org.eclipse.xtext.parsetree.NodeAdapter;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.parsetree.SyntaxError;
import org.eclipse.xtext.testlanguages.ReferenceGrammarTestLanguageStandaloneSetup;
+import org.eclipse.xtext.testlanguages.TreeTestLanguageStandaloneSetup;
+import org.eclipse.xtext.testlanguages.treeTestLanguage.Model;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
public class ParseErrorHandlingTest extends AbstractGeneratorTest {
@@ -90,7 +97,6 @@ public class ParseErrorHandlingTest extends AbstractGeneratorTest {
assertEquals(1,node.allSyntaxErrors().size());
}
-
public void testLexerError() throws Exception {
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
String model = "spielplatz 100 '}";
@@ -100,4 +106,33 @@ public class ParseErrorHandlingTest extends AbstractGeneratorTest {
logger.debug(node.allSyntaxErrors().get(0).getMessage());
}
+ public void testTrailingRecoverableError() throws Exception {
+ with(TreeTestLanguageStandaloneSetup.class);
+ String model = "parent ('Teststring') { \n" +
+ " child ('Teststring'){};\n" +
+ " child ('Teststring'){};\n" +
+ "};\n" +
+ "};\n" +
+ "\n";
+ Resource res = getResourceFromString(model);
+ assertEquals(res.getErrors().size(), 1, res.getErrors().size());
+ Diagnostic diag = res.getErrors().get(0);
+ assertNotNull(diag);
+ assertEquals(5, diag.getLine());
+ assertEquals(1, diag.getColumn());
+ Model parsedModel = (Model) res.getContents().get(0);
+ assertNotNull(parsedModel);
+ NodeAdapter nodeAdapter = NodeUtil.getNodeAdapter(parsedModel);
+ assertNotNull(nodeAdapter);
+ List<LeafNode> leafs = nodeAdapter.getParserNode().getLeafNodes();
+ LeafNode lastWs = leafs.get(leafs.size() - 1);
+ assertTrue(lastWs.isHidden());
+ assertNull(lastWs.getSyntaxError());
+ LeafNode lastNode = leafs.get(leafs.size() - 2);
+ assertTrue(lastNode.isHidden());
+ assertNotNull(lastNode);
+ assertEquals("};", lastNode.getText());
+ assertNotNull(lastNode.getSyntaxError());
+ }
+
}