diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-05-21 09:26:44 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-05-21 09:26:44 +0000 |
| commit | 055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f (patch) | |
| tree | 0e63fb68c69c8f6ad0f78893c63420f0a3600e1c /src-3.0/GF/Speech/PrRegExp.hs | |
| parent | 915a1de71783ab8446b1af9e72c7ba7dfbc12d3f (diff) | |
GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3
Diffstat (limited to 'src-3.0/GF/Speech/PrRegExp.hs')
| -rw-r--r-- | src-3.0/GF/Speech/PrRegExp.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src-3.0/GF/Speech/PrRegExp.hs b/src-3.0/GF/Speech/PrRegExp.hs new file mode 100644 index 000000000..55a25d69b --- /dev/null +++ b/src-3.0/GF/Speech/PrRegExp.hs @@ -0,0 +1,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] |
