Search in sources :

Example 11 with IMessageInfo

use of mb.nabl2.constraints.messages.IMessageInfo 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);
    }
}
Also used : MessageContent(mb.nabl2.constraints.messages.MessageContent) IUnifier(mb.nabl2.terms.unification.IUnifier) ImmutableSolveResult(mb.nabl2.solver.ImmutableSolveResult) SolveResult(mb.nabl2.solver.ISolver.SolveResult) ITerm(mb.nabl2.terms.ITerm) UnificationException(mb.nabl2.terms.unification.UnificationException) IMessageInfo(mb.nabl2.constraints.messages.IMessageInfo)

Aggregations

IMessageInfo (mb.nabl2.constraints.messages.IMessageInfo)10 ITerm (mb.nabl2.terms.ITerm)10 MessageContent (mb.nabl2.constraints.messages.MessageContent)7 SolveResult (mb.nabl2.solver.ISolver.SolveResult)6 Optional (java.util.Optional)4 Map (java.util.Map)3 Set (java.util.Set)3 CEvalSet (mb.nabl2.constraints.sets.CEvalSet)3 Scope (mb.nabl2.scopegraph.terms.Scope)3 IElement (mb.nabl2.sets.IElement)3 SolverCore (mb.nabl2.solver.SolverCore)3 HashMultimap (com.google.common.collect.HashMultimap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Multimap (com.google.common.collect.Multimap)2 Sets (com.google.common.collect.Sets)2 Collection (java.util.Collection)2 List (java.util.List)2 NaBL2DebugConfig (mb.nabl2.config.NaBL2DebugConfig)2 ImmutableCEqual (mb.nabl2.constraints.equality.ImmutableCEqual)2