public Set<org.kframework.definition.Sentence> apply(PriorityExtended pe) { Seq<scala.collection.Set<Tag>> seqOfSetOfTags = immutable(pe.getPriorityBlocks() .stream().map(block -> toTags(block.getProductions(), pe)) .collect(Collectors.toList())); return Sets.newHashSet(SyntaxPriority(seqOfSetOfTags)); }
public Module resolve(Module m) { module = m; funProds.clear(); funRules.clear(); Set<Sentence> newSentences = stream(m.localSentences()).map(this::resolve).collect(Collectors.toSet()); newSentences.addAll(funProds); newSentences.addAll(funRules); return Module(m.name(), m.imports(), immutable(newSentences), m.att()); } }
public scala.collection.Set<Tag> toTags(List<Tag> labels, ASTNode loc) { return immutable(labels.stream().flatMap(l -> { java.util.Set<Production> productions = context.tags.get(l.name()); if (productions.isEmpty()) throw KEMException.outerParserError("Could not find any productions for tag: " + l.name(), loc.getSource(), loc.getLocation()); return productions.stream().map(p -> Tag(p.getKLabel(kore))); }).collect(Collectors.toSet())); }
public org.kframework.definition.Definition apply(Definition d) { // Set<org.kframework.definition.Require> requires = d.getItems().stream() // .filter(i -> i instanceof Require).map(i -> apply((Require) i)) // .collect(Collectors.toSet()); Set<Module> kilModules = d.getItems().stream().filter(i -> i instanceof Module) .map(mod -> (Module) mod).collect(Collectors.toSet()); Module mainModule = kilModules.stream() .filter(mod -> mod.getName().equals(d.getMainModule())).findFirst().get(); HashMap<String, org.kframework.definition.Module> koreModules = new HashMap<>(); apply(mainModule, kilModules, koreModules); // Set<org.kframework.definition.Module> modules = kilModules.map(i -> // apply((Module) i)) // .collect(Collectors.toSet()); // TODO: handle LiterateDefinitionComments return Definition( koreModules.get(mainModule.getName()), immutable(new HashSet<>(koreModules.values())), Att()); }
public org.kframework.definition.Definition loadDefinition( String mainModuleName, String syntaxModuleName, String definitionText, File source, File currentDirectory, List<File> lookupDirectories, boolean autoImportDomains, boolean kore) { return loadDefinition(mainModuleName, syntaxModuleName, definitionText, Source.apply(source.getAbsolutePath()), currentDirectory, lookupDirectories, autoImportDomains, kore); }
private static Module excludeModulesByTag(Set<String> excludedModuleTags, Module mod) { Set<Module> newImports = stream(mod.imports()).filter(_import -> excludedModuleTags.stream().noneMatch(tag -> _import.att().contains(tag))).collect(Collectors.toSet()); return Module(mod.name(), immutable(newImports), mod.localSentences(), mod.att()); }
public Module resolve(Module input) { Set<Sentence> rulesToAdd = stream(input.sentences()) .filter(s -> s instanceof Context) .map(s -> (Context) s) .flatMap(c -> this.resolve(c, input)).collect(Collectors.toCollection(HashSet::new)); if (!rulesToAdd.isEmpty()) { rulesToAdd.add(SyntaxSort(Sorts.K())); } return Module(input.name(), input.imports(), (scala.collection.Set<Sentence>) stream(input.localSentences()).filter(s -> !(s instanceof Context)).collect(Collections.toSet()).$bar(immutable(rulesToAdd)), input.att()); }
public static scala.collection.Set<UserList> apply(scala.collection.Set<Sentence> sentences) { return Collections.immutable(getLists(Collections.mutable(sentences))).toSet(); }
public static scala.collection.Set<UserList> apply(scala.collection.Set<Sentence> sentences) { return Collections.immutable(getLists(Collections.mutable(sentences))).toSet(); }
private KLabel computePolyKLabel(KApply k) { List<Set<Integer>> poly = polyKLabels.get(k.klabel().name()); List<Sort> params = new ArrayList<>(); for (Set<Integer> positions : poly) { int pos = positions.iterator().next(); Sort sort; if (pos == 0) { sort = k.att().get(Sort.class); } else { sort = k.items().get(pos-1).att().get(Sort.class); } params.add(sort); } return KLabel(k.klabel().name(), immutable(params)); }
public static Function1<Definition, Definition> excludeModulesByTag(Set<String> excludedModuleTags) { DefinitionTransformer dt = DefinitionTransformer.from(mod -> excludeModulesByTag(excludedModuleTags, mod), "remove modules based on attributes"); return dt.andThen(d -> Definition(d.mainModule(), immutable(stream(d.entryModules()).filter(mod -> excludedModuleTags.stream().noneMatch(tag -> mod.att().contains(tag))).collect(Collectors.toSet())), d.att())); }
public org.kframework.definition.Definition loadDefinition( String mainModuleName, String syntaxModuleName, String definitionText, Source source, File currentDirectory, List<File> lookupDirectories, boolean autoImportDomains, boolean kore) { Set<Module> previousModules = new HashSet<>(); Set<File> requiredFiles = new HashSet<>(); if (autoImportDomains) previousModules.addAll(loadModules(new HashSet<>(), Kompile.REQUIRE_PRELUDE_K, source, currentDirectory, lookupDirectories, requiredFiles, kore)); Set<Module> modules = loadModules(previousModules, definitionText, source, currentDirectory, lookupDirectories, requiredFiles, kore); modules.addAll(previousModules); // add the previous modules, since load modules is not additive Module mainModule = getMainModule(mainModuleName, modules); Optional<Module> opt; opt = modules.stream().filter(m -> m.name().equals(syntaxModuleName)).findFirst(); Module syntaxModule; if (!opt.isPresent()) { kem.registerCompilerWarning("Could not find main syntax module with name " + syntaxModuleName + " in definition. Use --syntax-module to specify one. Using " + mainModuleName + " as default."); syntaxModule = mainModule; } else { syntaxModule = opt.get(); } return org.kframework.definition.Definition.apply(mainModule, immutable(modules), Att().add(Att.syntaxModule(), syntaxModule.name())); }
public Module resolve(Module input) { Set<Sentence> contextsToAdd = resolve(stream(input.localSentences()) .filter(s -> s instanceof Production) .map(s -> (Production) s) .filter(p -> p.att().contains("strict") || p.att().contains("seqstrict")).collect(Collectors.toSet())); return Module(input.name(), input.imports(), (scala.collection.Set<Sentence>) input.localSentences().$bar(immutable(contextsToAdd)), input.att()); } }
K replacementTerm() { getSplit(var); KLabel fragmentLabel = cfg.getCellFragmentLabel(parentCell); if (fragmentLabel == null) { throw KEMException.compilerError("Unsupported cell fragment with types: " + remainingCells, var); } List<Sort> children = cfg.getChildren(parentCell); List<K> arguments = new ArrayList<>(children.size()); for (Sort child : children) { K arg = split.get(child); if (arg == null) { if (cfg.getMultiplicity(child) == Multiplicity.ONE) { arg = cfg.getCellAbsentTerm(child); } else { arg = cfg.cfg.getUnit(child); } } assert arg != null; arguments.add(arg); } return KApply(fragmentLabel, immutable(arguments)); }
private Production resolve(Production prod) { if (kore && prod.klabel().isDefined() && prod.klabel().get().equals(KLabels.GENERATED_TOP_CELL)) { List<ProductionItem> pis = stream(prod.items()).collect(Collectors.toCollection(ArrayList::new)); int idx = 0; int i = 0; for (ProductionItem pi : pis) { if (pi instanceof NonTerminal) { idx = i; } i++; } pis.add(idx, NonTerminal(Sorts.GeneratedCounterCell())); return Production(prod.klabel().get(), prod.sort(), immutable(pis), prod.att()); } return prod; }
private Production funProd(KLabel fun, K k) { List<ProductionItem> pis = new ArrayList<>(); K left = RewriteToTop.toLeft(k); K right = RewriteToTop.toRight(k); pis.add(Terminal(fun.name())); pis.add(Terminal("(")); pis.add(NonTerminal(sort(left))); for (KVariable var : closure(k)) { pis.add(Terminal(",")); pis.add(NonTerminal(var.att().getOptional(Sort.class).orElse(Sorts.K()))); } pis.add(Terminal(")")); return Production(fun, sort(right), immutable(pis), Att().add("function")); }
public static Definition addSemanticsModule(Definition d) { java.util.Set<Module> allModules = mutable(d.modules()); Module languageParsingModule = Constructors.Module("LANGUAGE-PARSING", Set(d.mainModule(), d.getModule(d.att().get(Att.syntaxModule())).get(), d.getModule("K-TERM").get(), d.getModule(RuleGrammarGenerator.ID_PROGRAM_PARSING).get()), Set(), Att()); allModules.add(languageParsingModule); return Constructors.Definition(d.mainModule(), immutable(allModules), d.att()); }
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()); } }