@@ -20,7 +20,7 @@ import Control.Monad.Trans.Reader (ReaderT(..))
2020import Data.Char
2121import Data.Default
2222import Data.IORef
23−import Data.List( inits )
23+import Data.List(tails,inits)
2424import qualified Data.Map as M( fromList, lookup )
2525import Data.Maybe ( mapMaybe )
2626import qualified Data.Set as S( fromList, member )
@@ -160,12 +160,15 @@ compile table = cl' where
160160 True -> Prefix
161161 -- if the input_block is exactly what is expected for an event then consume the whole
162162 -- 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
165+ -- produced.
166+ -- The test verify_full_syn_input_to_event_2x verifies this.
164167 -- H: There will always be one match. The prefix_set contains, by definition, all
165168 -- prefixes of an event.
166169 False ->
167− let input_prefixes = init $ inits input_block
168− in case mapMaybe (\s -> (,) s `fmap` M.lookup s event_for_input) input_prefixes of
170+ let input_tails = init $ tail $ tails input_block
171+ in case mapMaybe (\s -> (,) s `fmap` M.lookup s event_for_input) input_tails of
169172 (s,e) : _ -> Valid e (drop (length s) input_block)
170173 -- neither a prefix or a full event. Might be interesting to log.
171174 [] -> Invalid