@Override public Module shallowCopy() { return new Module(this); }
public static void check(Module m) { m.getItems().stream().forEach(CheckListDecl::check); // i -> check(i) }
/** Adds a comment to the current module or definition list */ void comment(Token token) { String str = token.image; if (str.startsWith("//")) str = str.substring(2, str.length() - 1); // remove // and \n from beginning and end else str = str.substring(2, str.length() - 2); // remove /* and */ from beginning and end LiterateCommentType lcType = LiterateCommentType.COMMON; if (str.startsWith("@")) { lcType = LiterateCommentType.LATEX; str = str.substring(1); } else if (str.startsWith("!")) { lcType = LiterateCommentType.PREAMBLE; str = str.substring(1); } Location loc = new Location(token.beginLine, token.beginColumn, token.endLine, token.endColumn); if (module == null) { items.add(markLocExplicit(loc, new LiterateDefinitionComment(str, lcType))); } else { module.appendModuleItem(markLocExplicit(loc, new LiterateModuleComment(str, lcType))); } }
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()); }
lookupDirectories, requiredFiles));; Set<File> allFiles = modules.stream().map(m -> new File(m.getSource().source())).collect(Collectors.toSet()); System.out.println(files.resolveWorkingDirectory(".").toURI().relativize(files.resolveKompiled("timestamp").toURI()).getPath() + " : \\"); for (File file : allFiles) {
@Test public void testEmptyRules() throws Exception { // TODO: remove once the new parser is fully functional String def = "module TEST rule endmodule"; List<DefinitionItem> defItemList = Outer.parse(Source.apply("generated by OuterParsingTests"), def, null); Module mod = (Module) defItemList.get(0); StringSentence sen = (StringSentence) mod.getItems().get(0); Assert.assertEquals(sen.getContent(), ""); }
/** Parses an Import and adds it to module */ final public void Import(Module module) throws ParseException { Location loc = startLoc(); boolean isSyntax = false; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IMPORTS: jj_consume_token(IMPORTS); break; case IMPORTS2: jj_consume_token(IMPORTS2); break; default: jj_la1[27] = jj_gen; jj_consume_token(-1); throw new ParseException(); } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IMPORTSSYNTAX: jj_consume_token(IMPORTSSYNTAX); isSyntax = true; break; default: jj_la1[28] = jj_gen; ; } jj_consume_token(MODNAME); module.appendModuleItem(markLoc(loc, new Import(image(), isSyntax))); }
private static void checkCircularModuleImports(Module mainModule, scala.collection.Seq<Module> visitedModules) { if (visitedModules.contains(mainModule)) { String msg = "Found circularity in module imports: "; for (Module m : mutable(visitedModules)) { // JavaConversions.seqAsJavaList(visitedModules) msg += m.getName() + " < "; } msg += visitedModules.head().getName(); throw KEMException.compilerError(msg); } }
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()); Set<Import> importedModuleNames = mainModule.getItems().stream() .filter(imp -> imp instanceof Import) .map(imp -> (Import) imp) .filter(m -> m.getName().equals(name)) .findFirst(); if (theModule.isPresent()) { Module mod = theModule.get(); 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)); org.kframework.definition.Module newModule = Module(mainModule.getName(), immutable(importedModules), immutable(nonSyntaxItems), convertAttributes(mainModule));
@Test public void testLexicalRules() throws Exception { // TODO: remove once the new parser is fully functional String def = "module TEST syntax Str ::= Token{((~[\\'\\n\\r\\\\])|([\\\\]~[\\n\\r]))*} endmodule"; List<DefinitionItem> defItemList = Outer.parse(Source.apply("generated by OuterParsingTests"), def, null); Module mod = (Module) defItemList.get(0); Syntax syn = (Syntax) mod.getItems().get(0); Lexical lex = (Lexical) syn.getPriorityBlocks().get(0).getProductions().get(0).getItems().get(0); Assert.assertEquals("((~[\\'\\n\\r\\\\])|([\\\\]~[\\n\\r]))*", lex.getLexicalRule()); }
module.appendModuleItem(markLoc(loc, ss)); break; case SYNTAX: module.appendModuleItem(markLoc(loc, syn)); break; case PRIORITY: pblocks.add(new PriorityBlockExtended(list)); module.appendModuleItem(markLoc(loc, new PriorityExtended(pblocks))); break; case NON_ASSOC: module.appendModuleItem(markLoc(loc, new PriorityExtendedAssoc(type, list))); break; default:
@Test public void testLexicalRules2() throws Exception { // TODO: remove once the new parser is fully functional String def = "module TEST syntax Str ::= Token{{[a]|[b] \".\"}+NT~[x]*} endmodule"; List<DefinitionItem> defItemList = Outer.parse(Source.apply("generated by OuterParsingTests"), def, null); Module mod = (Module) defItemList.get(0); Syntax syn = (Syntax) mod.getItems().get(0); Lexical lex = (Lexical) syn.getPriorityBlocks().get(0).getProductions().get(0).getItems().get(0); Assert.assertEquals("{[a]|[b] \".\"}+NTDz~[x]*", lex.getLexicalRule()); } }