diff --git a/src/Graph.hs b/src/Graph.hs index 219005c..1acbfef 100644 --- a/src/Graph.hs +++ b/src/Graph.hs @@ -3,6 +3,7 @@ module Graph ( Graph(..) , Vertex(..) + , Zipper(..) , editLabel , follow , open diff --git a/src/Transducer.hs b/src/Transducer.hs index 284c371..a6f26d6 100644 --- a/src/Transducer.hs +++ b/src/Transducer.hs @@ -7,7 +7,7 @@ module Transducer ( import Stream (Stream(..), merge) import qualified Stream (empty) -import Graph (Graph(..), Vertex(..), editLabel, follow, open, rewind, singleton, weave) +import Graph (Graph(..), Vertex(..), Zipper(..), editLabel, follow, open, rewind, singleton, weave) type Transducer input output = Graph input [output] @@ -24,7 +24,9 @@ fromList = foldl add empty run :: (Ord input, Eq output) => Transducer input output -> Stream input -> Stream output run transducer (Stream inputs) = foldl (\(Stream outputs) (input, stream) -> case follow transducer input of - Nothing -> Stream.empty + Nothing -> case context transducer of + Top -> run (rewind transducer) stream + _ -> Stream.empty Just newState@(Graph {focus}) -> Stream ((emit stream <$> label focus) ++ outputs) `merge` run newState stream ) Stream.empty inputs