git.iko.soy/typeable/attoparsec
on master help sign in
#105 keep state around with the `Finished` as scanner is applied recursively and otherwise shortcutting might fail
commit057dfcc75aff4e2eadc002da1c9ed60dc90adf88 authorMarcin Tolysz <tolysz@gmail.com> dateThu 22 Oct 2015, 20:09 (11 years ago) parent4f13734
1 file changed+4−4
Data/Attoparsec/Text/Internal.hs+4−4
Data/Attoparsec/Text/Internal.hs+4−4
@@ -299,7 +299,7 @@ takeLazyText :: Parser L.Text
299299takeLazyText = L.fromChunks `fmap` takeRest
300300
301301data Scan s = Continue s
302− | Finished {-# UNPACK #-} !Int Text
302+ | Finished s {-# UNPACK #-} !Int Text
303303
304304scan_ :: (s -> [Text] -> Parser r) -> s -> (s -> Char -> Maybe s) -> Parser r
305305scan_ f s0 p = go [] s0
@@ -308,7 +308,7 @@ scan_ f s0 p = go [] s0
308308 case T.uncons t of
309309 Just (c,t') -> case p s c of
310310 Just s' -> scanner s' (n+1) t'
311− Nothing -> Finished n t
311+ Nothing -> Finished s n t
312312 Nothing -> Continue s
313313 go acc s = do
314314 input <- get
@@ -317,8 +317,8 @@ scan_ f s0 p = go [] s0
317317 if continue
318318 then go (input : acc) s'
319319 else f s' (input : acc)
320− Finished n t -> do advance (size input - size t)
321− f s (T.take n input : acc)
320+ Finished s' n t -> do advance (size input - size t)
321+ f s' (T.take n input : acc)
322322{-# INLINE scan_ #-}
323323
324324-- | A stateful scanner. The predicate consumes and transforms a