summaryrefslogtreecommitdiff
path: root/src-3.0
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-06-02 15:32:01 +0000
committerbjorn <bjorn@bringert.net>2008-06-02 15:32:01 +0000
commit5073ac4e7f4c24aa412ed3a3c3d719532df9f637 (patch)
treee9e60a0b58800dcc71aee9df2361852105c25574 /src-3.0
parent20ea9ea5ec7c65ab01bff47d78f55e06b85fe79d (diff)
Honor the --name flag when generating output files. Set module name in generated Haskell modules correctly.
Diffstat (limited to 'src-3.0')
-rw-r--r--src-3.0/GF/Command/Commands.hs2
-rw-r--r--src-3.0/GF/Compile/Export.hs13
-rw-r--r--src-3.0/GF/Compile/GFCCtoHaskell.hs18
-rw-r--r--src-3.0/GFC.hs5
4 files changed, 22 insertions, 16 deletions
diff --git a/src-3.0/GF/Command/Commands.hs b/src-3.0/GF/Command/Commands.hs
index 8761234cd..281c6f1cc 100644
--- a/src-3.0/GF/Command/Commands.hs
+++ b/src-3.0/GF/Command/Commands.hs
@@ -153,5 +153,5 @@ allCommands pgf = Map.fromAscList [
prGrammar opts = case valIdOpts "printer" "" opts of
"cats" -> unwords $ categories pgf
- v -> prPGF (read v) pgf
+ v -> prPGF (read v) pgf (prCId (absname pgf))
diff --git a/src-3.0/GF/Compile/Export.hs b/src-3.0/GF/Compile/Export.hs
index ab5dcb393..d6780147e 100644
--- a/src-3.0/GF/Compile/Export.hs
+++ b/src-3.0/GF/Compile/Export.hs
@@ -10,13 +10,16 @@ import GF.Text.UTF8
-- top-level access to code generation
-prPGF :: OutputFormat -> PGF -> String
-prPGF fmt gr = case fmt of
+prPGF :: OutputFormat
+ -> PGF
+ -> String -- ^ Output name, for example used for generated Haskell
+ -- module name.
+ -> String
+prPGF fmt gr name = case fmt of
FmtPGF -> printPGF gr
FmtJavaScript -> pgf2js gr
- FmtHaskell -> grammar2haskell gr
- FmtHaskellGADT -> grammar2haskellGADT gr
+ FmtHaskell -> grammar2haskell gr name
+ FmtHaskellGADT -> grammar2haskellGADT gr name
printPGF :: PGF -> String
printPGF = encodeUTF8 . printTree . fromPGF
-
diff --git a/src-3.0/GF/Compile/GFCCtoHaskell.hs b/src-3.0/GF/Compile/GFCCtoHaskell.hs
index 94210b65e..72e4cb922 100644
--- a/src-3.0/GF/Compile/GFCCtoHaskell.hs
+++ b/src-3.0/GF/Compile/GFCCtoHaskell.hs
@@ -27,24 +27,26 @@ import Data.List --(isPrefixOf, find, intersperse)
import qualified Data.Map as Map
-- | the main function
-grammar2haskell :: PGF -> String
-grammar2haskell gr = encodeUTF8 $ foldr (++++) [] $
- haskPreamble ++ [datatypes gr', gfinstances gr']
+grammar2haskell :: PGF
+ -> String -- ^ Module name.
+ -> String
+grammar2haskell gr name = encodeUTF8 $ foldr (++++) [] $
+ haskPreamble name ++ [datatypes gr', gfinstances gr']
where gr' = hSkeleton gr
-grammar2haskellGADT :: PGF -> String
-grammar2haskellGADT gr = encodeUTF8 $ foldr (++++) [] $
+grammar2haskellGADT :: PGF -> String -> String
+grammar2haskellGADT gr name = encodeUTF8 $ foldr (++++) [] $
["{-# OPTIONS_GHC -fglasgow-exts #-}"] ++
- haskPreamble ++ [datatypesGADT gr', gfinstances gr']
+ haskPreamble name ++ [datatypesGADT gr', gfinstances gr']
where gr' = hSkeleton gr
-- | by this you can prefix all identifiers with stg; the default is 'G'
gId :: OIdent -> OIdent
gId i = 'G':i
-haskPreamble =
+haskPreamble name =
[
- "module GSyntax where",
+ "module " ++ name ++ " where",
"",
"import PGF.CId",
"import PGF.Data",
diff --git a/src-3.0/GFC.hs b/src-3.0/GFC.hs
index 1c773630d..4e553659b 100644
--- a/src-3.0/GFC.hs
+++ b/src-3.0/GFC.hs
@@ -30,8 +30,9 @@ writeOutputs opts pgf = mapM_ (\fmt -> writeOutput opts fmt pgf) (flag optOutput
writeOutput :: Options -> OutputFormat-> PGF -> IOE ()
writeOutput opts fmt pgf =
- do let path = outputFilePath opts fmt (prCId (absname pgf))
- s = prPGF fmt pgf
+ do let name = fromMaybe (prCId (absname pgf)) (moduleFlag optName opts)
+ path = outputFilePath opts fmt name
+ s = prPGF fmt pgf name
writeOutputFile path s
outputFilePath :: Options -> OutputFormat -> String -> FilePath