feat: Parsing the constant magic flag
This commit is contained in:
parent
6a4d4e5051
commit
a4b5b06000
4 changed files with 26 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
{-# LANGUAGE DeriveFunctor #-}
|
||||
{-# LANGUAGE InstanceSigs #-}
|
||||
module Language.Java.Classfile.Extract (Extract(), bytes, runExtract) where
|
||||
module Language.Java.Classfile.Extract (Extract(), bytes, runExtract, expectRaw, expectEqual) where
|
||||
|
||||
import Data.ByteString.Lazy (ByteString)
|
||||
import qualified Data.ByteString.Lazy as ByteString
|
||||
|
@ -47,6 +47,20 @@ bytes count = Extract $ \ input -> let
|
|||
then Fail
|
||||
else Done rest bs
|
||||
|
||||
expectRaw :: ByteString -> Extract ByteString
|
||||
expectRaw e = Extract $ \ input -> let
|
||||
(actual, rest) = ByteString.splitAt (ByteString.length e) input
|
||||
in case actual == e of
|
||||
True -> Done rest actual
|
||||
False -> Fail
|
||||
|
||||
expectEqual :: Eq a => Extract a -> a -> Extract a
|
||||
expectEqual (Extract computeActual) expected = Extract $ \ input -> case computeActual input of
|
||||
Done rest actual -> if actual == expected
|
||||
then Done rest actual
|
||||
else Fail
|
||||
Fail -> Fail
|
||||
|
||||
{- It seems I cannot define a lawful monad instance
|
||||
instance Monad Extract where
|
||||
(>>=) :: Extract a -> (a -> Extract b) -> Extract b
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue