[Haskell-cafe] Am I using Parsec correctly?

Cody Goodman codygman.consulting at gmail.com
Tue Mar 3 10:00:26 UTC 2015


-- trying to parse the text below using Parsec:

-- ACT I.

-- SCENE I. An open place.
-- [An open place. Thunder and lightning. Enter three Witches.]

--   FIRST WITCH.
--     When shall we three meet again
--     In thunder, lightning, or in rain?

-- Here's the code I have

import Text.Parsec
import Control.Applicative
import Data.Traversable (sequenceA)

section s = sequenceA [string s, string " ", many1 letter] `endBy` char '.'

act = section "ACT"
scene = section "SCENE"

main = do
  parseTest act "ACT I.\n"
  parseTest scene "SCENE I."

-- this returns:
-- λ> main
-- [["ACT"," ","I"]]
-- [["SCENE"," ","I"]]

-- Am I using Parsec correctly so far?
-- After this I want to match acts (many1 act) and scenes (many1 scene) and
I believe I see how to do that, just wanting to make sure I'm on the right
track.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150303/d5181891/attachment.html>


More information about the Haskell-Cafe mailing list