use of mb.nabl2.terms.unification.UnificationException in project nabl by metaborg.
the class UnificationPerformanceTest method testCycle.
private static void testCycle() {
System.out.println("Testing cycle");
final IUnifier.Transient unifier = PersistentUnifier.Transient.of();
ITermVar varA = TermBuild.B.newVar("", A);
ITermVar varB = TermBuild.B.newVar("", B);
ITermVar varC = TermBuild.B.newVar("", C);
ITerm termB = TermBuild.B.newTuple(varB, varB);
ITerm termC = TermBuild.B.newTuple(varC, varC);
try {
unifier.unify(varA, termB);
unifier.unify(varB, termC);
unifier.unify(varC, termB);
System.out.println(unifier);
} catch (UnificationException e) {
System.out.println("Could not unify");
}
System.out.println("ground = " + unifier.isGround(termB));
System.out.println("cyclic = " + unifier.isCyclic(termB));
System.out.println("size = " + unifier.size(termB));
System.out.println("vars = " + unifier.getVars(termB));
System.out.println("equal = " + unifier.areEqual(termB, termC));
System.out.println("unequal = " + unifier.areUnequal(termB, termC));
}
use of mb.nabl2.terms.unification.UnificationException in project nabl by metaborg.
the class UnificationPerformanceTest method testUnify.
private static IUnifier testUnify(int n) {
final IUnifier.Transient unifier = PersistentUnifier.Transient.of();
final ITerm left = TermBuild.B.newTuple(Iterables.concat(createVars(A, n), createTuples(B, n), Iterables2.singleton(createVar(A, n))));
final ITerm right = TermBuild.B.newTuple(Iterables.concat(createTuples(A, n), createVars(B, n), Iterables2.singleton(createVar(B, n))));
try {
unifier.unify(left, right);
} catch (UnificationException e) {
System.err.println("Unification failed");
e.printStackTrace(System.err);
}
System.out.println("ground = " + unifier.isGround(left));
System.out.println("cyclic = " + unifier.isCyclic(left));
System.out.println("size = " + unifier.size(left));
System.out.println("vars = " + unifier.getVars(left));
System.out.println("equal = " + unifier.areEqual(left, right));
System.out.println("unequal = " + unifier.areUnequal(left, right));
return unifier;
}
use of mb.nabl2.terms.unification.UnificationException in project nabl by metaborg.
the class TermMultisetTest method testContainsOriginalAndUnifiedTerm.
@Test
public void testContainsOriginalAndUnifiedTerm() throws UnificationException {
final ITermVar v1 = B.newVar("", "v1");
final ITerm t1 = B.newInt(1);
final ITerm t2 = B.newTuple(v1);
terms.add(t2, unifier);
assertEquals(1, terms.varSet().size());
IUnifier.Immutable result = unifier.unify(v1, t1);
terms.update(result.varSet(), unifier);
assertTrue(terms.contains(t2, unifier));
assertTrue(terms.contains(unifier.findTerm(t2), unifier));
assertEquals(0, terms.varSet().size());
}
use of mb.nabl2.terms.unification.UnificationException in project nabl by metaborg.
the class EqualityComponent method solve.
// ------------------------------------------------------------------------------------------------------//
private Optional<SolveResult> solve(CEqual constraint) {
final ITerm left = constraint.getLeft();
final ITerm right = constraint.getRight();
try {
final IUnifier.Transient unifier = this.unifier.get().melt();
final IUnifier.Immutable unifyResult = unifier.unify(left, right);
final SolveResult solveResult = ImmutableSolveResult.builder().unifierDiff(unifyResult).build();
this.unifier.set(unifier.freeze());
return Optional.of(solveResult);
} catch (UnificationException ex) {
final MessageContent content = MessageContent.builder().append("Cannot unify ").append(left).append(" with ").append(right).build();
final IMessageInfo message = (constraint.getMessageInfo().withDefaultContent(content));
final SolveResult solveResult = SolveResult.messages(message);
return Optional.of(solveResult);
}
}
Aggregations