summaryrefslogtreecommitdiff
path: root/edit-lens/src/Data/String/DFST.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-05-21 16:14:26 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-05-21 16:14:26 +0200
commitd3f6fdc3ea71386c2b9a9cd5a686455dbee3e60e (patch)
treeb62e4748b8e058a5ab4122accf6b33e15bdd9b49 /edit-lens/src/Data/String/DFST.hs
parenteb599b2394e62842423cc0bbee2432a9cae95f4b (diff)
downloadincremental-dfsts-d3f6fdc3ea71386c2b9a9cd5a686455dbee3e60e.tar
incremental-dfsts-d3f6fdc3ea71386c2b9a9cd5a686455dbee3e60e.tar.gz
incremental-dfsts-d3f6fdc3ea71386c2b9a9cd5a686455dbee3e60e.tar.bz2
incremental-dfsts-d3f6fdc3ea71386c2b9a9cd5a686455dbee3e60e.tar.xz
incremental-dfsts-d3f6fdc3ea71386c2b9a9cd5a686455dbee3e60e.zip
Introduce FSTs & Generalize input/output
`toFST` is currently invalid
Diffstat (limited to 'edit-lens/src/Data/String/DFST.hs')
-rw-r--r--edit-lens/src/Data/String/DFST.hs42
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{-|
5Description: Deterministic finite state transducers
6-}
7module Data.String.DFST
8 ( DFST(..)
9 , runDFST, runDFST'
10 ) where
11
12import Data.Map.Strict (Map, (!?))
13import qualified Data.Map.Strict as Map
14
15import Data.Set (Set)
16import qualified Data.Set as Set
17
18import Control.Monad
19
20data 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
27runDFST :: forall state. Ord state => DFST state -> String -> Maybe String
28runDFST dfst@DFST{..} str = let (finalState, str') = runDFST' dfst stInitial str id
29 in str' "" <$ guard (finalState `Set.member` stAccept)
30
31runDFST' :: 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
37runDFST' _ st [] acc = (st, acc)
38runDFST' 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