public Tuple2<Either<java.util.Set<ParseFailedException>, Term>, java.util.Set<VarInfo>> apply(TermCons tc) { if (hasPolySort(tc)) { return visitPolyChildrenSets(tc, this::apply); } return simpleResult(tc); }
public Term apply(TermCons tc) { if (hasPolySort(tc)) { return visitPolyChildrenSafe(tc, this::apply); } return tc; }
private List<Term> lowerKList(Term listTerm) { List<Term> items = new ArrayList<>(); lowerKListAcc(listTerm, items); return items; }
public static Term disambiguateForUnparse(Module mod, Term ambiguity) { Term rez3 = new PushTopAmbiguityUp().apply(ambiguity); Either<Set<ParseFailedException>, Term> rez = new ApplyTypeCheckVisitor(mod.subsorts()).apply(rez3); Tuple2<Either<Set<ParseFailedException>, Term>, Set<ParseFailedException>> rez2; if (rez.isLeft()) { rez2 = new AmbFilter(false).apply(rez3); return rez2._1().right().get(); } rez2 = new VariableTypeInferenceFilter(mod.subsorts(), mod.definedSorts(), mod.productionsFor(), false, false).apply(rez.right().get()); if (rez2._1().isLeft()) { rez2 = new AmbFilter(false).apply(rez.right().get()); return rez2._1().right().get(); } rez3 = new PushAmbiguitiesDownAndPreferAvoid(mod.overloads()).apply(rez2._1().right().get()); rez2 = new AmbFilter(false).apply(rez3); return rez2._1().right().get(); } }
private void parseTerm(String term, String sort, K expected) { parseTerm(term, sort, expected, 0); }
public Either<java.util.Set<ParseFailedException>, Term> apply(TermCons tc) { if (hasPolySort(tc)) { return visitPolyChildren(tc, this::apply); } return Right.apply(tc); }
@Test public void testConstant() throws Exception { assertCleanup(foo, foo); }
static Term visitPolyChildrenSafe(TermCons tc, Function<Term, Term> apply) { for (int i : getPolyChildren(tc)) { apply.apply(tc.get(i - 1)); } return tc; }
@Test public void testEmptyList1() { parseTerm(".As", "As", NIL); }
@Test public void testAmb2() throws Exception { Ambiguity two = Ambiguity.apply(foo, bar); assertCleanup(two, two); }
@Test public void testConcreteTop() { parseTerm(".As", "As", NIL); parseTerm("a,a", "As", KApply(CONS, A, KApply(CONS, A, NIL))); parseTerm("a,.As", "As", KApply(CONS, A, NIL)); parseTerm("a,b", "As", KApply(CONS, A, KApply(CONS, B, NIL))); parseTerm("b,.Bs", "As", KApply(CONS, B, NIL)); parseTerm("b,b", "As", KApply(CONS, B, KApply(CONS, B, NIL))); }
@Test public void testArgumentLabeledNilSub1() { parseTerm("h(`.List{\"_,__TEST\"}`(.KList))", "K", KApply(H, NIL)); }
@Test public void testArgumentLabeledNil() { parseTerm("f(`.List{\"_,__TEST\"}`(.KList))", "K", KApply(F, NIL)); }
@Test public void testConcreteArgument() { parseTerm("f(.As)", "K", KApply(F, NIL)); parseTerm("f(a)", "K", KApply(F, KApply(CONS, A, NIL))); parseTerm("f(a,a)", "K", KApply(F, KApply(CONS, A, KApply(CONS, A, NIL)))); parseTerm("f(a,.As)", "K", KApply(F, KApply(CONS, A, NIL))); parseTerm("f(a,b)", "K", KApply(F, KApply(CONS, A, KApply(CONS, B, NIL)))); parseTerm("f(b,.Bs)", "K", KApply(F, KApply(CONS, B, NIL))); parseTerm("f(b,b)", "K", KApply(F, KApply(CONS, B, KApply(CONS, B, NIL)))); }
@Test public void testLabedFunConcreteArgument() { parseTerm("`f`(.As)", "K", KApply(F, NIL)); parseTerm("`f`((a,a))", "K", KApply(F, KApply(CONS, A, KApply(CONS, A, NIL)))); parseTerm("`f`((a,.As))", "K", KApply(F, KApply(CONS, A, NIL))); parseTerm("`f`((a,b))", "K", KApply(F, KApply(CONS, A, KApply(CONS, B, NIL)))); parseTerm("`f`((b,.Bs))", "K", KApply(F, KApply(CONS, B, NIL))); parseTerm("`f`((b,b))", "K", KApply(F, KApply(CONS, B, KApply(CONS, B, NIL)))); }
@Test public void testArgumentLabeledConsSub2() { // gets a warning because the argument of sort As does not fit.n parseTerm("h(`_,__TEST`(a,.As))", "K", KApply(H, KApply(CONS, A, NIL)), 1); }
@Test public void testArgumentInferredListVar() { // 1 warning from inference parseTerm("f(V)", "K", KApply(F, KApply(CAST_AS, KVariable("V"))), 1); }
@Test public void testArgumentAnnItemVar() { parseTerm("f(V:A)", "K", KApply(F, KApply(CONS, KApply(CAST_A, KVariable("V")), NIL))); }
@Test public void testArgumentAnnSubItemVar() { parseTerm("f(V:B)", "K", KApply(F, KApply(CONS, KApply(CAST_B, KVariable("V")), NIL))); } }
@Test public void testArgumentInferredItemVar() { // 1 warning from inference parseTerm("f(V)~>g(V)", "K", KSequence(KApply(F, KApply(CONS, KApply(CAST_A, KVariable("V")), NIL)), KApply(G, KApply(CAST_A, KVariable("V")))), 1); }