Search in sources :

Example 1 with CCheckRelation

use of mb.nabl2.constraints.relations.CCheckRelation in project nabl by metaborg.

the class RelationComponent method solve.

public Optional<SolveResult> solve(CCheckRelation c) {
    final ITerm left = unifier().findRecursive(c.getLeft());
    final ITerm right = unifier().findRecursive(c.getRight());
    if (!(left.isGround() && right.isGround())) {
        return Optional.empty();
    }
    return c.getRelation().match(IRelationName.Cases.of(// @formatter:off
    name -> {
        if (!isComplete.test(name)) {
            return Optional.empty();
        }
        if (relation(name).contains(left, right)) {
            return Optional.of(SolveResult.empty());
        } else {
            return Optional.empty();
        }
    }, extName -> {
        final ITerm msginfo = MessageInfo.build(c.getMessageInfo());
        return callExternal(extName, left, right, msginfo).map(csTerm -> {
            return Constraints.matchConstraintOrList().match(csTerm, unifier()).map(SolveResult::constraints).orElseThrow(() -> new IllegalArgumentException("Expected list of constraints, got " + csTerm));
        });
    }));
}
Also used : VariantRelations(mb.nabl2.relations.variants.VariantRelations) RelationFunctions(mb.nabl2.relations.terms.FunctionName.RelationFunctions) ITerm(mb.nabl2.terms.ITerm) ImmutableCEqual(mb.nabl2.constraints.equality.ImmutableCEqual) PartialFunction1(org.metaborg.util.functions.PartialFunction1) SolveResult(mb.nabl2.solver.ISolver.SolveResult) SolverCore(mb.nabl2.solver.SolverCore) IVariantRelation(mb.nabl2.relations.variants.IVariantRelation) CCheckRelation(mb.nabl2.constraints.relations.CCheckRelation) RelationException(mb.nabl2.relations.RelationException) IRelation(mb.nabl2.relations.IRelation) Map(java.util.Map) ASolver(mb.nabl2.solver.ASolver) M(mb.nabl2.terms.matching.TermMatch.M) Constraints(mb.nabl2.constraints.Constraints) CEvalFunction(mb.nabl2.constraints.relations.CEvalFunction) FunctionUndefinedException(mb.nabl2.solver.FunctionUndefinedException) Predicate1(org.metaborg.util.functions.Predicate1) Maps(com.google.common.collect.Maps) IMessageInfo(mb.nabl2.constraints.messages.IMessageInfo) MessageContent(mb.nabl2.constraints.messages.MessageContent) IRelationConstraint(mb.nabl2.constraints.relations.IRelationConstraint) IFunctionName(mb.nabl2.relations.IFunctionName) MessageInfo(mb.nabl2.constraints.messages.MessageInfo) CBuildRelation(mb.nabl2.constraints.relations.CBuildRelation) SeedResult(mb.nabl2.solver.ISolver.SeedResult) Entry(java.util.Map.Entry) Optional(java.util.Optional) IRelationName(mb.nabl2.relations.IRelationName) SolveResult(mb.nabl2.solver.ISolver.SolveResult) ITerm(mb.nabl2.terms.ITerm)

Aggregations

Maps (com.google.common.collect.Maps)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Constraints (mb.nabl2.constraints.Constraints)1 ImmutableCEqual (mb.nabl2.constraints.equality.ImmutableCEqual)1 IMessageInfo (mb.nabl2.constraints.messages.IMessageInfo)1 MessageContent (mb.nabl2.constraints.messages.MessageContent)1 MessageInfo (mb.nabl2.constraints.messages.MessageInfo)1 CBuildRelation (mb.nabl2.constraints.relations.CBuildRelation)1 CCheckRelation (mb.nabl2.constraints.relations.CCheckRelation)1 CEvalFunction (mb.nabl2.constraints.relations.CEvalFunction)1 IRelationConstraint (mb.nabl2.constraints.relations.IRelationConstraint)1 IFunctionName (mb.nabl2.relations.IFunctionName)1 IRelation (mb.nabl2.relations.IRelation)1 IRelationName (mb.nabl2.relations.IRelationName)1 RelationException (mb.nabl2.relations.RelationException)1 RelationFunctions (mb.nabl2.relations.terms.FunctionName.RelationFunctions)1 IVariantRelation (mb.nabl2.relations.variants.IVariantRelation)1 VariantRelations (mb.nabl2.relations.variants.VariantRelations)1