+
+ # Handle lexer and parser error
+ var nmodule = tree.n_base
+ if nmodule == null then
+ var neof = tree.n_eof
+ assert neof isa AError
+ error(neof, neof.message)
+ return null
+ end
+
+ return nmodule
+ end
+
+ # Try to load a module and its imported modules using a path.
+ # Display an error if there is a problem (IO / lexer / parser / importation) and return null
+ # Note: usually, you do not need this method, use `get_mmodule_by_name` instead.
+ fun load_module(filename: String): nullable AModule
+ do
+ # Look for the module
+ var file = identify_file(filename)
+ if file == null then return null # forward error
+
+ # Already known and loaded? then return it
+ var mmodule = file.mmodule
+ if mmodule != null then
+ return mmodule2nmodule[mmodule]
+ end
+
+ # Load it manually
+ var nmodule = load_module_ast(filename)
+ if nmodule == null then return null # forward error
+
+ # build the mmodule and load imported modules
+ mmodule = build_a_mmodule(file.mgroup, file.name, nmodule)
+
+ if mmodule == null then return null # forward error
+
+ # Update the file information
+ file.mmodule = mmodule
+
+ # Load imported module
+ build_module_importation(nmodule)
+
+ return nmodule