git.iko.soy/typeable/attoparsec
on master help sign in
Add pMatch function in accordance with Jeremy Shaw's wishes
commit19f3404e4f303b8e223c425a85093ad5056d84bf authorSamuel Bronson <naesten@gmail.com> dateTue 22 Aug 2006, 10:37 (20 years ago) parentcc634a2
1 file changed+11
ByteStringParser.hs+11
ByteStringParser.hs+11
@@ -76,6 +76,10 @@ p <?> msg =
7676 (Left _) -> Left (st, [msg])
7777 ok -> ok
7878
79+-- |get remaining input
80+getInput :: Parser C.ByteString C.ByteString
81+getInput = Parser (\st -> Right (st,st))
82+
7983
8084-- * Things like in @Parsec.Char@
8185
@@ -148,6 +152,13 @@ notEmpty (Parser p) =
148152 else o
149153 x -> x
150154
155+-- | parse some input with the given parser and return that input without copying it
156+pMatch :: Parser C.ByteString a -> Parser C.ByteString C.ByteString
157+pMatch p = do start <- getInput
158+ p
159+ end <- getInput
160+ return (C.take (C.length start - C.length end) start)
161+
151162
152163-- * Running parsers
153164