summaryrefslogtreecommitdiff
path: root/src/GF/Speech/RegExp.hs
diff options
context:
space:
mode:
authorbringert <bringert@cs.chalmers.se>2007-06-25 13:38:40 +0000
committerbringert <bringert@cs.chalmers.se>2007-06-25 13:38:40 +0000
commit2b63a895690e6f4eb57c0a1b95692b640b9d9e2c (patch)
tree8006e803c44c86ba70473a7820fbb296345f8fa4 /src/GF/Speech/RegExp.hs
parentf081dc0d6bb73d5439420569c352e88b0f096a7f (diff)
Some refactorings needed for recursion removal.
Diffstat (limited to 'src/GF/Speech/RegExp.hs')
-rw-r--r--src/GF/Speech/RegExp.hs20
1 files changed, 15 insertions, 5 deletions
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