-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
368 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module tlang.compiler.modman.exceptions; | ||
|
||
import misc.exceptions; | ||
import tlang.compiler.modman.modman : ModuleManager; | ||
|
||
public final class ModuleManagerError : TError | ||
{ | ||
this(ModuleManager modMan, string msg) | ||
{ | ||
super("Module manager '"~modMan.toString()~"' had error: "~msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
module tlang.compiler.modman.modman; | ||
|
||
import gogga; | ||
|
||
// TODO: We may want to throw an exception whilst searching | ||
// ... as to which path is invalid | ||
import tlang.compiler.modman.exceptions; | ||
|
||
/** | ||
* Manager for searching for modules etc. | ||
*/ | ||
public final class ModuleManager | ||
{ | ||
/** | ||
* The search paths | ||
*/ | ||
private string[] searchPaths; | ||
|
||
/** | ||
* Creates a new module manager with the | ||
* provided paths of which it should | ||
* consider when searching for module | ||
* files | ||
* | ||
* Params: | ||
* searchPaths = the search paths | ||
* Throws: | ||
* ModuleManagerError = if the | ||
* provided search paths are incorrect | ||
*/ | ||
this(string[] searchPaths) | ||
{ | ||
if(!validate(searchPaths)) | ||
{ | ||
throw new ModuleManagerError(this, "An invalid path exists within the provided search paths"); | ||
} | ||
|
||
this.searchPaths = searchPaths; | ||
} | ||
|
||
/** | ||
* Validates the given paths, and only | ||
* returns a valid verdict if all of | ||
* the paths are valid search paths | ||
* | ||
* Params: | ||
* searchPaths = the search paths | ||
* to consider | ||
* Returns: `true` if all paths are valid, | ||
* `false` otherwise | ||
*/ | ||
public static bool validate(string[] searchPaths) | ||
{ | ||
foreach(string searchPath; searchPaths) | ||
{ | ||
if(!validate(searchPath)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Validates a given path that it is a valid | ||
* search path | ||
* | ||
* Params: | ||
* searchPath = the path to check | ||
* Returns: `true` if the search path is valid, | ||
* `false` otherwise | ||
*/ | ||
public static bool validate(string searchPath) | ||
{ | ||
// Path cannot be empty | ||
if(searchPath.length == 0) | ||
{ | ||
return false; | ||
} | ||
|
||
import std.file : isDir; | ||
|
||
// It should be a valid directory | ||
return isDir(searchPath); | ||
} | ||
} | ||
|
||
/** | ||
* Tests the static methods of the `ModuleManager` | ||
* | ||
* In this case positive verdict is expected | ||
*/ | ||
unittest | ||
{ | ||
string[] goodPaths = [ | ||
"source/tlang/testing", | ||
"source/tlang/testing/modules" | ||
]; | ||
|
||
bool res = ModuleManager.validate(goodPaths); | ||
assert(res); | ||
} | ||
|
||
/** | ||
* Tests the static methods of the `ModuleManager` | ||
* | ||
* In this case negative verdict is expected | ||
*/ | ||
unittest | ||
{ | ||
string[] badPaths = [ | ||
"source/tlang/testing", | ||
"source/tlang/testing/modules", | ||
"README.md", | ||
]; | ||
|
||
bool res = ModuleManager.validate(badPaths); | ||
assert(!res); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module tlang.compiler.modman; | ||
|
||
public import tlang.compiler.modman.modman : ModuleManager; | ||
public import tlang.compiler.modman.exceptions : ModuleManagerError; |
Oops, something went wrong.