Verified Commit 0630d34f authored by Camil Staps's avatar Camil Staps 🚀

Only find modules in the given directory/ies, not in their children

parent d4997410
Pipeline #14652 failed with stage
in 58 seconds
......@@ -4,6 +4,7 @@ import StdArray
import StdList
import StdString
import Clean.Parse
import Data.Error
from Data.Func import $, mapSt
import System.Directory
......@@ -66,12 +67,22 @@ where
findAllModules :: !ModuleFindingOptions !*World -> *(![OSError], ![FilePath], !*World)
findAllModules opts w
# (errs,(paths,w)) = mapSt (scanDirectory` collect) (baseDirectories opts) ([], w)
# (errs,(paths,w)) = mapSt (\d -> scanDirectory` (collect d) d) (baseDirectories opts) ([], w)
= (flatten errs,paths,w)
where
scanDirectory` f dir (st,w) = (err, (st`,w`)) where (err, st`, w`) = scanDirectory f st dir w
collect fp fi seen w
collect dir fp fi seen w
| endsWith (if opts.include_applications ".icl" ".dcl") fp
= ([fp:seen], w)
# (modname, w) = guessModuleName fp w
| isError modname = (seen, w)
# modname = fromOk modname
| isNothing modname = (seen, w)
# modname = fromJust modname
# expected = {if (c == pathSeparator) '.' c \\ c <-: fp % (size dir`, size fp - 5)}
with dir` = dir </> ""
| modname == expected
= ([fp:seen], w)
= (seen, w)
| otherwise
= (seen, w)
......@@ -7,12 +7,24 @@ definition module Clean.Parse
from Data.Error import :: MaybeError
from Data.Maybe import :: Maybe
from System.File import :: FileError
from System.FilePath import :: FilePath
from hashtable import :: HashTable
from Heap import :: Heap
from syntax import :: Module, :: ParsedDefinition, :: ParsedModule
/**
* Guess the module name of a Clean file.
*
* @param The path to the Clean file
* @result
* `Error`, if the file could not be read;
* `Ok Nothing`, if the module name could not be guessed;
* `Ok (Just name)` in case of success.
*/
guessModuleName :: !FilePath !*World -> *(!MaybeError FileError (Maybe String), !*World)
/**
* Parse a Clean module.
*
......
......@@ -17,12 +17,18 @@ from hashtable import :: BoxedIdent{boxed_ident}, :: HashTable,
from parse import wantModule
import syntax
readModule :: !FilePath !*World -> *(!MaybeError String (ParsedModule, HashTable), !*World)
readModule filename w
guessModuleName :: !FilePath !*World -> *(!MaybeError FileError (Maybe String), !*World)
guessModuleName filename w
# (s,w) = readFile filename w
| isError s = (Error (toString (fromError s)), w)
| isError s = (Error (fromError s), w)
# modname = getModuleName (fromString (fromOk s))
# modname = fromMaybe (takeFileName (dropExtension filename)) modname
= (Ok modname, w)
readModule :: !FilePath !*World -> *(!MaybeError String (ParsedModule, HashTable), !*World)
readModule filename w
# (modname,w) = guessModuleName filename w
| isError modname = (Error (toString (fromError modname)), w)
# modname = fromMaybe (takeFileName (dropExtension filename)) (fromOk modname)
# ht = newHashTable newHeap
# ht = set_hte_mark (if icl 1 0) ht
# (ok,f,w) = fopen filename FReadText w
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment