@@ -30,6 +30,7 @@ compile :: ClassifyMap -> [Char] -> KClass
30compile table = cl' where
30compile table = cl' where
31 -- take all prefixes and create a set of these
31 -- take all prefixes and create a set of these
32 prefixSet = S.fromList $ concatMap (init . inits . fst) $ table
32 prefixSet = S.fromList $ concatMap (init . inits . fst) $ table
33+ maxValidInputLength = maximum (map (length . fst) table)
33 eventForInput = M.fromList table
34 eventForInput = M.fromList table
34 cl' [] = Prefix
35 cl' [] = Prefix
35 cl' inputBlock = case M.lookup inputBlock eventForInput of
36 cl' inputBlock = case M.lookup inputBlock eventForInput of
@@ -45,7 +46,7 @@ compile table = cl' where
45 -- H: There will always be one match. The prefixSet contains, by definition, all
46 -- H: There will always be one match. The prefixSet contains, by definition, all
46 -- prefixes of an event.
47 -- prefixes of an event.
48− let inputPrefixes = reverse $ tail $ inits inputBlock
49+ let inputPrefixes = reverse $ take maxValidInputLength $ tail $ inits inputBlock
49 in case mapMaybe (\s -> (,) s `fmap` M.lookup s eventForInput) inputPrefixes of
50 in case mapMaybe (\s -> (,) s `fmap` M.lookup s eventForInput) inputPrefixes of
50 (s,e) : _ -> Valid e (drop (length s) inputBlock)
51 (s,e) : _ -> Valid e (drop (length s) inputBlock)
51 -- neither a prefix or a full event.
52 -- neither a prefix or a full event.