// you will go into an infinite loop (since, regardless of the instantiating parameter,
// that file will attempt to OPEN the exact same set of files. leading back to itself, etc. etc.)
// <= If there is an infinite loop, that means there is at least 1 infinite chain of OPEN (from root).
// Since the number of files is finite, at least 1 filename will be repeated.
if (thispath.contains(filename))
throw new ErrorSyntax(pos,
"Circular dependency in module import. The file \""+(new File(filename)).getName()+"\" is imported infinitely often.");
thispath.add(filename);
// No cycle detected so far. So now we parse the file.
CompModule u = CompParser.alloy_parseStream(seenDollar, loaded, fc, root, 0, filename, prefix, initialResolution);
if (prefix.length()==0) root = u;
// Here, we recursively open the included files
for(Open x: u.getOpens()) {
String cp=Util.canon(computeModulePath(u.getModelName(), filename, x.filename)), content=fc.get(cp);
try {
if (content==null) { content=loaded.get(cp); }
if (content==null) { content=fc.get(x.filename); if (content!=null) cp=x.filename; }
if (content==null) { content=loaded.get(x.filename); if (content!=null) cp=x.filename; }
if (content==null) { content=Util.readAll(cp); }
} catch(IOException ex1) {
try {
String newCp = (Util.jarPrefix()+"models/"+x.filename+".als").replace('/', File.separatorChar);
content = Util.readAll(newCp);
cp = newCp;
} catch(IOException ex) {
throw new ErrorSyntax(x.pos,
"This module cannot be found.\nIt is not a built-in library module, and it cannot be found at \""+cp+"\".\n");
}
}
loaded.put(cp, content);
CompModule y = parseRecursively(seenDollar, loaded, fc, x.pos, cp, root, (prefix.length()==0 ? x.alias : prefix+"/"+x.alias), thispath, initialResolution);