summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Compiler.hs
diff options
context:
space:
mode:
authorThomas H <Thomas-H@users.noreply.github.com>2019-02-21 14:26:11 +0100
committerGitHub <noreply@github.com>2019-02-21 14:26:11 +0100
commitb6fd9a7744dd170950d7ffb654c11b036564fb81 (patch)
treee8dceb47c970e0431e65a9992053f3dbdd28305e /src/compiler/GF/Compiler.hs
parent64a2483b12f17e98160a5974a3015a54629de480 (diff)
parentf8346c4557f5e29e85245f259bce952014870dd6 (diff)
Merge pull request #34 from heatherleaf/master
Encode/decode of canonical grammars to/from JSON/YAML
Diffstat (limited to 'src/compiler/GF/Compiler.hs')
-rw-r--r--src/compiler/GF/Compiler.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/compiler/GF/Compiler.hs b/src/compiler/GF/Compiler.hs
index 2bd0fc0cb..539b0b341 100644
--- a/src/compiler/GF/Compiler.hs
+++ b/src/compiler/GF/Compiler.hs
@@ -24,6 +24,7 @@ import Data.Maybe
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.ByteString.Lazy as BSL
+import GF.Grammar.CanonicalJSON (encodeJSON, encodeYAML)
import System.FilePath
import Control.Monad(when,unless,forM_)
@@ -48,7 +49,7 @@ mainGFC opts fs = do
compileSourceFiles :: Options -> [FilePath] -> IOE ()
compileSourceFiles opts fs =
do output <- batchCompile opts fs
- exportCncs output
+ exportCanonical output
unless (flag optStopAfterPhase opts == Compile) $
linkGrammars opts output
where
@@ -56,13 +57,15 @@ compileSourceFiles opts fs =
batchCompile' opts fs = do (t,cnc_gr) <- S.batchCompile opts fs
return (t,[cnc_gr])
- exportCncs output =
+ exportCanonical (_time, canonical) =
do when (FmtHaskell `elem` ofmts && haskellOption opts HaskellConcrete) $
- mapM_ cnc2haskell (snd output)
+ mapM_ cnc2haskell canonical
when (FmtCanonicalGF `elem` ofmts) $
do createDirectoryIfMissing False "canonical"
- mapM_ abs2canonical (snd output)
- mapM_ cnc2canonical (snd output)
+ mapM_ abs2canonical canonical
+ mapM_ cnc2canonical canonical
+ when (FmtCanonicalJson `elem` ofmts) $ mapM_ grammar2json canonical
+ when (FmtCanonicalYaml `elem` ofmts) $ mapM_ grammar2yaml canonical
where
ofmts = flag optOutputFormats opts
@@ -79,6 +82,14 @@ compileSourceFiles opts fs =
mapM_ (writeExport.fmap render80) $
concretes2canonical opts (srcAbsName gr cnc) gr
+ grammar2json (cnc,gr) = encodeJSON (render absname ++ ".json") gr_canon
+ where absname = srcAbsName gr cnc
+ gr_canon = grammar2canonical opts absname gr
+
+ grammar2yaml (cnc,gr) = encodeYAML (render absname ++ ".yaml") gr_canon
+ where absname = srcAbsName gr cnc
+ gr_canon = grammar2canonical opts absname gr
+
writeExport (path,s) = writing opts path $ writeUTF8File path s