@Override protected KList apply(KList set, MetaData metaData) { return set.remove(length); } }
@Override public int hashCode() { return var.hashCode(); }
@Override public Term apply(TermCons tc) { if (tc.production().sort().name().equals("RuleContent")) { Term t = new PushTopAmbiguityUp2().apply(tc.get(0)); if (t instanceof Ambiguity) { Ambiguity old = (Ambiguity)t; Set<Term> newTerms = new HashSet<>(); for (Term child : old.items()) { Term newTerm = tc.with(0, child); newTerms.add(newTerm); } return Ambiguity.apply(newTerms); } } return super.apply(tc); }
@Override public Term apply(TermCons tc) { if (tc.production().klabel().isDefined() && tc.production().klabel().get().equals(KLabels.KREWRITE)) { Term t = tc.get(0); if (t instanceof Ambiguity) { Ambiguity old = (Ambiguity)t; Set<Term> newTerms = new HashSet<>(); for (Term child : old.items()) { Term newTerm = tc.with(0, child); newTerms.add(newTerm); } return Ambiguity.apply(newTerms); } } return super.apply(tc); } }
@Override public Either<java.util.Set<ParseFailedException>, Term> apply(Ambiguity amb) { // if the ambiguity has rewrites at the top, prefer them, and eliminate the rest scala.collection.Set<Term> rewrites = amb.items().stream().filter(o -> o instanceof TermCons && ((TermCons) o).production().klabel().isDefined() && ((TermCons) o).production().klabel().get().name().equals("#KRewrite")).collect(Collections.toSet()); if (rewrites.size() == 0 || rewrites.size() == amb.items().size()) return super.apply(amb); if (rewrites.size() == 1) return Right.apply(rewrites.head()); return super.apply(Ambiguity.apply(mutable(rewrites))); }
public Term apply(Ambiguity a) { Set<Production> productions = new HashSet<>(); for (Term t : a.items()) { if (t instanceof TermCons) { TermCons tc = (TermCons)t; productions.add(tc.production()); } else { return a; } } Set<Production> candidates = overloads.minimal(productions); Ambiguity result = Ambiguity.apply(a.items().stream().filter(t -> candidates.contains(((ProductionReference)t).production())).collect(Collectors.toSet())); if (result.items().size() == 1) { return result.items().iterator().next(); } return result; } }
@Test public void testKList() throws Exception { assertCleanup(Ambiguity.apply(KList.apply(ConsPStack.singleton(foo))), foo); }
protected Term apply(KList klist, MetaData metaData) { Term term; Location loc = new Location(metaData.start.line, metaData.start.column, metaData.end.line, metaData.end.column); Source source = metaData.source; if (isToken) { String value = metaData.input.subSequence(metaData.start.position, metaData.end.position).toString(); term = Constant.apply(value, label, Optional.of(loc), Optional.of(source)); } else if (needsLabel) { term = TermCons.apply(klist.items(), label, loc, source); } else { return klist; } return term; } }
@Override public Term apply(TermCons tc) { if (tc.production().att().contains("bracket") || tc.production().klabel().get().name().equals("#SyntacticCast") || tc.production().klabel().get().name().equals("#InnerCast") || tc.production().klabel().get().name().equals("#OuterCast")) { return apply(tc.get(0)); } return super.apply(tc); } }
@Test public void testAmb2() throws Exception { Ambiguity two = Ambiguity.apply(foo, bar); assertCleanup(two, two); }
public static boolean isFunctionRule(TermCons tc) { if (tc.production().sort().name().equals("RuleContent")) { ProductionReference child = (ProductionReference) tc.get(0); if (child.production().klabel().isDefined() && child.production().klabel().get().equals(KLabels.KREWRITE)) { child = (ProductionReference)((TermCons)child).get(0); } return child.production().att().contains(Attribute.FUNCTION_KEY); } return false; }
static Term visitPolyChildrenSafe(TermCons tc, Function<Term, Term> apply) { for (int i : getPolyChildren(tc)) { apply.apply(tc.get(i - 1)); } return tc; }
/** * Remove KList artifacts from parsing only when it contains a single element. */ @Override public Either<Set<ParseFailedException>, Term> apply(KList node) { Either<Set<ParseFailedException>, Term> res = super.apply(node); if (res.isRight() && ((KList) res.right().get()).items().size() == 1) return Right.apply(((KList) res.right().get()).items().get(0)); else return res; } }
public VarInfo(Constant varOcc, Sort sort, VarType varType) { this.varKey = getVarKey(varOcc); this.sort = sort; this.loc = varOcc.location().orElse(null); this.varType = varType; }
public boolean isAnyVar() { return var.value().equals(ResolveAnonVar.ANON_VAR.name()); } }
@Override public Either<java.util.Set<ParseFailedException>, Term> apply(Ambiguity amb) { // if the ambiguity has KSeq at the top, prefer them, and eliminate the rest scala.collection.Set<Term> rewrites = amb.items().stream().filter(o -> o instanceof TermCons && ((TermCons) o).production().klabel().isDefined() && ((TermCons) o).production().klabel().get().name().equals("#KSequence")).collect(Collections.toSet()); if (rewrites.size() == 0 || rewrites.size() == amb.items().size()) return super.apply(amb); if (rewrites.size() == 1) return Right.apply(rewrites.head()); return super.apply(Ambiguity.apply(mutable(rewrites))); }
@Test public void testAmb() throws Exception { assertCleanup(Ambiguity.apply(foo), foo); }