private boolean isPriorityWrong(ProductionReference outer, ProductionReference inner) { Tag parentLabel = new Tag(outer.production().klabel().get().name()); Tag localLabel = new Tag(inner.production().klabel().get().name()); if (m.priorities().lessThan(parentLabel, localLabel)) { return true; } if (m.leftAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } if (m.rightAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } return false; }
private boolean isLeftAssoc(ProductionReference outer, ProductionReference inner) { Tag parentLabel = new Tag(outer.production().klabel().get().name()); Tag localLabel = new Tag(inner.production().klabel().get().name()); if (m.leftAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } return false; }
private boolean isRightAssoc(ProductionReference outer, ProductionReference inner) { Tag parentLabel = new Tag(outer.production().klabel().get().name()); Tag localLabel = new Tag(inner.production().klabel().get().name()); if (m.rightAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } return false; }
"%}\n\n" + "%%\n\n"); if (this.module.definedSorts().contains(Sorts.Layout())) { flex.append(this.module.layout() + " ;\n");
boolean needNewScanner = !scanner.getModule().importedModuleNames().contains(module.name()); final Scanner realScanner = needNewScanner ? parser.getScanner() : scanner;
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()); } }
if (! mod.definedSorts().contains(Sorts.Layout())) { modules.add(baseK.getModule(DEFAULT_LAYOUT).get());
public Either<java.util.Set<ParseFailedException>, Term> apply(TermCons tc) { if (tc.production().att().contains("bracket")) return Right.apply(tc); //if (Side.RIGHT == side && !(tc.production().items().apply(0) instanceof NonTerminal)) return Right.apply(tc); //if (Side.LEFT == side && !(tc.production().items().apply(tc.production().items().size() - 1) instanceof NonTerminal)) return Right.apply(tc); Tag parentLabel = new Tag(parent.production().klabel().get().name()); Tag localLabel = new Tag(tc.production().klabel().get().name()); if (priorities.lessThan(parentLabel, localLabel)) { String msg = "Priority filter exception. Cannot use " + localLabel + " as a child of " + parentLabel; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } if (leftAssoc.contains(new Tuple2<>(parentLabel, localLabel)) && Side.RIGHT == side) { String msg = "Associativity filter exception. Cannot use " + localLabel + " as a right child of " + parentLabel; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } if (rigthAssoc.contains(new Tuple2<>(parentLabel, localLabel)) && Side.LEFT == side) { String msg = "Associativity filter exception. Cannot use " + localLabel + " as a left child of " + parentLabel; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } return Right.apply(tc); } }
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); }
ProductionReference child = (ProductionReference) items.next(); Sort childSort = getSort(child); if (listSorts.contains(expectedSort) && !(subsorts.lessThanEq(childSort, expectedSort) && listSorts.contains(childSort))) { final boolean isBracket = child.production().att().contains("bracket"); if (isBracket
@Override public Either<Set<ParseFailedException>, Term> apply(TermCons tc) { if (overloads.elements().contains(tc.production()) && tc.items().isEmpty()) { Set<Production> candidates = stream(overloads.elements()).filter(p -> p.klabel().isDefined() && p.klabelAtt().equals(tc.production().klabelAtt()) && overloads.lessThanEq(p, tc.production())).collect(Collectors.toSet()); candidates = overloads.minimal(candidates); if (candidates.size() != 1) { KException ex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.INNER_PARSER, "Overloaded term does not have a least sort. Possible sorts: " + candidates, tc.source().orElse(null), tc.location().orElse(null)); return Left.apply(Sets.newHashSet(new ParseFailedException(ex))); } Production prod = candidates.iterator().next(); prod = Production(prod.klabel(), prod.sort(), prod.items(), prod.att().add("originalPrd", Production.class, tc.production())); return super.apply(TermCons.apply(tc.items(), prod, tc.location(), tc.source())); } return super.apply(tc); } }
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()); } }
private boolean isPriorityWrong(ProductionReference outer, ProductionReference inner, int position) { if (outer.production().klabel().isEmpty() || inner.production().klabel().isEmpty()) { return false; } Tag parentLabel = new Tag(outer.production().klabel().get().name()); Tag localLabel = new Tag(inner.production().klabel().get().name()); if (!m.subsorts().lessThanEq(inner.production().sort(), ((NonTerminal)outer.production().items().apply(position)).sort())) { return true; } if (m.priorities().lessThan(parentLabel, localLabel)) { return true; } if (m.leftAssoc().contains(new Tuple2<>(parentLabel, localLabel)) && position == outer.production().items().size() - 1) { return true; } if (m.rightAssoc().contains(new Tuple2<>(parentLabel, localLabel)) && position == 0) { return true; } return false; }
Set<Sentence> disambProds; if (mod.importedModuleNames().contains(AUTO_CASTS)) { // create the diamond Set<Sentence> temp; for (Sort srt : iterable(mod.definedSorts())) { if (mod.importedModuleNames().contains(RECORD_PRODS)) { for (Production p : iterable(mod.productions())) { if (p.isPrefixProduction()) { if (mod.importedModuleNames().contains(RULE_CELLS)) { // prepare cell productions for rule parsing boolean addConfigCells = mod.importedModuleNames().contains(CONFIG_CELLS); Set<Sentence> parseProds; if (addRuleCells) { if (mod.importedModuleNames().contains(AUTO_FOLLOW)) { Object PRESENT = new Object(); PatriciaTrie<Object> terminals = new PatriciaTrie<>(); // collect all terminals so we can do automatic follow restriction for prefix terminals if (mod.importedModuleNames().contains(PROGRAM_LISTS)) { Set<Sentence> prods3 = new HashSet<>(); if (!isParserSort(srt) && !mod.listSorts().contains(srt)) { if (mod.importedModuleNames().contains(RULE_LISTS)) { java.util.Set<Sentence> res = new HashSet<>(); for (UserList ul : UserList.getLists(parseProds)) {
att = att.add("format", format.toString()); if(!m.definedKLabels().contains(KLabel(klabel)) && multiplicity != Multiplicity.OPTIONAL) { Production cellProduction = Production(KLabel(klabel), sort, immutable(items), att); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel)), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); if (!m.definedKLabels().contains(KLabel(initLabel))) { sentences.add(initializer); if (!m.definedKLabels().contains(KLabel("no"+childSort.toString()))) { sentences.add(Production(KLabel("no"+childSort.toString()), childOptSort, List(Terminal("no"+childSort.toString())), Att().add(Attribute.CELL_OPT_ABSENT_KEY,Sort.class,childSort))); if (!m.definedKLabels().contains(KLabel("<" + cellName + ">-fragment"))) { sentences.add(Production(KLabel("<" + cellName + ">-fragment"), fragmentSort, immutable(fragmentItems), Att().add(Attribute.CELL_FRAGMENT_KEY, Sort.class, Sort(sortName)))); sentences.add(cellUnit); if(!m.definedKLabels().contains(KLabel(klabel))) { Production cellProduction = Production(KLabel(klabel), sort, immutable(items), att.add(Attribute.UNIT_KEY, cellUnit.klabel().get().name())); sentences.add(cellProduction);
private static Set<Sentence> genProjection(Sort sort, Module m) { KLabel lbl = getProjectLbl(sort, m); KVariable var = KVariable("K", Att.empty().add(Sort.class, sort)); Rule r = Rule(KRewrite(KApply(lbl, var), var), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add("projection")); if (m.definedKLabels().contains(lbl)) { return Set(r); } return Set(Production(lbl, sort, Seq(Terminal(lbl.name()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add("function").add("projection")), r); }
if (mainModule.definedKLabels().contains(stratCell)) { Rule makeStuck = Rule(IncompleteCellUtils.make(stratCell, false, KRewrite(KSequence(), KApply(KLabel("#STUCK"))), true), BooleanUtils.TRUE, BooleanUtils.TRUE); Rule makeUnstuck = Rule(IncompleteCellUtils.make(stratCell, false, KRewrite(KApply(KLabel("#STUCK")), KSequence()), true), BooleanUtils.TRUE, BooleanUtils.TRUE);
KApply freshCell = KApply(KLabel("#configCell"), counterCellLabel, KApply(KLabel("#cellPropertyListTerminator")), KToken("0", Sorts.Int()), counterCellLabel); if (m.equals(def.mainModule()) && kore) { if (!m.definedKLabels().contains(KLabels.GENERATED_TOP_CELL)) { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); ParseInModule mod = RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), true); if (kore && m.localKLabels().contains(KLabels.GENERATED_TOP_CELL)) { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); ParseInModule mod = RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), true);