diff options
Diffstat (limited to 'edit-lens/src/Data/String/DFST.hs')
-rw-r--r-- | edit-lens/src/Data/String/DFST.hs | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/edit-lens/src/Data/String/DFST.hs b/edit-lens/src/Data/String/DFST.hs deleted file mode 100644 index 54a1336..0000000 --- a/edit-lens/src/Data/String/DFST.hs +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | {-# LANGUAGE ScopedTypeVariables | ||
2 | #-} | ||
3 | |||
4 | {-| | ||
5 | Description: Deterministic finite state transducers | ||
6 | -} | ||
7 | module Data.String.DFST | ||
8 | ( DFST(..) | ||
9 | , runDFST, runDFST' | ||
10 | ) where | ||
11 | |||
12 | import Data.Map.Strict (Map, (!?)) | ||
13 | import qualified Data.Map.Strict as Map | ||
14 | |||
15 | import Data.Set (Set) | ||
16 | import qualified Data.Set as Set | ||
17 | |||
18 | import Control.Monad | ||
19 | |||
20 | data DFST state = DFST | ||
21 | { stInitial :: state | ||
22 | , stTransition :: Map (state, Char) (state, String) | ||
23 | -- ^ All @(s, c)@-combinations not mapped are assumed to map to @(s, Nothing)@ | ||
24 | , stAccept :: Set state | ||
25 | } | ||
26 | |||
27 | runDFST :: forall state. Ord state => DFST state -> String -> Maybe String | ||
28 | runDFST dfst@DFST{..} str = let (finalState, str') = runDFST' dfst stInitial str id | ||
29 | in str' "" <$ guard (finalState `Set.member` stAccept) | ||
30 | |||
31 | runDFST' :: forall state. Ord state | ||
32 | => DFST state | ||
33 | -> state -- ^ Current state | ||
34 | -> String -- ^ Remaining input | ||
35 | -> (String -> String) -- ^ Output as difference list | ||
36 | -> (state, (String -> String)) -- ^ Next state, altered output | ||
37 | runDFST' _ st [] acc = (st, acc) | ||
38 | runDFST' dfst@DFST{..} st (c:cs) acc | ||
39 | | Just (st', mc') <- stTransition !? (st, c) | ||
40 | = runDFST' dfst st' cs $ acc . (mc' ++) | ||
41 | | otherwise | ||
42 | = runDFST' dfst st cs acc | ||