mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-04 08:42:50 -06:00
Added regexps grammar printer. This is a first step towards recursion-free SRGS.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
-- This module prints a grammar as a regular expression.
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
module GF.Speech.PrRegExp (regexpPrinter) where
|
||||
module GF.Speech.PrRegExp (regexpPrinter,multiRegexpPrinter) where
|
||||
|
||||
import GF.Conversion.Types
|
||||
import GF.Infra.Ident
|
||||
@@ -20,3 +20,16 @@ import GF.Compile.ShellState (StateGrammar)
|
||||
|
||||
regexpPrinter :: Options -> StateGrammar -> String
|
||||
regexpPrinter opts s = 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 (MFASym s) = s
|
||||
showLabel (MFASub l) = "<" ++ l ++ ">"
|
||||
|
||||
mfa2res :: MFA String -> [(String,RE (MFALabel String))]
|
||||
mfa2res (MFA start dfas) =
|
||||
[("START",f start)] ++ [(l,f dfa) | (l,dfa) <- dfas]
|
||||
where f = minimizeRE . dfa2re
|
||||
Reference in New Issue
Block a user