Effective Haskell:Chapter 13 (B9 - PDF version) - infinite loop when running the ClassyArchiver code

Refer to pages 508-511

I get an infinite loop when running the original parseArchive function, after adding a variable called "archiveDef, which codifies the example given on p.491.


archiveDef :: Text
archiveDef = Text.unlines $
  [ "archive \"example.archive\":"
  , ""
  , "import \"./extras/example1.txt\""
  , ""
  , "new-file \"inline-example.txt\":"
  , "     this is some text"
  , "     it can have newlines"
  , "     but it needs to be indented"
  , ""
  , "import \"./extras/example2.txt\""
  ]

λ> runArchiver archiveDef parseArchive

I’ve changed the parseArchive function by removing “parseBlock”.
I commented out the original line and added the modification under it.


parseArchive :: Archiver Archive
parseArchive = do
    expectText "archive"
    dropSpaces
    archiveName <- quotedString
    expectText ":\n"
    -- files <- parseBlock parseArchiveStatements
    files <- parseArchiveStatements               -- CHANGE HERE
    pure $ Archive archiveName files

The infinite loop disappears when using this modified version.