Skip to content

Commit

Permalink
Parser
Browse files Browse the repository at this point in the history
- `findModulesInDirectory(string directory)` now will search the directory, exclude all non-files and only return an array of files ending in `.t`
- It also will only do a shallow scan (will not recurse into any directories)
  • Loading branch information
deavmi committed Aug 27, 2023
1 parent 46388e5 commit 3f7c367
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions source/tlang/compiler/parsing/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,9 @@ public final class Parser
// TODO: Be able to split by `.` and lookup modules via that in FS
gprintln("Module to import: '"~moduleName~"'");


string[] modulesInStartingDir = findModulesFromStartingPath(currentModulePath);




Expand All @@ -2255,6 +2258,40 @@ public final class Parser

import std.path;

private static string[] findModulesFromStartingPath(string startingModulePath)
{
// Get directory the mdoule path resides in
string startingDir = dirName(startingModulePath);

// strip(pathSplitter(currentModulePath).back(), ".t");

return findModulesInDirectory(startingDir);
}

import std.file;
import std.string : endsWith, strip;
private static string[] findModulesInDirectory(string directory)
{
string[] modulesFound;
scope(exit)
{
gprintln("findModulesInDirectory("~directory~"): "~to!(string)(modulesFound));
}

foreach(DirEntry entry; dirEntries!()(directory, SpanMode.shallow))
{
// gprintln(entry);
if(entry.isFile() && endsWith(entry.name(), ".t"))
{
string moduleName = entry.name().strip(".t");
modulesFound ~= moduleName;
}
}


return modulesFound;
}

private static string getWorkingDirectory()
{
// TOOD: look at lazy, seems cool
Expand Down

0 comments on commit 3f7c367

Please sign in to comment.