summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Compiler.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2014-12-11 16:08:36 +0000
committerhallgren <hallgren@chalmers.se>2014-12-11 16:08:36 +0000
commit2eaf46f6104d02f25c5a0551af08114dac6b63e9 (patch)
treee2fa8d146d7908497165f1a96c9397a11b6b7bd8 /src/compiler/GF/Compiler.hs
parent9be0c216769b7ba31e7f6e7dca28de3c9cecd4a3 (diff)
Work in progress on translating linearization functions to Haskell
The translation is currently good enough to translate all concrete syntaxes of the Foods and Letter grammars, and some concrete syntaxes of the Phrasebook grammar (e.g. PhrasebookEng & PhrasebookSpa works, but there are problems with e.g. PhrasebookSwe and PhrasebookChi) This functionality is enabled by running gf -make -output-format=haskell -haskell=concrete ... TODO: - variants - pre { ... } - eta expansion of linearization functions - record subtyping can still cause type errors in the Haskell code in some cases - reduce code large tables
Diffstat (limited to 'src/compiler/GF/Compiler.hs')
-rw-r--r--src/compiler/GF/Compiler.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/compiler/GF/Compiler.hs b/src/compiler/GF/Compiler.hs
index 57d0b6e03..cd27c487b 100644
--- a/src/compiler/GF/Compiler.hs
+++ b/src/compiler/GF/Compiler.hs
@@ -6,6 +6,7 @@ import PGF.Internal(putSplitAbs,encodeFile,runPut)
import GF.Compile as S(batchCompile,link,srcAbsName)
import GF.CompileInParallel as P(parallelBatchCompile)
import GF.Compile.Export
+import GF.Compile.ConcreteToHaskell(concretes2haskell)
import GF.Compile.CFGtoPGF
import GF.Compile.GetGrammar
import GF.Grammar.CFG
@@ -22,7 +23,7 @@ import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString.Lazy as BSL
import System.FilePath
-import Control.Monad(unless,forM_)
+import Control.Monad(when,unless,forM_)
-- | Compile the given GF grammar files. The result is a number of @.gfo@ files
-- and, depending on the options, a @.pgf@ file. (@gf -batch@, @gf -make@)
@@ -45,6 +46,7 @@ mainGFC opts fs = do
compileSourceFiles :: Options -> [FilePath] -> IOE ()
compileSourceFiles opts fs =
do output <- batchCompile opts fs
+ cncs2haskell output
unless (flag optStopAfterPhase opts == Compile) $
linkGrammars opts output
where
@@ -52,6 +54,17 @@ compileSourceFiles opts fs =
batchCompile' opts fs = do (t,cnc_gr) <- S.batchCompile opts fs
return (t,[cnc_gr])
+ cncs2haskell output =
+ when (FmtHaskell `elem` outputFormats opts &&
+ haskellOption opts HaskellConcrete) $
+ mapM_ cnc2haskell (snd output)
+
+ cnc2haskell (cnc,gr) =
+ mapM_ writeHs $ concretes2haskell opts (srcAbsName gr cnc) gr
+
+ writeHs (path,s) = writing opts path $ writeUTF8File path s
+
+
-- | Create a @.pgf@ file (and possibly files in other formats, if specified
-- in the 'Options') from the output of 'parallelBatchCompile'.
-- If a @.pgf@ file by the same name already exists and it is newer than the