mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
applied patch from bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=248463
This commit is contained in:
parent
9a0da686a7
commit
76d50eb17e
4 changed files with 56 additions and 73 deletions
|
@ -21,13 +21,14 @@ public abstract class AbstractParseTreeConstructor implements
|
|||
protected final static boolean IS_MANY = true;
|
||||
protected final static boolean IS_REQUIRED = true;
|
||||
protected boolean many;
|
||||
|
||||
// TODO: rename to current
|
||||
protected InstanceDescription object;
|
||||
protected AbstractToken otherSolution;
|
||||
|
||||
protected AbstractToken predecessor;
|
||||
protected boolean required;
|
||||
|
||||
|
||||
public AbstractToken(AbstractToken predecessor, boolean many,
|
||||
boolean required) {
|
||||
super();
|
||||
|
@ -52,13 +53,12 @@ public abstract class AbstractParseTreeConstructor implements
|
|||
}
|
||||
|
||||
public AbstractToken createFirstSolution(InstanceDescription obj) {
|
||||
System.out.println("enter :" + depth(this)
|
||||
+ getClass().getSimpleName() + "\t " + obj + " -> "
|
||||
+ dsl(this));
|
||||
System.out.println("->" + depth(this) + getClass().getSimpleName()
|
||||
+ "\t " + obj + " -> " + dsl(this));
|
||||
object = obj;
|
||||
AbstractToken t1 = createOneChild(this);
|
||||
System.out
|
||||
.println("return:"
|
||||
.println("< "
|
||||
+ depth(this)
|
||||
+ getClass().getSimpleName()
|
||||
+ " -> "
|
||||
|
@ -68,17 +68,17 @@ public abstract class AbstractParseTreeConstructor implements
|
|||
return required ? null : predecessor;
|
||||
if (many) {
|
||||
AbstractToken t2 = newInstance(t1);
|
||||
t2 = t2.createFirstSolution(t1.object);
|
||||
AbstractToken t3 = t2.createFirstSolution(t1.object);
|
||||
|
||||
if (t2 != null) {
|
||||
if (t3 != null) {
|
||||
otherSolution = t1;
|
||||
return t2;
|
||||
object = t2.object;
|
||||
return t3;
|
||||
}
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
|
||||
public AbstractToken createNextSolution() {
|
||||
if (otherSolution != null) {
|
||||
AbstractToken t = otherSolution;
|
||||
|
@ -99,7 +99,6 @@ public abstract class AbstractParseTreeConstructor implements
|
|||
return b.toString();
|
||||
}
|
||||
|
||||
|
||||
private String dsl(AbstractToken ele) {
|
||||
SimpleSerializingCallback cb = new SimpleSerializingCallback(
|
||||
converterService);
|
||||
|
@ -122,7 +121,6 @@ public abstract class AbstractParseTreeConstructor implements
|
|||
return object;
|
||||
}
|
||||
|
||||
|
||||
protected abstract AbstractToken newInstance(AbstractToken predecessor);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ public class InstanceDescription implements IInstanceDescription {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
List<String> l = new ArrayList<String>();
|
||||
|
@ -90,7 +91,8 @@ public class InstanceDescription implements IInstanceDescription {
|
|||
EStructuralFeature f = described.eClass().getEStructuralFeature(
|
||||
i.getKey());
|
||||
Object v = described.eGet(f);
|
||||
int count = (v instanceof Collection) ? ((Collection<?>) v).size() : 1;
|
||||
@SuppressWarnings("unchecked")
|
||||
int count = (v instanceof Collection) ? ((Collection) v).size() : 1;
|
||||
l.add(i.getKey() + ":" + i.getValue() + "/" + count);
|
||||
}
|
||||
return hashCode() + "/" + described.eClass().getName() + ":"
|
||||
|
|
|
@ -19,60 +19,59 @@ import org.eclipse.xtext.util.EmfFormater;
|
|||
import org.eclipse.xtext.xtext2ecore.EcoreModelComparator;
|
||||
|
||||
public class ComplexReconstrTest extends AbstractGeneratorTest {
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(ComplexReconstrTestStandaloneSetup.class);
|
||||
}
|
||||
|
||||
|
||||
public void testPrintGrammar() {
|
||||
ResourceSet rs = new XtextResourceSet();
|
||||
URI u = URI.createURI("classpath:/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTest.xmi");
|
||||
URI u = URI
|
||||
.createURI("classpath:/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTest.xmi");
|
||||
EObject o = rs.getResource(u, true).getContents().get(0);
|
||||
for(Object x : o.eContents()) if(x instanceof ParserRule) {
|
||||
ParserRule pr = (ParserRule) x;
|
||||
if(pr.getName().toLowerCase().contains("tricky")){
|
||||
System.out.println(EmfFormater.objToStr(pr, ""));
|
||||
for (Object x : o.eContents())
|
||||
if (x instanceof ParserRule) {
|
||||
ParserRule pr = (ParserRule) x;
|
||||
if (pr.getName().toLowerCase().contains("tricky")) {
|
||||
System.out.println(EmfFormater.objToStr(pr, ""));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FIXME: Make this test work again
|
||||
|
||||
// public void testSimple() throws Exception {
|
||||
// String model = "( a + b - c ) !";
|
||||
// assertEquals(model,parseAndSerialize(model));
|
||||
// }
|
||||
|
||||
// FIXME: Make this test work again
|
||||
|
||||
// public void testComplex() throws Exception {
|
||||
// String model = "( ( a + b ) ! - c + d + e + f - ( x + s ) - ( ( a + b ) ! - c ) ! ) !";
|
||||
// assertEquals(model,parseAndSerialize(model));
|
||||
// }
|
||||
public void testSimple() throws Exception {
|
||||
String model = "( a + b - c ) !";
|
||||
assertEquals(model, parseAndSerialize(model));
|
||||
}
|
||||
|
||||
public void testComplex() throws Exception {
|
||||
String model = "( ( a + b ) ! - c + d + e + f - ( ^x + s ) - ( ( a + b ) ! - c ) ! ) !";
|
||||
assertEquals(model, parseAndSerialize(model));
|
||||
}
|
||||
|
||||
private String parseAndSerialize(String model) throws Exception {
|
||||
EObject result = (EObject) getModel(model);
|
||||
System.out.println(EmfFormater.objToStr(result, ""));
|
||||
IParseTreeConstructor con = getParseTreeConstructor();
|
||||
WhitespacePreservingCallback callback = new WhitespacePreservingCallback(getValueConverterService());
|
||||
con.update(result,callback);
|
||||
WhitespacePreservingCallback callback = new WhitespacePreservingCallback(
|
||||
getValueConverterService());
|
||||
con.update(result, callback);
|
||||
return callback.toString();
|
||||
}
|
||||
|
||||
// FIXME: Make this test work again
|
||||
|
||||
// public void testNormalizableCompositeNodesIncluded() throws Exception {
|
||||
// reconstructAndCompare("a");
|
||||
// reconstructAndCompare("a + b");
|
||||
// }
|
||||
|
||||
private void reconstructAndCompare(String mymodel) throws Exception, InterruptedException {
|
||||
public void testNormalizableCompositeNodesIncluded() throws Exception {
|
||||
reconstructAndCompare("a");
|
||||
reconstructAndCompare("a + b");
|
||||
}
|
||||
|
||||
private void reconstructAndCompare(String mymodel) throws Exception,
|
||||
InterruptedException {
|
||||
EObject model = getModel(mymodel);
|
||||
EObject model2 = getModel(parseAndSerialize(mymodel));
|
||||
EcoreModelComparator ecoreModelComparator = new EcoreModelComparator();
|
||||
assertFalse(ecoreModelComparator.modelsDiffer(model, model2));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -25,14 +25,15 @@ public class SimpleReconstrTest extends AbstractGeneratorTest {
|
|||
String model = "( a b ) !";
|
||||
assertEquals(model, parseAndSerialize(model));
|
||||
}
|
||||
|
||||
|
||||
// FIXME: Make this test work again
|
||||
// FIXME: make this work again
|
||||
|
||||
// public void testFollowingHiddenTokens() throws Exception {
|
||||
// String model = "a ";
|
||||
// assertEquals(model, parseAndSerialize(model));
|
||||
// }
|
||||
// FIXME: Make this test work again
|
||||
|
||||
// FIXME: make this work again
|
||||
|
||||
// public void testComplex() throws Exception {
|
||||
// String model = "( ( a b ) ! c d e f ( x s ) ( \t ( a \n\rb/*ffo \n bar */ ) ! c ) ! ) //holla\n!";
|
||||
|
@ -49,38 +50,21 @@ public class SimpleReconstrTest extends AbstractGeneratorTest {
|
|||
return callback.toString();
|
||||
}
|
||||
|
||||
public void recursionTest() {
|
||||
rec(1);
|
||||
public void testSimpleExpressions5() throws Exception {
|
||||
with(SimpleExpressionsStandaloneSetup.class);
|
||||
String model = "a + b - c * d / e";
|
||||
assertEquals(model, parseAndSerialize(model));
|
||||
}
|
||||
|
||||
private void rec(int i) {
|
||||
// max1: 345957
|
||||
String xxx = "lala";
|
||||
xxx += "y";
|
||||
System.out.println(i);
|
||||
rec(i + 1);
|
||||
public void testSimpleExpressions1() throws Exception {
|
||||
with(SimpleExpressionsStandaloneSetup.class);
|
||||
String model = "a + b - c";
|
||||
assertEquals(model, parseAndSerialize(model));
|
||||
}
|
||||
|
||||
// FIXME: Make this test work again
|
||||
|
||||
// public void testSimpleExpressions5() throws Exception {
|
||||
// with(SimpleExpressionsStandaloneSetup.class);
|
||||
// String model = "a + b - c * d / e";
|
||||
// assertEquals(model, parseAndSerialize(model));
|
||||
// }
|
||||
|
||||
// FIXME: Make this test work again
|
||||
|
||||
// public void testSimpleExpressions1() throws Exception {
|
||||
// with(SimpleExpressionsStandaloneSetup.class);
|
||||
// String model = "a + b - c";
|
||||
// assertEquals(model, parseAndSerialize(model));
|
||||
// }
|
||||
|
||||
public void testSimpleTwoNumbers() throws Exception {
|
||||
String model = "2 45";
|
||||
assertEquals(model, parseAndSerialize(model));
|
||||
|
||||
}
|
||||
|
||||
public void testSimpleManyStrings1() throws Exception {
|
||||
|
|
Loading…
Reference in a new issue