/** * Checks whether a lhs pattern is constructor-based, i.e., an application of a * function symbol to a list of constructor terms. * * @param term * @return */ public boolean isConstructorBased(K term) { if (term instanceof KApply) { return ((KApply) term).klist().items().stream().allMatch(this::isConstructorTerm); } if (term instanceof KAs) { return isConstructorBased(((KAs) term).pattern()); } KException.criticalError("Unexpecting isConstructorBased call on " + term.getClass()); return false; }
private boolean isList(K item, boolean klist, boolean rhs, VarInfo vars, boolean anywhereRule) { return !klist && ((item instanceof KVariable && getSortOfVar((KVariable)item, vars).equals("K")) || item instanceof KSequence || (item instanceof KAs && isList(((KAs) item).alias(), klist, rhs, vars, anywhereRule)) || (item instanceof KApply && (functions.contains(((KApply) item).klabel()) || (((anywhereKLabels.contains(((KApply) item).klabel()) && !anywhereRule) || ((KApply) item).klabel() instanceof KVariable) && rhs)))) && !(!rhs && item instanceof KApply && collectionFor.containsKey(((KApply) item).klabel())); }
public DefaultMutableTreeNode apply(KAs k) { DefaultMutableTreeNode pattern = apply(k.pattern()); DefaultMutableTreeNode alias = apply(k.alias()); if (pattern.isLeaf() && alias.isLeaf()) { String text = ToKast.apply(k); if (text.length() < 80) { return new DefaultMutableTreeNode(text); } } DefaultMutableTreeNode node = new DefaultMutableTreeNode("#as"); node.add(pattern); node.add(alias); return node; }
@Override public void apply(KApply k) { if (k.klabel().name().equals("<k>")) { if (!hasProblem.booleanValue()) { hasProblem.setTrue(); if (k.klist().items().size() == 1) { if (k.klist().items().get(0) instanceof KSequence) { KSequence seq = (KSequence) k.klist().items().get(0); if (seq.items().size() >= 1) { K head = seq.items().get(0); while (head instanceof KAs) { head = ((KAs) head).pattern(); } if (head instanceof KApply) { KApply app = (KApply) head; if (!(app.klabel() instanceof KVariable)) { if (!rhs || (!functions.contains(app.klabel()) && !anywhereKLabels.contains(app.klabel()))) { nextOps.add(app.klabel()); hasProblem.setFalse(); } } } } } } } } super.apply(k); } }.apply(side);
K head = kCell.items().get(0); while (head instanceof KAs) { head = ((KAs) head).pattern();
private Sort sort(K k) { if (k instanceof KSequence) return Sorts.K(); if (k instanceof KAs) return sort(((KAs) k).pattern()); if (k instanceof InjectedKLabel) return Sorts.KItem(); if (k instanceof KToken) return ((KToken) k).sort(); if (k instanceof KApply) return k.att().get(Production.class).sort(); if (k instanceof KVariable) return Sorts.K(); throw KEMException.compilerError("Could not compute sort of term", k); }