From 2b63a895690e6f4eb57c0a1b95692b640b9d9e2c Mon Sep 17 00:00:00 2001 From: bringert Date: Mon, 25 Jun 2007 13:38:40 +0000 Subject: Some refactorings needed for recursion removal. --- src/GF/Speech/RegExp.hs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/GF/Speech/RegExp.hs') diff --git a/src/GF/Speech/RegExp.hs b/src/GF/Speech/RegExp.hs index 120a43d26..1842780ee 100644 --- a/src/GF/Speech/RegExp.hs +++ b/src/GF/Speech/RegExp.hs @@ -3,7 +3,8 @@ module GF.Speech.RegExp (RE(..), isEpsilon, isNull, unionRE, concatRE, seqRE, repeatRE, minimizeRE, - mapRE, joinRE, + mapRE, mapRE', joinRE, + symbolsRE, dfa2re, prRE) where import Data.List @@ -107,10 +108,13 @@ firstRE (REConcat (x:xs)) = (x, REConcat xs) firstRE r = (r,epsilonRE) mapRE :: (a -> b) -> RE a -> RE b -mapRE f (REConcat xs) = REConcat (map (mapRE f) xs) -mapRE f (REUnion xs) = REUnion (map (mapRE f) xs) -mapRE f (RERepeat xs) = RERepeat (mapRE f xs) -mapRE f (RESymbol s) = RESymbol (f s) +mapRE f = mapRE' (RESymbol . f) + +mapRE' :: (a -> RE b) -> RE a -> RE b +mapRE' f (REConcat xs) = REConcat (map (mapRE' f) xs) +mapRE' f (REUnion xs) = REUnion (map (mapRE' f) xs) +mapRE' f (RERepeat x) = RERepeat (mapRE' f x) +mapRE' f (RESymbol s) = f s joinRE :: RE (RE a) -> RE a joinRE (REConcat xs) = REConcat (map joinRE xs) @@ -118,6 +122,12 @@ joinRE (REUnion xs) = REUnion (map joinRE xs) joinRE (RERepeat xs) = RERepeat (joinRE xs) joinRE (RESymbol ss) = ss +symbolsRE :: RE a -> [a] +symbolsRE (REConcat xs) = concatMap symbolsRE xs +symbolsRE (REUnion xs) = concatMap symbolsRE xs +symbolsRE (RERepeat x) = symbolsRE x +symbolsRE (RESymbol x) = [x] + -- Debugging prRE :: RE String -> String -- cgit v1.2.3