@@ -20,7 +20,7 @@ import Control.Monad.Trans.Reader (ReaderT(..))
20import Data.Char
20import Data.Char
21import Data.Default
21import Data.Default
22import Data.IORef
22import Data.IORef
23−import Data.List( inits )
23+import Data.List(tails,inits)
24import qualified Data.Map as M( fromList, lookup )
24import qualified Data.Map as M( fromList, lookup )
25import Data.Maybe ( mapMaybe )
25import Data.Maybe ( mapMaybe )
26import qualified Data.Set as S( fromList, member )
26import qualified Data.Set as S( fromList, member )
@@ -160,12 +160,15 @@ compile table = cl' where
160 True -> Prefix
160 True -> Prefix
161 -- if the input_block is exactly what is expected for an event then consume the whole
161 -- if the input_block is exactly what is expected for an event then consume the whole
162 -- block and return the event
162 -- block and return the event
163− -- look up progressively large prefixes of the input block until an event is found
163+ -- look up progressively smaller tails of the input block until an event is found
164+ -- The assumption is that the event that consumes the most input bytes should be
166+ -- The test verify_full_syn_input_to_event_2x verifies this.
164 -- H: There will always be one match. The prefix_set contains, by definition, all
167 -- H: There will always be one match. The prefix_set contains, by definition, all
165 -- prefixes of an event.
168 -- prefixes of an event.
167− let input_prefixes = init $ inits input_block
170+ let input_tails = init $ tail $ tails input_block
168− in case mapMaybe (\s -> (,) s `fmap` M.lookup s event_for_input) input_prefixes of
171+ in case mapMaybe (\s -> (,) s `fmap` M.lookup s event_for_input) input_tails of
169 (s,e) : _ -> Valid e (drop (length s) input_block)
172 (s,e) : _ -> Valid e (drop (length s) input_block)
170 -- neither a prefix or a full event. Might be interesting to log.
173 -- neither a prefix or a full event. Might be interesting to log.
171 [] -> Invalid
174 [] -> Invalid