summaryrefslogtreecommitdiff
path: root/src/GF/Speech/PrRegExp.hs
blob: 55a25d69b71897d7270d3b2bb55813c4216c83ce (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
----------------------------------------------------------------------
-- |
-- Module      : PrSLF
-- Maintainer  : BB
-- Stability   : (stable)
-- Portability : (portable)
--
-- This module prints a grammar as a regular expression.
-----------------------------------------------------------------------------

module GF.Speech.PrRegExp (regexpPrinter,multiRegexpPrinter) where

import GF.Conversion.Types
import GF.Formalism.Utilities
import GF.Infra.Ident
import GF.Infra.Option (Options)
import GF.Speech.CFGToFiniteState
import GF.Speech.RegExp
import GF.Compile.ShellState (StateGrammar)


regexpPrinter :: Options -> StateGrammar -> String
regexpPrinter opts s = (++"\n") $ prRE $ dfa2re $ cfgToFA opts s

multiRegexpPrinter :: Options -> StateGrammar -> String
multiRegexpPrinter opts s = prREs $ mfa2res $ cfgToMFA opts s

prREs :: [(String,RE (MFALabel String))] -> String
prREs res = unlines [l ++ " = " ++ prRE (mapRE showLabel re) | (l,re) <- res]
  where showLabel = symbol (\l -> "<" ++ l ++ ">") id

mfa2res :: MFA String -> [(String,RE (MFALabel String))]
mfa2res (MFA _ dfas) = [(l, minimizeRE (dfa2re dfa)) | (l,dfa) <- dfas]