@SuppressWarnings("unchecked") public Set<org.kframework.definition.Sentence> apply(ModuleItem i) { if (i instanceof Syntax || i instanceof PriorityExtended) { return (Set<org.kframework.definition.Sentence>) apply((ASTNode) i); } else if (i instanceof Restrictions) { return Sets.newHashSet(); } else { return Sets.newHashSet((org.kframework.definition.Sentence) apply((ASTNode) i)); } }
public R apply(ASTNode t) { try { MethodHandles.Lookup lookup = MethodHandles.lookup(); Method visitMethod = this.getClass().getDeclaredMethod("apply", t.getClass()); MethodHandle visitMethodHandle = lookup.unreflect(visitMethod); return (R) visitMethodHandle.invoke(this, t); } catch (NoSuchMethodException e) { throw new VisitingException("Visitor " + this.getClass() + " is missing a definition for visit(" + t.getClass() + ")" + ". Encounteed when visiting " + makeErrorMessage(t), e); // DISABLE EXCEPTION CHECKSTYLE } catch (VisitingException e) { throw e; } catch (Throwable e) { throw new VisitingException(makeErrorMessage(t), e); } // ENABLE EXCEPTION CHECKSTYLE } // ENABLE EXCEPTION CHECKING
public org.kframework.definition.SyntaxAssociativity apply(PriorityExtendedAssoc ii) { scala.collection.Set<Tag> tags = toTags(ii.getTags(), ii); String assocOrig = ii.getAssoc(); Value assoc = applyAssoc(assocOrig); return SyntaxAssociativity(assoc, tags); }
res.add(SyntaxSort(sort, convertAttributes(s))); return res; Value assoc = applyAssoc(b.getAssoc()); res.add(SyntaxAssociativity(assoc, applyToTags.apply(b))); applyUserList(res, sort, p, (UserList) p.getItems().get(0)); } else { List<ProductionItem> items = new ArrayList<>(); else regex = ((Lexical) it).getLexicalRule(); RegexTerminal regexTerminal = getRegexTerminal(regex); org.kframework.attributes.Att attrs = convertAttributes(p); res.add(SyntaxAssociativity(applyAssoc("left"), Set(Tag(p.getKLabel(kore))))); else if (p.containsAttribute("right")) res.add(SyntaxAssociativity(applyAssoc("right"), Set(Tag(p.getKLabel(kore))))); else if (p.containsAttribute("non-assoc")) res.add(SyntaxAssociativity(applyAssoc("non-assoc"), Set(Tag(p.getKLabel(kore)))));
private org.kframework.definition.Module apply(Module mainModule, Set<Module> allKilModules, Map<String, org.kframework.definition.Module> koreModules, scala.collection.Seq<Module> visitedModules) { checkCircularModuleImports(mainModule, visitedModules); CheckListDecl.check(mainModule); Set<org.kframework.definition.Sentence> items = mainModule.getItems().stream() .filter(j -> !(j instanceof org.kframework.kil.Import)) .flatMap(j -> apply(j).stream()).collect(Collectors.toSet()); org.kframework.definition.Module result = koreModules.get(mod.getName()); if (result == null) { result = apply(mod, allKilModules, koreModules, cons(mainModule, visitedModules)); .map(resolveImport).collect(Collectors.toSet()); Set<org.kframework.definition.Sentence> syntaxItems = items.stream().filter(org.kframework.definition.Sentence::isSyntax).collect(Collectors.toSet()); org.kframework.definition.Module newSyntaxModule = Module(new Import(mainModule.getName()).getImportSyntax().getName(), immutable(importedSyntaxModules), immutable(syntaxItems), convertAttributes(mainModule)); Set<org.kframework.definition.Sentence> nonSyntaxItems = items.stream().filter(org.kframework.definition.Sentence::isNonSyntax).collect(Collectors.toSet()); org.kframework.definition.Module newModule = Module(mainModule.getName(), immutable(importedModules), immutable(nonSyntaxItems), convertAttributes(mainModule));
public Set<Module> loadModules( Set<Module> previousModules, String definitionText, Source source, File currentDirectory, List<File> lookupDirectories, Set<File> requiredFiles, boolean kore) { List<org.kframework.kil.Module> kilModules = slurp(definitionText, source, currentDirectory, lookupDirectories, requiredFiles); Definition def = new Definition(); def.setItems((List<DefinitionItem>) (Object) kilModules); Context context = new Context(); new CollectProductionsVisitor(kore, context).visit(def); KILtoKORE kilToKore = new KILtoKORE(context, false, kore); HashMap<String, Module> koreModules = new HashMap<>(); koreModules.putAll(previousModules.stream().collect(Collectors.toMap(Module::name, m -> m))); HashSet<org.kframework.kil.Module> kilModulesSet = new HashSet<>(kilModules); return kilModules.stream().map(m -> kilToKore.apply(m, kilModulesSet, koreModules)).flatMap(m -> Stream.concat(Stream.of(m), Stream.of(koreModules.get(m.name() + "$SYNTAX")))).collect(Collectors.toSet()); }
public static org.kframework.attributes.Att convertAttributes(ASTNode t) { Attributes attributes = t.getAttributes(); Map<String, String> attributesSet = attributes .keySet() .stream() .map(key -> { String keyString = key.toString(); String valueString = attributes.get(key).getValue().toString(); if (keyString.equals("klabel")) { return Tuple2.apply("klabel", valueString); } else { return Tuple2.apply(keyString, valueString); } }).collect(Collectors.toMap(Tuple2::_1, Tuple2::_2)); return Att().addAll(attributesSet) .addAll(attributesFromLocation(t.getLocation())) .addAll(attributesFromSource(t.getSource())); }
private static void assertPatterns(String original, String precede, String pattern, String follow) { RegexTerminal re1 = KILtoKORE.getRegexTerminal(original); Assert.assertEquals(precede, re1.precedeRegex()); Assert.assertEquals(pattern, re1.regex()); Assert.assertEquals(follow, re1.followRegex()); }
public ModuleComment apply(LiterateModuleComment m) { return new org.kframework.definition.ModuleComment(m.getValue(), convertAttributes(m)); }
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)); }
/** * Takes a definition in e-kore textual format and a main module name, and returns the KORE * representation of that module. Current implementation uses JavaCC and goes through KIL. * * @param definitionText textual representation of the modules. * @param mainModule main module name. * @return KORE representation of the main module. */ public static Module parseMainModuleOuterSyntax(String definitionText, Source source, String mainModule) { Definition def = new Definition(); def.setItems(Outer.parse(source, definitionText, null)); def.setMainModule(mainModule); def.setMainSyntaxModule(mainModule); Context context = new Context(); new CollectProductionsVisitor(false, context).visit(def); KILtoKORE kilToKore = new KILtoKORE(context); return kilToKore.apply(def).getModule(mainModule).get(); }
public org.kframework.definition.Module apply(Module mainModule, Set<Module> allKilModules, Map<String, org.kframework.definition.Module> koreModules) { return apply(mainModule, allKilModules, koreModules, Seq()); }
public org.kframework.definition.Bubble apply(StringSentence sentence) { return Bubble(sentence.getType(), sentence.getContent(), convertAttributes(sentence) .add("contentStartLine", Integer.class, sentence.getContentStartLine()) .add("contentStartColumn", Integer.class, sentence.getContentStartColumn())); }
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 void applyUserList(Set<org.kframework.definition.Sentence> res, org.kframework.kore.Sort sort, Production p, UserList userList) { // Transform list declarations of the form Es ::= List{E, ","} into something representable in kore org.kframework.kore.Sort elementSort = userList.getSort(); org.kframework.attributes.Att attrs = convertAttributes(p).add(Att.userList(), userList.getListType()); String kilProductionId = "" + System.identityHashCode(p); Att attrsWithKilProductionId = attrs.add(PRODUCTION_ID, kilProductionId); org.kframework.definition.Production prod1, prod3; // Es ::= E "," Es prod1 = Production(KLabel(p.getKLabel(kore)), sort, Seq(NonTerminal(elementSort), Terminal(userList.getSeparator()), NonTerminal(sort)), attrsWithKilProductionId.add("right")); // Es ::= ".Es" prod3 = Production(KLabel(p.getTerminatorKLabel(kore)), sort, Seq(Terminal("." + sort.toString())), attrsWithKilProductionId.remove("format").remove("strict").add("klabel", p.getTerminatorKLabel(false))); res.add(prod1); res.add(prod3); }