@@ -30,6 +30,7 @@ compile :: ClassifyMap -> [Char] -> KClass
3030compile table = cl' where
3131 -- take all prefixes and create a set of these
3232 prefixSet = S.fromList $ concatMap (init . inits . fst) $ table
33+ maxValidInputLength = maximum (map (length . fst) table)
3334 eventForInput = M.fromList table
3435 cl' [] = Prefix
3536 cl' inputBlock = case M.lookup inputBlock eventForInput of
@@ -45,7 +46,7 @@ compile table = cl' where
4546 -- H: There will always be one match. The prefixSet contains, by definition, all
4647 -- prefixes of an event.
4748 False ->
48− let inputPrefixes = reverse $ tail $ inits inputBlock
49+ let inputPrefixes = reverse $ take maxValidInputLength $ tail $ inits inputBlock
4950 in case mapMaybe (\s -> (,) s `fmap` M.lookup s eventForInput) inputPrefixes of
5051 (s,e) : _ -> Valid e (drop (length s) inputBlock)
5152 -- neither a prefix or a full event.