diff options
| author | bringert <bringert@cs.chalmers.se> | 2008-01-04 14:51:20 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2008-01-04 14:51:20 +0000 |
| commit | a68b2850e76a36c1f4ca032ea69c1ffa81b69885 (patch) | |
| tree | 01a0b82d654890ee3142d522885fb8d31738f496 /src/GF/Devel | |
| parent | d54c209e9dc37825b153232a56e4c5adbbb685b1 (diff) | |
Added -noparse flag to gfc. In the process, I refactored GF.Devel.GFC and GF.Command.Importing to use a common source to gfcc compilation function in the new module GF.Compile.API.
Diffstat (limited to 'src/GF/Devel')
| -rw-r--r-- | src/GF/Devel/GFC.hs | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/src/GF/Devel/GFC.hs b/src/GF/Devel/GFC.hs index 2cb9104c5..a72289a49 100644 --- a/src/GF/Devel/GFC.hs +++ b/src/GF/Devel/GFC.hs @@ -1,11 +1,9 @@ module GF.Devel.GFC (mainGFC) where -- module Main where -import GF.Devel.Compile +import GF.Compile.API import GF.Devel.PrintGFCC -import GF.Devel.GrammarToGFCC -import GF.GFCC.OptimizeGFCC -import GF.GFCC.CheckGFCC +import GF.GFCC.CId import GF.GFCC.DataGFCC import GF.GFCC.Raw.ParGFCCRaw import GF.GFCC.Raw.ConvertGFCC @@ -20,47 +18,43 @@ mainGFC xx = do case opts of _ | oElem (iOpt "help") opts -> putStrLn usageMsg _ | oElem (iOpt "-make") opts -> do - gr <- batchCompile opts fs - let name = justModuleName (last fs) - let (abs,gc0) = mkCanon2gfcc opts name gr - gc1 <- checkGFCCio gc0 - let gc = addParsers $ if oElem (iOpt "noopt") opts then gc1 else optGFCC gc1 - let target = targetName opts abs - let gfccFile = target ++ ".gfcc" - writeFile gfccFile (printGFCC gc) - putStrLn $ "wrote file " ++ gfccFile - mapM_ (alsoPrint opts target gc) printOptions + gfcc <- compileToGFCC opts fs + let gfccFile = targetNameGFCC opts (absname gfcc) + outputFile gfccFile (printGFCC gfcc) + mapM_ (alsoPrint opts gfcc) printOptions -- gfc -o target.gfcc source_1.gfcc ... source_n.gfcc _ | all ((=="gfcc") . fileSuffix) fs -> do gfccs <- mapM file2gfcc fs let gfcc = foldl1 unionGFCC gfccs - let abs = printCId $ absname gfcc - let target = targetName opts abs - let gfccFile = target ++ ".gfcc" - writeFile gfccFile (printGFCC gfcc) - putStrLn $ "wrote file " ++ gfccFile - mapM_ (alsoPrint opts target gfcc) printOptions + let gfccFile = targetNameGFCC opts (absname gfcc) + outputFile gfccFile (printGFCC gfcc) + mapM_ (alsoPrint opts gfcc) printOptions _ -> do mapM_ (batchCompile opts) (map return fs) putStrLn "Done." +targetName :: Options -> CId -> String targetName opts abs = case getOptVal opts (aOpt "target") of Just n -> n - _ -> abs + _ -> prIdent abs + +targetNameGFCC :: Options -> CId -> FilePath +targetNameGFCC opts abs = targetName opts abs ++ ".gfcc" ---- TODO: nicer and richer print options -alsoPrint opts abs gr (opt,name) = do +alsoPrint opts gr (opt,name) = do if oElem (iOpt opt) opts - then do - let outfile = name - let output = prGFCC opt gr - writeFile outfile output - putStrLn $ "wrote file " ++ outfile + then outputFile name (prGFCC opt gr) else return () +outputFile :: FilePath -> String -> IO () +outputFile outfile output = + do writeFile outfile output + putStrLn $ "wrote file " ++ outfile + printOptions = [ ("haskell","GSyntax.hs"), ("haskell_gadt","GSyntax.hs"), @@ -69,4 +63,4 @@ printOptions = [ ] usageMsg = - "usage: gfc (-h | --make (-noopt) (-target=PREFIX) (-js | -jsref | -haskell | -haskell_gadt)) (-src) FILES" + "usage: gfc (-h | --make (-noopt) (-noparse) (-target=PREFIX) (-js | -jsref | -haskell | -haskell_gadt)) (-src) FILES" |
