public static boolean isParserSort(Sort s) { return kSorts.contains(s) || s.name().startsWith("#"); }
private boolean isExceptionSort(Sort srt) { return kSorts.contains(srt) || srt.name().startsWith("#"); }
private String getPrefixLabel(boolean kore) { String label = ""; List<String> sorts = new ArrayList<>(); for (ProductionItem pi : items) { if (pi instanceof NonTerminal) { label += "_"; sorts.add(((NonTerminal) pi).getSort().name()); } else if (pi instanceof Terminal) { label += ((Terminal) pi).getTerminal(); } else if (pi instanceof UserList) { label += "_" + ((UserList) pi).separator + "_"; sorts.add(((UserList) pi).sort.name()); sorts.add(sort.name()); } } return label + "_" + ownerModuleName + (kore ? "_" + sorts.stream().reduce("", (s1, s2) -> s1 + "_" + s2) : ""); }
/** * Gets the corresponding {@code Sort} from its {@code String} * representation. * * @param name * the name of the sort * @return the sort */ public static Sort of(org.kframework.kore.Sort sort) { return cache.computeIfAbsent(sort.toString(), s -> new Sort(sort.name(), sort.params(), maxOrdinal.getAndIncrement())); }
private void check(Production p) { if (p.att().contains(Attribute.CELL_KEY)) { for (ProductionItem i : mutable(p.items())) { if (i instanceof NonTerminal) { Sort sort = ((NonTerminal) i).sort(); if (sort.name().endsWith("Cell")) { if (cells.contains(sort)) { Production cell = new ConfigurationInfoFromModule(module).cellProductionsFor().get(sort).get().head(); errors.add(KEMException.compilerError("Cell " + cell.klabel().get() + " found twice in configuration.", p)); } cells.add(sort); } } } } } }
/** * Returns the KLabel for the list terminator. * Constructed as '.List{"<list_klabel>"} * Should be called only if isListDecl is true. * @return String representation of the separator KLabel. */ public String getTerminatorKLabel(boolean kore) { assert isListDecl(); return ".List{" + StringUtil.enquoteCString(getKLabel(kore)) + "}" + (kore ? "_" + getSort().name() : ""); }
@Override public K apply(KApply k0) { if (hasCells(k0)) { ArrayList<K> klist0 = new ArrayList<K>(Collections.nCopies(k0.klist().size(), null)); for (int idx = 0; idx < k0.klist().size(); idx++) { K item0 = k0.klist().items().get(idx); klist0.set(idx, item0); if (item0 instanceof KApply) { KApply k = (KApply) item0; if (k.klabel().name().equals("#cells")) { if (cellFragmentVarsCell.contains(k)) { Sort cellFragmentSort = nthArgSort(k0.klabel(), idx); if (cellFragmentSort == null) { throw new IllegalArgumentException("Not found " + idx + "th argument sort of " + k0.klabel()); } if (cellFragmentSort.name().endsWith("Fragment")) { Sort cellSort = Sort(cellFragmentSort.name().substring(0,cellFragmentSort.name().indexOf("Fragment"))); KLabel cellLabel = cfg.cfg.getCellLabel(cellSort); klist0.set(idx, KApply(cellLabel, KList(item0), Att().add("dummy_cell"))); } } } } } return KApply(k0.klabel(), KList(klist0), k0.att()); } return super.apply(k0); } @Override
@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); }
private Stream<? extends Sentence> genKore(Sort sort) { if (sort.equals(Sorts.K())) { return Stream.of(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable("K")), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); } else { List<Sentence> res = new ArrayList<>(); res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable(sort.name(), Att().add(Sort.class, sort))), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable("K")), BooleanUtils.FALSE), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add("owise"))); return res.stream(); } }
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; }
@Override public scala.collection.Set<Sort> getCellBagSortsOfCell(Sort k) { return Set(Sort(k.name() + "Bag", k.params())); } }
@Override public K apply(KToken k) { return KToken(k.s(), Sort(k.sort().name(), k.sort().params()), k.att()); }
@Override public K apply(KToken k) { if (lhs) { if (k.sort().equals(Sorts.Int()) || k.sort().equals(Sorts.Float())) { KVariable var = newDotVariable(k.sort()); state.add(KApply(KLabel("_==" + k.sort().name() + "_"), var, k)); return var; } } return super.apply(k); }
if (s instanceof Production) { Production p = (Production) s; if (p.sort().name().startsWith("#")) return p; // don't do anything for such productions since they are advanced features prod1 = Production(ul.terminatorKLabel, Sort(ul.sort.name() + "#Terminator", ul.sort.params()), Seq(Terminal("")), newAtts.remove("format").add(Constants.ORIGINAL_PRD, Production.class, ul.pTerminator)); prod2 = Production(ul.klabel, Sort("Ne#" + ul.sort.name(), ul.sort.params()), Seq(NonTerminal(ul.childSort), Terminal(ul.separator), NonTerminal(Sort("Ne#" + ul.sort.name(), ul.sort.params()))), newAtts.add(Constants.ORIGINAL_PRD, Production.class, ul.pList)); prod3 = Production(ul.klabel, Sort("Ne#" + ul.sort.name(), ul.sort.params()), Seq(NonTerminal(ul.childSort), Terminal(""), NonTerminal(Sort(ul.sort.name() + "#Terminator", ul.sort.params()))), newAtts.add(Constants.ORIGINAL_PRD, Production.class, ul.pList)); prod4 = Production(ul.sort, Seq(NonTerminal(Sort("Ne#" + ul.sort.name(), ul.sort.params())))); prod5 = Production(ul.sort, Seq(NonTerminal(Sort(ul.sort.name() + "#Terminator", ul.sort.params())))); res.add(prod3); res.add(prod4); res.add(SyntaxSort(Sort(ul.sort.name() + "#Terminator", ul.sort.params()))); res.add(SyntaxSort(Sort("Ne#" + ul.sort.name(), ul.sort.params()))); if (!ul.nonEmpty) { res.add(prod5);
fragmentItems.add(Terminal("<"+cellName+">-fragment")); for (Sort childSort : childSorts) { if (!childSort.name().endsWith("Cell")) { Sort childOptSort = Sort(childSort.name()+"Opt", childSort.params()); fragmentItems.add(NonTerminal(childOptSort)); .add(Attribute.ASSOCIATIVE_KEY, "") .add("cellCollection") .add("element", bagSort.name() + "Item") .add("wrapElement", "<" + cellName + ">") .add(Attribute.UNIT_KEY, "." + bagSort.name()) .add(Attribute.HOOK_KEY, type.toUpperCase() + ".concat") .add("avoid") // needed to ensure cell collections are parsed as Bag instead of CellBag Sentence bagElement; if (type.equals("Map")) { bagElement = Production(KLabel(bagSort.name() + "Item"), bagSort, Seq( Terminal(bagSort.name() + "Item"), Terminal("("), NonTerminal(childSorts.get(0)), Terminal(")")), Att().add(Attribute.HOOK_KEY, elementHook).add(Attribute.FUNCTION_KEY)); } else { bagElement = Production(KLabel(bagSort.name() + "Item"), bagSort, Seq( Terminal(bagSort.name() + "Item"), Terminal("("), NonTerminal(sort), Terminal(")")), Att().add(Attribute.HOOK_KEY, elementHook).add(Attribute.FUNCTION_KEY));