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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -