public static Set<KLabel> filteredMapConstructors(Module m) { return stream(m.productions()) .filter(p -> p.att().contains(Attribute.ASSOCIATIVE_KEY) && p.att().contains("filterElement")) .map(p -> p.klabel().get()) .distinct() .collect(Collectors.toSet()); }
for (Production p : iterable(mainModule.productions())) { if (p.att().contains(Attribute.FUNCTION_KEY)) { functions.add(p.klabel().get());
collectAttributes(attributes, att); for (Production prod : iterable(module.productions())) { Att att = prod.att(); collectAttributes(attributes, att); for (Production prod : iterable(module.productions())) { prod = computePolyProd(prod); if (prod.klabel().isEmpty()) { for (Production prod : iterable(module.productions())) { prod = computePolyProd(prod); if (prod.isSubsort()) {
public static Grammar getGrammar(Module module, Scanner scanner) { Automaton.setMinimization(Automaton.MINIMIZE_BRZOZOWSKI); Grammar grammar = new Grammar(); Set<String> rejects = new HashSet<>(); Set<Sort> sorts = Stream.concat(stream(module.definedSorts()), stream(module.usedCellSorts())).collect(Collectors.toSet()); // create a NonTerminal for every declared sort for (Sort sort : sorts) { grammar.add(grammar.new NonTerminal(sort.toString())); } stream(module.productions()).forEach(p -> collectRejects(p, rejects)); stream(module.productions()).collect(Collectors.groupingBy(p -> p.sort())).entrySet().stream().sorted(Comparator.comparing(e2 -> e2.getKey().toString())).forEach(e -> processProductions(e.getKey(), e.getValue(), grammar, rejects, scanner)); grammar.compile(scanner); return grammar; }
stream(mod.productions()).filter(p -> p.sort().equals(candidateSort) && p.klabel().isDefined()).forEach(candidateProduction -> { stream(mod.productions()).filter(p -> mod.subsorts().lessThanEq(p.sort(), sort)).filter(p -> nonProtectingSubsorts.contains(p.sort())).distinct().forEach(p -> { if (p.klabel().isDefined() && !p.att().contains(Attribute.FUNCTION_KEY)) { List<K> klist = new ArrayList<>();
private boolean equalsSyntax(Module _this, Module that) { if (!_this.productions().equals(that.productions())) return false; if (!_this.priorities().equals(that.priorities())) return false; if (!_this.leftAssoc().equals(that.leftAssoc())) return false; if (!_this.rightAssoc().equals(that.rightAssoc())) return false; return _this.sortDeclarations().equals(that.sortDeclarations()); }
private Rule getExitCodeRule(Definition parsedDefinition) { Module mainMod = parsedDefinition.mainModule(); Set<Production> exitProds = stream(mainMod.productions()).filter(p -> p.att().contains("exit")).collect(Collectors.toSet()); if (exitProds.size() == 0) { return null; } else if (exitProds.size() > 1) { throw KEMException.compilerError("Found more than one or zero productions with 'exit' attribute. Exactly one production, a cell, must have this attribute, designating the exit code of krun. Found:\n" + exitProds); } Production exitProd = exitProds.iterator().next(); return Rule(IncompleteCellUtils.make(exitProd.klabel().get(), false, KApply(KLabel("#SemanticCastToInt"), KVariable("_")), false), BooleanUtils.TRUE, BooleanUtils.TRUE); }
private boolean containsThreadCell(CompiledDefinition def) { return stream(def.executionModule().productions()) .anyMatch(p -> (p.att().contains("thread") && p.att().contains("cell"))); } public void initialize(CompiledDefinition def) {
public static Map<KLabel, KLabel> collectionFor(Module m) { return stream(m.productions()).filter(p -> p.att().contains(Attribute.ASSOCIATIVE_KEY)).flatMap(p -> { Set<Tuple2<KLabel, KLabel>> set = new HashSet<>(); set.add(Tuple2.apply(p.klabel().get(), p.klabel().get())); if (p.att().contains(Attribute.UNIT_KEY)) { set.add(Tuple2.apply(KLabel(p.att().<String>get(Attribute.UNIT_KEY)), p.klabel().get())); } if (p.att().contains("element")) { set.add(Tuple2.apply(KLabel(p.att().<String>get("element")), p.klabel().get())); } if (p.att().contains("wrapElement")) { set.add(Tuple2.apply(KLabel(p.att().<String>get("wrapElement")), p.klabel().get())); } return set.stream(); }).distinct().collect(Collectors.toMap(Tuple2::_1, Tuple2::_2)); }
Optional<Production> collectionProduction = stream(module.productions()) .filter(p -> p.att().contains("cellCollection") && p.sort().equals(realSort)) .findAny();
public static Map<KLabel, KLabel> collectionFor(Module m) { return stream(m.productions()).filter(p -> p.att().contains(Attribute.ASSOCIATIVE_KEY)).flatMap(p -> { Set<Tuple2<KLabel, KLabel>> set = new HashSet<>(); set.add(Tuple2.apply(p.klabel().get(), p.klabel().get())); if (p.att().contains(Attribute.UNIT_KEY)) { set.add(Tuple2.apply(KLabel(p.att().get(Attribute.UNIT_KEY)), p.klabel().get())); } if (p.att().contains("element")) { set.add(Tuple2.apply(KLabel(p.att().get("element")), p.klabel().get())); } if (p.att().contains("filterElement")) { set.add(Tuple2.apply(KLabel(p.att().get("filterElement")), p.klabel().get())); } if (p.att().contains("wrapElement")) { set.add(Tuple2.apply(KLabel(p.att().get("wrapElement")), p.klabel().get())); } return set.stream(); }).distinct().collect(Collectors.toMap(Tuple2::_1, Tuple2::_2)); }
Map<String, Integer> terminals = new HashMap<>(); int idx = 0; for (Production p : iterable(module.productions())) { for (ProductionItem pi : iterable(p.items())) { if (pi instanceof TerminalLike) {
private Map<String, DataStructureSort> getDataStructureSorts(Module module) { ImmutableMap.Builder<String, DataStructureSort> builder = ImmutableMap.builder(); for (org.kframework.definition.Production prod : iterable(module.productions())) { Optional<?> assoc = prod.att().getOptional(Attribute.ASSOCIATIVE_KEY); Optional<?> comm = prod.att().getOptional(Attribute.COMMUTATIVE_KEY);
public Module gen(Module mod) { Set<Sentence> res = new HashSet<>(); for (Sort sort : iterable(mod.definedSorts())) { Production prod = Production(KLabel("is" + sort.toString()), Sorts.Bool(), Seq(Terminal("is" + sort.toString()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add(Attribute.FUNCTION_KEY).add(Attribute.PREDICATE_KEY, Sort.class, sort)); if (!mod.productions().contains(prod)) res.add(prod); } if (!res.isEmpty()) { res.add(SyntaxSort(Sorts.K())); } return Module(mod.name(), mod.imports(), (scala.collection.Set<Sentence>) mod.localSentences().$bar(immutable(res)), mod.att()); } }
Set<Sentence> importedConfigurationSortsSubsortedToCell = stream(inputModule.productions()) .filter(p -> p.att().contains("cell")) .map(p -> Production(Sorts.Cell(), Seq(NonTerminal(p.sort())))).collect(Collections.toSet());
for (Production p : iterable(mod.productions())) { if (p.isPrefixProduction()) { prods.addAll(mutable(p.recordProductions())); for (Production p : iterable(mod.productions())) { if (p.att().contains("poly")) { List<Set<Integer>> positions = computePositions(p);