private boolean isInternalKLabel(String name, Module m) { return name.startsWith("#SemanticCastTo") || internalNames.contains(name) || (name.startsWith("is") && m.definedSorts().apply(Outer.parseSort(name.substring(2)))); } }
private static List<List<Sort>> makeAllSortTuples(int size, Module mod) { List<List<Sort>> res = new ArrayList<>(); List<Sort> allSorts = stream(mod.definedSorts()).filter(s -> !isParserSort(s)).collect(Collectors.toList()); makeAllSortTuples(size, size, allSorts, res, new int[size]); return res; }
public Subsorts(Module module) { sorts = JavaConversions.asJavaCollection(module.definedSorts()).stream() .map(Sort::of) .collect(Collectors.toSet()); this.subsort = ArrayTable.create(sorts, sorts); for (org.kframework.kore.Sort sort1 : Collections.iterable(module.definedSorts())) { for (org.kframework.kore.Sort sort2 : Collections.iterable(module.definedSorts())) { subsort.put( Sort.of(sort1), Sort.of(sort2), module.subsorts().$greater(sort1, sort2)); } } }
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; }
public Module gen(Module mod) { this.mod = mod; predicateRules = stream(mod.rules()).filter(this::isPredicate).collect(Collectors.toSet()); return Module(mod.name(), mod.imports(), (Set<Sentence>) mod.localSentences().$bar(stream(mod.definedSorts()) .flatMap(this::gen).collect(Collections.toSet())), mod.att()); }
"%}\n\n" + "%%\n\n"); if (this.module.definedSorts().contains(Sorts.Layout())) { flex.append(this.module.layout() + " ;\n");
public void initialize() { disambModule.definedSorts(); disambModule.subsorts(); disambModule.priorities(); disambModule.leftAssoc(); disambModule.rightAssoc(); disambModule.productionsFor(); disambModule.overloads(); }
public static Module subsortKItem(Module module) { java.util.Set<Sentence> prods = new HashSet<>(); for (Sort srt : iterable(module.definedSorts())) { if (!RuleGrammarGenerator.isParserSort(srt)) { // KItem ::= Sort Production prod = Production(Sorts.KItem(), Seq(NonTerminal(srt)), Att()); if (!module.sentences().contains(prod)) { prods.add(prod); } } } if (prods.isEmpty()) { return module; } else { return Module(module.name(), module.imports(), Stream.concat(stream(module.localSentences()), prods.stream()) .collect(org.kframework.Collections.toSet()), module.att()); } }
public String constants() { StringBuilder sb = new StringBuilder(); sb.append("type sort = \n"); Set<Sort> sorts = mutable(mainModule.definedSorts()); sorts.add(Sorts.Bool()); sorts.add(Sorts.Int());
if (! mod.definedSorts().contains(Sorts.Layout())) { modules.add(baseK.getModule(DEFAULT_LAYOUT).get());
private Set<Sort> upperBounds(Collection<Sort> bounds) { Set<Sort> maxs = new HashSet<>(); nextsort: for (Sort sort : iterable(mod.definedSorts())) { // for every declared sort // Sorts at or below KBott, or above K, are assumed to be // sorts from kast.k representing meta-syntax that is not a real sort. // This is done to prevent variables from being inferred as KBott or // as KList. if (mod.subsorts().lessThanEq(sort, Sorts.KBott())) continue; if (mod.subsorts().greaterThan(sort, Sorts.K())) continue; for (Sort bound : bounds) if (!mod.subsorts().lessThanEq(bound, sort)) continue nextsort; maxs.add(sort); } return maxs; }
private K parseConfigVars(KRunOptions options, CompiledDefinition compiledDef) { HashMap<KToken, K> output = new HashMap<>(); for (Map.Entry<String, Pair<String, String>> entry : options.configurationCreation.configVars(compiledDef.getParsedDefinition().mainModule().name(), files).entrySet()) { String name = entry.getKey(); String value = entry.getValue().getLeft(); String parser = entry.getValue().getRight(); String configVarName = "$" + name; Sort sort = compiledDef.configurationVariableDefaultSorts.getOrDefault(configVarName, compiledDef.programStartSymbol); K configVar = externalParse(parser, value, sort, Source.apply("<command line: -c" + name + ">"), compiledDef); output.put(KToken(configVarName, Sorts.KConfigVar()), configVar); } if (compiledDef.kompiledDefinition.mainModule().definedSorts().contains(Sorts.String())) { if (options.io()) { output.put(KToken("$STDIN", Sorts.KConfigVar()), KToken("\"\"", Sorts.String())); output.put(KToken("$IO", Sorts.KConfigVar()), KToken("\"on\"", Sorts.String())); } else { String stdin = getStdinBuffer(tty.stdin); output.put(KToken("$STDIN", Sorts.KConfigVar()), KToken(StringUtil.enquoteKString(stdin), Sorts.String())); output.put(KToken("$IO", Sorts.KConfigVar()), KToken("\"off\"", Sorts.String())); } } if (options.global.debug) { // on the critical path, so don't perform this check because it's slow unless we're debugging. checkConfigVars(output.keySet(), compiledDef); } return plugConfigVars(compiledDef, output); }
stream(mainModule.definedSorts()).filter(s -> mainModule.subsorts().greaterThanEq(predicateSort, s)).distinct() .filter(sort -> mainModule.sortAttributesFor().contains(sort)).forEach(sort -> { String sortHook = mainModule.sortAttributesFor().apply(sort).<String>getOptional("hook").orElse("");
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()); } }
stream(mod.definedSorts()).filter(s -> mod.subsorts().lessThanEq(s, sort)).forEach(subsort -> { MutableBoolean isProtecting = new MutableBoolean(true); stream(mod.definedSorts()).filter(s -> mod.subsorts().lessThanEq(s, subsort)).forEach(candidateSort -> { if (predicateRules.stream().filter(r -> isPredicateFor(r, candidateSort)).findAny().isPresent()) { stream(mod.definedSorts()).filter(s -> mod.subsorts().lessThanEq(s, sort)).distinct().forEach(s -> { res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KApply(KLabel("#KToken"), KToken(s.toString(), Sorts.KString()), KVariable("_"))), BooleanUtils.TRUE), BooleanUtils.TRUE,
Map<String, Boolean> attributes = new HashMap<>(); sb.append("\n"); for (Sort sort : iterable(module.definedSorts())) { Att att = module.sortAttributesFor().get(sort).getOrElse(() -> KORE.Att()); collectAttributes(attributes, att); collectionSorts.add("LIST.List"); collectionSorts.add("ARRAY.Array"); for (Sort sort : iterable(module.definedSorts())) { if (sort.equals(Sorts.K()) || sort.equals(Sorts.KItem())) { continue; for (Sort sort : iterable(module.definedSorts())) { sb.append(" axiom{} "); boolean hasToken = false; for (Sort s : iterable(module.definedSorts())) { if (module.subsorts().lessThan(s, sort)) { numTerms++;
for (Sort srt : iterable(mod.definedSorts())) { if (!isParserSort(srt)) { Set<Sentence> prods3 = new HashSet<>(); for (Sort srt : iterable(mod.definedSorts())) { if (!isParserSort(srt) && !mod.listSorts().contains(srt)) {
if (rez.isLeft()) return new Tuple2<>(rez, warn); Tuple2<Either<Set<ParseFailedException>, Term>, Set<ParseFailedException>> rez2 = new VariableTypeInferenceFilter(disambModule.subsorts(), disambModule.definedSorts(), disambModule.productionsFor(), strict && inferSortChecks, true).apply(rez.right().get()); if (rez2._1().isLeft()) return rez2;
public static Term disambiguateForUnparse(Module mod, Term ambiguity) { Term rez3 = new PushTopAmbiguityUp().apply(ambiguity); Either<Set<ParseFailedException>, Term> rez = new ApplyTypeCheckVisitor(mod.subsorts()).apply(rez3); Tuple2<Either<Set<ParseFailedException>, Term>, Set<ParseFailedException>> rez2; if (rez.isLeft()) { rez2 = new AmbFilter(false).apply(rez3); return rez2._1().right().get(); } rez2 = new VariableTypeInferenceFilter(mod.subsorts(), mod.definedSorts(), mod.productionsFor(), false, false).apply(rez.right().get()); if (rez2._1().isLeft()) { rez2 = new AmbFilter(false).apply(rez.right().get()); return rez2._1().right().get(); } rez3 = new PushAmbiguitiesDownAndPreferAvoid(mod.overloads()).apply(rez2._1().right().get()); rez2 = new AmbFilter(false).apply(rez3); return rez2._1().right().get(); } }