Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add command line option for excluding files matching pattern.

  • Loading branch information...
commit 202eac09bad90b1402bf59dedad582faca55bdc7 1 parent 10c07f5
arvidj arvidj authored
Showing with 21 additions and 5 deletions.
  1. +1 −1  lex-pass.cabal
  2. +11 −3 src/Config.hs
  3. +4 −1 src/Main.hs
  4. +5 −0 src/Options.hs
2  lex-pass.cabal
View
@@ -21,7 +21,7 @@ executable lex-pass
main-is: Main.hs
build-depends: FUtil, HSH >= 2, MissingH, base >= 4, binary, bytestring,
containers, derive, directory, filepath, mtl, parsec == 3.*,
- process, syb
+ process, syb, regex-compat
ghc-options: -threaded
executable lex-pass-test
14 src/Config.hs
View
@@ -4,7 +4,15 @@ import Data.List
import HSH
-- put any custom default excluded directories or aliased filetypes here etc
-sourceFiles :: [String] -> String -> IO [String]
-sourceFiles ftypes dir = run ("find", dir:args) where
- args = intercalate ["-or"] [["-iname", "*." ++ ftype] | ftype <- ftypes]
+sourceFiles :: [String] -> [String] -> String -> IO [String]
+sourceFiles ftypes exlcDirs dir = run (findCommand ftypes exlcDirs dir)
+findCommand :: [String] -> [String] -> String -> (String, [String])
+findCommand ftypes exclDirs dir = ("find", allArgs) where
+ allArgs = dir:(exclArgs ++ inclArgs ++ ["-print"])
+ inclArgs = orArgs [["-iname", "*." ++ ftype] | ftype <- ftypes]
+ exclArgs = if exclDirs /= []
+ then (paren . orArgs $ [["-wholename", dir] | dir <- exclDirs]) ++ ["-prune", "-o"]
+ else []
+ paren args = ["("] ++ args ++ [")"]
+ orArgs = intercalate ["-or"]
5 src/Main.hs
View
@@ -12,6 +12,7 @@ import System.Environment
import System.FilePath
import System.IO
import System.Process
+import Text.Regex
import CodeGen.Transf
import LexPassUtil
@@ -91,7 +92,9 @@ main = do
transf = lookupTrans transfName
subPaths <- map killInitialDotSlash <$> if optFiles opts
then getContents >>= return . lines
- else Config.sourceFiles (transfTypes transf) dir
+ else Config.sourceFiles (transfTypes transf)
+ (maybe [] (\p -> splitRegex (mkRegex ",") p) (optExclPats opts))
+ dir
let
subPaths' = case optStartAtFile opts of
Nothing -> subPaths
5 src/Options.hs
View
@@ -7,6 +7,7 @@ data Options = Options {
optNumCores :: Int,
optFiles :: Bool,
optDir :: Maybe String,
+ optExclPats :: Maybe String,
optStartAtFile :: Maybe String}
deriving Show
@@ -16,6 +17,7 @@ defaultOptions = Options {
optNumCores = 1,
optFiles = False,
optDir = Nothing,
+ optExclPats = Nothing,
optStartAtFile = Nothing}
options :: [OptDescr (Options -> Options)]
@@ -32,6 +34,9 @@ options = [
\files of interest. Abstract syntax trees\n\
\will be cached in top-level .ast/\n\
\directory.",
+ Option "e" ["exclude"]
+ (ReqArg (\ d opts -> opts {optExclPats = Just d}) "<patterns>")
+ "Exclude files patterns. ",
Option "f" ["files"]
(NoArg (\ opts -> opts {optFiles = True}))
"Pass a specific list of files to stdin\n\
Please sign in to comment.
Something went wrong with that request. Please try again.