haskell - How to read exact N chars with Parsec? -


i'm new haskell , parsec. wish parse php-serialize format of string 's:numb:"string";'

s:12:"123";6789012";

where number count of chars. so, function looks like:

newtype phpstring = phpstring string  pstring :: genparser char st phpstring pstring = { string "s:"         ; value1 <- many1 digit         ; string ":\""         ; value2 <- takeexactnchars (read value1)          ; string "\";"               ; return $ phpstring value2     }              takeexactnchars n = ??????? 

i write using replicatem control.monad:

import text.parsercombinators.parsec import control.monad (replicatem)  pstring :: parser string pstring = string "s:"              n <- fmap read (many1 digit)              string ":\""         -- bug fix; weren't picking colon              s <- replicatem n anychar              string "\";"              return s 

testing in ghci:

*main> parse pstring "" "s:12:\"123\";6789012\";" right "123\";6789012" 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -