Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added command-line option to specify list of explicity-enabled langua…

…ge extensions for parsing
  • Loading branch information...
commit 52c4b5f81de1fa60c85a92aa00885931b00b0bd6 1 parent 61677f1
@adept authored
Showing with 19 additions and 10 deletions.
  1. +2 −2 src/GraphType.hs
  2. +10 −5 src/OptionParser.hs
  3. +7 −3 src/Parse.hs
View
4 src/GraphType.hs
@@ -17,8 +17,8 @@ import Data.Maybe
import Control.Monad
main = do
- (Mode output trim, root, files) <- getOpts
- types <- parseFiles files
+ (Mode output trim exts, root, files) <- getOpts
+ types <- parseFiles exts files
let trimmed = if trim
then doTrim types
else types
View
15 src/OptionParser.hs
@@ -10,31 +10,36 @@ import System.Exit
import System.Console.GetOpt
import Data.Maybe ( fromMaybe )
import Control.Monad (when)
+import Language.Haskell.Exts (Extension)
-- | Mode of operation
data Mode = Mode { output :: String -- ^ Name of the output file
, trim :: Bool -- ^ Trim trivial types/newtypes or not
+ , exts :: Maybe [Extension]
}
-- | Default mode: output to "output.dot", dont trim trivial types
-defaultMode = Mode "output.dot" False
-
+defaultMode = Mode {output="output.dot", trim=False, exts=Nothing}
data Flag
- = Output FilePath | Trim | Help
+ = Output FilePath | Trim | Help | Extensions [Extension]
deriving (Eq,Show)
options :: [OptDescr Flag]
options =
[ Option ['o'] ["output"] (OptArg getOutput "file") "Name of the output file (default: output.dot)",
Option ['t'] ["trim"] (NoArg Trim) "Trim types/newtype that do not have references to other user-defined types",
+ Option ['e'] ["exts"] (ReqArg getExts "extensions") "Comma-separated list of extensions to enable when parsing sources",
Option [] ["help"] (NoArg Help) "Show this help" ]
getOutput Nothing = Output "output.dot"
getOutput (Just s) = Output s
-update (Output f) m = m { output = f }
-update Trim m = m { trim = True }
+getExts exts = Extensions $ read $ "[" ++ exts ++ "]"
+
+update (Output f) m = m { output = f }
+update Trim m = m { trim = True }
+update (Extensions es) m = m { exts = Just es }
getOpts :: IO (Mode, String, [FilePath])
getOpts = getArgs >>= \argv ->
View
10 src/Parse.hs
@@ -6,11 +6,15 @@ import Data.Generics.PlateData (universeBi)
import Control.Monad (liftM)
import System.Exit (exitFailure)
-parseFiles :: [FilePath] -> IO [Decl]
-parseFiles = liftM concat . mapM parseFile'
+parseFiles :: Maybe [Extension] -> [FilePath] -> IO [Decl]
+parseFiles exts = liftM concat . mapM parseFile'
where
+ parser = case exts of
+ Nothing -> parseFile
+ Just es -> \f -> parseFileWithMode defaultParseMode{ parseFilename = f, extensions = es} f
+
parseFile' fname = do
- res <- parseFile fname
+ res <- parser fname
case res of
ParseOk m -> return $ collectDeclarations m
ParseFailed srcLoc message -> do
Please sign in to comment.
Something went wrong with that request. Please try again.