diff --git a/grammars/silver/compiler/translation/java/driver/BuildProcess.sv b/grammars/silver/compiler/translation/java/driver/BuildProcess.sv index 38d679125..5e8340cda 100644 --- a/grammars/silver/compiler/translation/java/driver/BuildProcess.sv +++ b/grammars/silver/compiler/translation/java/driver/BuildProcess.sv @@ -246,7 +246,8 @@ IO<()> ::= silverGen::String keepFiles::[String] r::Decorated RootSpec exit(-5); }); }); - oldSrcFiles::[String] <- listContents(srcPath); + srcDirContents::[String] <- listContents(srcPath); + oldSrcFiles::[String] <- filterM(isFile, map(append(srcPath, _), srcDirContents)); deleteFiles(removeAll(keepFiles, oldSrcFiles)); deleteDirFiles(binPath); writeFiles(srcPath, r.genFiles); diff --git a/grammars/silver/core/List.sv b/grammars/silver/core/List.sv index 746e448a6..5318f2d70 100644 --- a/grammars/silver/core/List.sv +++ b/grammars/silver/core/List.sv @@ -172,6 +172,29 @@ function filter else filter(f, tail(lst)); } +@{-- + - Monadic (actually Applicative) version of filter + - + - @param f The filter function + - @param lst The input list to filter + - @return Only those elements of 'lst' that 'f' returns true for, in the + - same order as they appeared in 'lst' + -} +function filterM +Applicative m => +m<[a]> ::= f::(m ::= a) lst::[a] +{ + return + case lst of + | [] -> pure([]) + | h :: t -> do { + cond::Boolean <- f(h); + rest::[a] <- filterM(f, t); + return if cond then h :: rest else rest; + } + end; +} + @{-- - Partition a list in two -