@@ -80,9 +80,10 @@ makeLenses ''InputBuffer
81data InputState = InputState
81data InputState = InputState
82 { _unprocessedBytes :: ByteString
82 { _unprocessedBytes :: ByteString
83+ , _classifierState :: ClassifierState
83 , _appliedConfig :: Config
84 , _appliedConfig :: Config
84 , _inputBuffer :: InputBuffer
85 , _inputBuffer :: InputBuffer
85− , _classifier :: ByteString -> KClass
86+ , _classifier :: ClassifierState -> ByteString -> KClass
88makeLenses ''InputState
89makeLenses ''InputState
@@ -154,28 +155,40 @@ applyConfig _ _ = fail "(vty) applyConfig was not provided a complete configurat
154parseEvent :: InputM Event
155parseEvent :: InputM Event
155parseEvent = do
156parseEvent = do
156 c <- use classifier
157 c <- use classifier
158+ s <- use classifierState
157 b <- use unprocessedBytes
159 b <- use unprocessedBytes
158− case c b of
160+ case c s b of
159 Valid e remaining -> do
161 Valid e remaining -> do
160 logMsg $ "valid parse: " ++ show e
162 logMsg $ "valid parse: " ++ show e
161 logMsg $ "remaining: " ++ show remaining
163 logMsg $ "remaining: " ++ show remaining
164+ classifierState .= ClassifierStart
162 unprocessedBytes .= remaining
165 unprocessedBytes .= remaining
164− _ -> mzero
167+ _ -> mzero
166dropInvalid :: InputM ()
169dropInvalid :: InputM ()
167dropInvalid = do
170dropInvalid = do
168 c <- use classifier
171 c <- use classifier
172+ s <- use classifierState
169 b <- use unprocessedBytes
173 b <- use unprocessedBytes
178+ ClassifierStart -> ClassifierInChunk b []
179+ ClassifierInChunk p bs -> ClassifierInChunk p (b:bs)
180+ unprocessedBytes .= BS8.empty
170− when (c b == Invalid) $ do
181+ Invalid -> do
171− logMsg "dropping input bytes"
182+ logMsg "dropping input bytes"
183+ classifierState .= ClassifierStart
172− unprocessedBytes .= BS8.empty
184+ unprocessedBytes .= BS8.empty
174runInputProcessorLoop :: ClassifyMap -> Input -> IO ()
187runInputProcessorLoop :: ClassifyMap -> Input -> IO ()
175runInputProcessorLoop classifyTable input = do
188runInputProcessorLoop classifyTable input = do
176 let bufferSize = 1024
189 let bufferSize = 1024
177 allocaArray bufferSize $ \(bufferPtr :: Ptr Word8) -> do
190 allocaArray bufferSize $ \(bufferPtr :: Ptr Word8) -> do
178− s0 <- InputState BS8.empty
191+ s0 <- InputState BS8.empty ClassifierStart
179 <$> readIORef (_configRef input)
192 <$> readIORef (_configRef input)
180 <*> pure (InputBuffer bufferPtr bufferSize)
193 <*> pure (InputBuffer bufferPtr bufferSize)
181 <*> pure (classify classifyTable)
194 <*> pure (classify classifyTable)