X-Git-Url: http://nitlanguage.org diff --git a/src/loader.nit b/src/loader.nit index 1f3f72c..5d20c9c 100644 --- a/src/loader.nit +++ b/src/loader.nit @@ -52,6 +52,8 @@ redef class ModelBuilder var nit_dir = toolcontext.nit_dir var libname = nit_dir/"lib" if libname.file_exists then paths.add(libname) + libname = nit_dir/"contrib" + if libname.file_exists then paths.add(libname) end # Load a bunch of modules. @@ -222,6 +224,14 @@ redef class ModelBuilder return res end + # Fourth, try if the requested module is itself a group with a src + try_file = dirname + "/" + name + "/src/" + name + ".nit" + if try_file.file_exists then + var res = self.identify_file(try_file.simplify_path) + assert res != null + return res + end + c = c.parent end @@ -301,6 +311,19 @@ redef class ModelBuilder end end end + try_file = (dirname + "/" + name + "/src/" + name + ".nit").simplify_path + if try_file.file_exists then + if candidate == null then + candidate = try_file + else if candidate != try_file then + # try to disambiguate conflicting modules + var abs_candidate = module_absolute_path(candidate) + var abs_try_file = module_absolute_path(try_file) + if abs_candidate != abs_try_file then + toolcontext.error(location, "Error: conflicting module file for `{name}`: `{candidate}` `{try_file}`") + end + end + end end if candidate == null then return null return identify_file(candidate) @@ -456,11 +479,21 @@ redef class ModelBuilder # Load a markdown file as a documentation object fun load_markdown(filepath: String): MDoc do - var mdoc = new MDoc(new Location(new SourceFile.from_string(filepath, ""),0,0,0,0)) var s = new FileReader.open(filepath) + var lines = new Array[String] + var line_starts = new Array[Int] + var len = 1 while not s.eof do - mdoc.content.add(s.read_line) - end + var line = s.read_line + lines.add(line) + line_starts.add(len) + len += line.length + 1 + end + s.close + var source = new SourceFile.from_string(filepath, lines.join("\n")) + source.line_starts.add_all line_starts + var mdoc = new MDoc(new Location(source, 1, lines.length, 0, 0)) + mdoc.content.add_all(lines) return mdoc end