Search in sources :

Example 1 with CEvalSet

use of mb.nabl2.constraints.sets.CEvalSet in project nabl by metaborg.

the class SetComponent method solve.

private Optional<SolveResult> solve(CEvalSet constraint) {
    ITerm setTerm = unifier().findRecursive(constraint.getSet());
    if (!setTerm.isGround()) {
        return Optional.empty();
    }
    Optional<Set<IElement<ITerm>>> maybeSet = evaluator.match(setTerm, unifier());
    if (!(maybeSet.isPresent())) {
        return Optional.empty();
    }
    List<ITerm> set = maybeSet.get().stream().map(i -> unifier().findRecursive(i.getValue())).collect(Collectors.toList());
    return Optional.of(SolveResult.constraints(ImmutableCEqual.of(constraint.getResult(), B.newList(set), constraint.getMessageInfo())));
}
Also used : ISetConstraint(mb.nabl2.constraints.sets.ISetConstraint) Function1(org.metaborg.util.functions.Function1) ITerm(mb.nabl2.terms.ITerm) ImmutableCEqual(mb.nabl2.constraints.equality.ImmutableCEqual) Multimap(com.google.common.collect.Multimap) SolveResult(mb.nabl2.solver.ISolver.SolveResult) SolverCore(mb.nabl2.solver.SolverCore) CEvalSet(mb.nabl2.constraints.sets.CEvalSet) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) SetEvaluator(mb.nabl2.sets.SetEvaluator) T(mb.nabl2.terms.matching.Transform.T) Unit(org.metaborg.util.unit.Unit) B(mb.nabl2.terms.build.TermBuild.B) ImmutableMessageInfo(mb.nabl2.constraints.messages.ImmutableMessageInfo) ASolver(mb.nabl2.solver.ASolver) M(mb.nabl2.terms.matching.TermMatch.M) Collection(java.util.Collection) Set(java.util.Set) CDistinct(mb.nabl2.constraints.sets.CDistinct) Collectors(java.util.stream.Collectors) IMessageInfo(mb.nabl2.constraints.messages.IMessageInfo) MessageContent(mb.nabl2.constraints.messages.MessageContent) CSubsetEq(mb.nabl2.constraints.sets.CSubsetEq) Iterables2(org.metaborg.util.iterators.Iterables2) List(java.util.List) Optional(java.util.Optional) IMatcher(mb.nabl2.terms.matching.TermMatch.IMatcher) IElement(mb.nabl2.sets.IElement) CEvalSet(mb.nabl2.constraints.sets.CEvalSet) Set(java.util.Set) ITerm(mb.nabl2.terms.ITerm)

Aggregations

HashMultimap (com.google.common.collect.HashMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ImmutableCEqual (mb.nabl2.constraints.equality.ImmutableCEqual)1 IMessageInfo (mb.nabl2.constraints.messages.IMessageInfo)1 ImmutableMessageInfo (mb.nabl2.constraints.messages.ImmutableMessageInfo)1 MessageContent (mb.nabl2.constraints.messages.MessageContent)1 CDistinct (mb.nabl2.constraints.sets.CDistinct)1 CEvalSet (mb.nabl2.constraints.sets.CEvalSet)1 CSubsetEq (mb.nabl2.constraints.sets.CSubsetEq)1 ISetConstraint (mb.nabl2.constraints.sets.ISetConstraint)1 IElement (mb.nabl2.sets.IElement)1 SetEvaluator (mb.nabl2.sets.SetEvaluator)1 ASolver (mb.nabl2.solver.ASolver)1 SolveResult (mb.nabl2.solver.ISolver.SolveResult)1