Commit 1e3e32d7 authored by Steffen Michels's avatar Steffen Michels

Merge branch 'modulefinder-enhancements' into 'master'

Clean.ModuleFinder: only find modules in the given directory/ies, not in their children

See merge request !202
parents ed4f03ef d17e6741
Pipeline #14760 passed with stage
in 1 minute and 6 seconds
......@@ -4,6 +4,7 @@ import StdArray
import StdList
import StdString
import Clean.Parse.ModuleName
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)
......@@ -3,8 +3,7 @@ implementation module Clean.Parse
// NOTE: be VERY restrictive with adding imports here, because this may break
// the module when the compiler changes.
import StdFile
import Clean.Parse.ModuleName
import Data.Error
import Data.Maybe
import System.File
......@@ -19,10 +18,9 @@ import syntax
readModule :: !FilePath !*World -> *(!MaybeError String (ParsedModule, HashTable), !*World)
readModule filename w
# (s,w) = readFile filename w
| isError s = (Error (toString (fromError s)), w)
# modname = getModuleName (fromString (fromOk s))
# modname = fromMaybe (takeFileName (dropExtension filename)) modname
# (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
......@@ -40,35 +38,3 @@ where
wantModule` f s b1 i p b2 ht io fs
# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs
= ((b1,b2,pm,ht,f),fs)
// A reasonably accurate simple scanner to get the module name from the file
getModuleName :: ![Char] -> Maybe String
getModuleName ['definition':c:cs] | isSpace c = justModule cs
getModuleName ['implementation':c:cs] | isSpace c = justModule cs
getModuleName ['system':c:cs] | isSpace c = justModule cs
getModuleName [c:cs] | isSpace c = getModuleName cs
getModuleName ['//':cs] = getModuleName (dropWhile ((<>) '\n') cs)
getModuleName ['/*':cs] = getModuleName (skipMultiLineComment cs)
getModuleName cs = justModule cs
justModule :: ![Char] -> Maybe String
justModule ['module':c:cs] | isSpace c = justModuleName cs
justModule [c:cs] | isSpace c = justModule cs
justModule ['//':cs] = justModule (dropWhile ((<>) '\n') cs)
justModule ['/*':cs] = justModule (skipMultiLineComment cs)
justModule _ = Nothing
justModuleName :: ![Char] -> Maybe String
justModuleName cs
# (_,cs) = span isSpace cs
# (name,_) = span (\c -> c <> '/' && c <> ';' && not (isSpace c)) cs
= case name of
[] -> Nothing
_ -> Just (toString name)
skipMultiLineComment :: ![Char] -> [Char]
skipMultiLineComment ['*/':cs] = cs
skipMultiLineComment ['/*':cs] = skipMultiLineComment (skipMultiLineComment cs)
skipMultiLineComment [c:cs] = skipMultiLineComment cs
skipMultiLineComment [] = []
definition module Clean.Parse.ModuleName
from Data.Error import :: MaybeError
from Data.Maybe import :: Maybe
from System.File import :: FileError
from System.FilePath import :: FilePath
/**
* 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)
implementation module Clean.Parse.ModuleName
import StdBool
import StdChar
import StdClass
import StdFile
import StdList
import Data.Error
import Data.Maybe
import System.File
import System.FilePath
guessModuleName :: !FilePath !*World -> *(!MaybeError FileError (Maybe String), !*World)
guessModuleName filename w
# (s,w) = readFile filename w
| isError s = (Error (fromError s), w)
# modname = getModuleName (fromString (fromOk s))
= (Ok modname, w)
// A reasonably accurate simple scanner to get the module name from the file
getModuleName :: ![Char] -> Maybe String
getModuleName ['definition':c:cs] | isSpace c = justModule cs
getModuleName ['implementation':c:cs] | isSpace c = justModule cs
getModuleName ['system':c:cs] | isSpace c = justModule cs
getModuleName [c:cs] | isSpace c = getModuleName cs
getModuleName ['//':cs] = getModuleName (dropWhile ((<>) '\n') cs)
getModuleName ['/*':cs] = getModuleName (skipMultiLineComment cs)
getModuleName cs = justModule cs
justModule :: ![Char] -> Maybe String
justModule ['module':c:cs] | isSpace c = justModuleName cs
justModule [c:cs] | isSpace c = justModule cs
justModule ['//':cs] = justModule (dropWhile ((<>) '\n') cs)
justModule ['/*':cs] = justModule (skipMultiLineComment cs)
justModule _ = Nothing
justModuleName :: ![Char] -> Maybe String
justModuleName cs
# (_,cs) = span isSpace cs
# (name,_) = span (\c -> c <> '/' && c <> ';' && not (isSpace c)) cs
= case name of
[] -> Nothing
_ -> Just (toString name)
skipMultiLineComment :: ![Char] -> [Char]
skipMultiLineComment ['*/':cs] = cs
skipMultiLineComment ['/*':cs] = skipMultiLineComment (skipMultiLineComment cs)
skipMultiLineComment [c:cs] = skipMultiLineComment cs
skipMultiLineComment [] = []
......@@ -20,6 +20,7 @@ import qualified StdLibMisc
import qualified Clean.Doc
//import qualified Clean.Parse // requires Clean compiler
//import qualified Clean.Parse.Comments // requires Clean compiler
import qualified Clean.Parse.ModuleName
import qualified Clean.Types
//import qualified Clean.Types.CoclTransform // requires Clean compiler
import qualified Clean.Types.Parse
......
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