summaryrefslogtreecommitdiff
path: root/src-3.0/GF/Compile/Export.hs
blob: 81d9e3140a2266b3e3e35f75be8ecea3e4835952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module GF.Compile.Export where

import PGF.CId
import PGF.Data (PGF(..))
import PGF.Raw.Print (printTree)
import PGF.Raw.Convert (fromPGF)
import GF.Compile.GFCCtoHaskell
import GF.Compile.GFCCtoJS
import GF.Infra.Option
import GF.Speech.SRGS
import GF.Text.UTF8

-- top-level access to code generation

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 name
  FmtHaskell_GADT -> grammar2haskellGADT gr name
  FmtSRGS_XML     -> srgsXmlPrinter Nothing gr (outputConcr gr)

-- | Get the name of the concrete syntax to generate output from.
-- FIXME: there should be an option to change this.
outputConcr :: PGF -> CId
outputConcr pgf = case cncnames pgf of
                    []     -> error "No concrete syntax."
                    cnc:_  -> cnc

printPGF :: PGF -> String
printPGF = encodeUTF8 . printTree . fromPGF