self.toolcontext.info("*** PARSE ***", 1)
var mmodules = new ArraySet[MModule]
for a in names do
- # Case of a group
- var mgroup = self.get_mgroup(a)
+ # Case of a group (root or sub-directory)
+ var mgroup = self.identify_group(a)
if mgroup != null then
mmodules.add_all parse_group(mgroup)
continue
# Try each entry as a group or a module
for f in fs do
var af = a/f
- mgroup = get_mgroup(af)
+ mgroup = identify_group(af)
if mgroup != null then
mmodules.add_all parse_group(mgroup)
continue
var mp = identify_file((dirname/"{name}.nit").simplify_path)
if mp != null then res.add mp
# Try the default module of a group
- var g = get_mgroup((dirname/name).simplify_path)
+ var g = identify_group((dirname/name).simplify_path)
if g != null then
scan_group(g)
res.add_all g.mmodule_paths_by_name(name)
var res = new ArraySet[MGroup]
for dirname in lookpaths do
# try a single group directory
- var mg = get_mgroup(dirname/name)
+ var mg = identify_group(dirname/name)
if mg != null then
res.add mg
end
fun identify_file(path: String): nullable ModulePath
do
# special case for not a nit file
- if path.file_extension != "nit" then
+ if not path.has_suffix(".nit") then
# search dirless files in known -I paths
if not path.chars.has('/') then
var res = search_module_in_paths(null, path, self.paths)
# Found nothing? maybe it is a group...
var candidate = null
if path.file_exists then
- var mgroup = get_mgroup(path)
+ var mgroup = identify_group(path)
if mgroup != null then
var owner_path = mgroup.filepath.join_path(mgroup.name + ".nit")
if owner_path.file_exists then candidate = owner_path
end
# Fast track, the path is already known
- var pn = path.basename(".nit")
+ if identified_files_by_path.has_key(path) then return identified_files_by_path[path]
var rp = module_absolute_path(path)
if identified_files_by_path.has_key(rp) then return identified_files_by_path[rp]
+ var pn = path.basename(".nit")
+
# Search for a group
var mgrouppath = path.join_path("..").simplify_path
- var mgroup = get_mgroup(mgrouppath)
+ var mgroup = identify_group(mgrouppath)
if mgroup == null then
# singleton package
mgroup.module_paths.add(res)
identified_files_by_path[rp] = res
+ identified_files_by_path[path] = res
identified_files.add(res)
return res
end
# If the directory is not a group null is returned.
#
# Note: `paths` is also used to look for mgroups
- fun get_mgroup(dirpath: String): nullable MGroup
+ fun identify_group(dirpath: String): nullable MGroup
do
- if not dirpath.file_exists then do
+ var stat = dirpath.file_stat
+
+ if stat == null then do
+ # search dirless directories in known -I paths
+ if dirpath.chars.has('/') then return null
for p in paths do
var try = p / dirpath
- if try.file_exists then
+ stat = try.file_stat
+ if stat != null then
dirpath = try
break label
end
return null
end label
+ # Filter out non-directories
+ if not stat.is_dir then
+ return null
+ end
+
+ # Fast track, the path is already known
var rdp = module_absolute_path(dirpath)
if mgroups.has_key(rdp) then
return mgroups[rdp]
end
- # Filter out non-directories
- var stat = dirpath.file_stat
- if stat == null or not stat.is_dir then
- mgroups[rdp] = null
- return null
- end
-
# By default, the name of the package or group is the base_name of the directory
- var pn = rdp.basename(".nit")
+ var pn = rdp.basename
# Check `package.ini` that indicate a package
var ini = null
var stopper = parentpath / "packages.ini"
if not stopper.file_exists then
# Recursively get the parent group
- parent = get_mgroup(parentpath)
+ parent = identify_group(parentpath)
if parent == null then
# Parent is not a group, thus we are not a group either
mgroups[rdp] = null
if p == null then return
for f in p.files do
var fp = p/f
- var g = get_mgroup(fp)
+ var g = identify_group(fp)
# Recursively scan for groups of the same package
- if g != null and g.mpackage == mgroup.mpackage then
+ if g == null then
+ identify_file(fp)
+ else if g.mpackage == mgroup.mpackage then
scan_group(g)
end
- identify_file(fp)
end
end
# Transform relative paths (starting with '../') into absolute paths
private fun module_absolute_path(path: String): String do
- return getcwd.join_path(path).simplify_path
+ return path.realpath
end
# Try to load a module AST using a path.
# Display an error if there is a problem (IO / lexer / parser) and return null
fun load_module_ast(filename: String): nullable AModule
do
- if filename.file_extension != "nit" then
+ if not filename.has_suffix(".nit") then
self.toolcontext.error(null, "Error: file `{filename}` is not a valid nit module.")
return null
end