get_mmodule_by_name
but does not force the parsing of the MModule (cf. identify_module
)
# Like (and used by) `get_mmodule_by_name` but does not force the parsing of the MModule (cf. `identify_module`)
fun search_mmodule_by_name(anode: nullable ANode, mgroup: nullable MGroup, name: String): nullable MModule
do
# First, look in groups
var c = mgroup
if c != null then
var r = c.mpackage.root
assert r != null
scan_group(r)
var res = r.mmodules_by_name(name)
if res.not_empty then return res.first
end
# Look at some known directories
var lookpaths = self.paths
# Look in the directory of the group package also (even if not explicitly in the path)
if mgroup != null then
# path of the root group
var dirname = mgroup.mpackage.root.filepath
if dirname != null then
dirname = dirname.join_path("..").simplify_path
if not lookpaths.has(dirname) and dirname.file_exists then
lookpaths = lookpaths.to_a
lookpaths.add(dirname)
end
end
end
if mgroup != null then
var alias = mgroup.mpackage.import_alias(name)
if alias != null then name = alias
end
var loc = null
if anode != null then loc = anode.hot_location
var candidate = search_module_in_paths(loc, name, lookpaths)
if candidate == null then
if mgroup != null then
error(anode, "Error: cannot find module `{name}` from `{mgroup.name}`. Tried: {lookpaths.join(", ")}.")
else
error(anode, "Error: cannot find module `{name}`. Tried: {lookpaths.join(", ")}.")
end
return null
end
return candidate
end
src/loader.nit:229,2--276,4