-- //     [17] line(n) ::=
-- //             space(n) (list|group)?  space? comment? break  |
-- //             space? comment? break |
-- //             space(n) block

-- In order to parse this structurally, I am going to parse a
-- line and all its children in one go, so my function will
-- be called 'tree' instead of 'line'

tree = do whiteSpace
          indent <?> "correct indentation"
          ts <- list
          whiteSpace
          sf <- many (try tree) >>= return . concat
          popStack
          case ts of
               [] -> unexpected "lack of nodes"
               ((Node x ys):zs) -> return ((Node x (ys++sf)):zs)

-- //     [18] graph ::= line* end

--ogdl = liftM (ogdlRoot . concat) $ tree `sepEndBy1` whiteSpace
--  where ogdlRoot xs = [Node "OGDL" xs]
tree = do whiteSpace
          indent <?> "correct indentation"
          ts <- list
          whiteSpace
          sf <- many (try tree) >>= return . concat
          popStack
          case ts of
               [] -> unexpected "lack of nodes"
               ((Node x ys):zs) -> return ((Node x (ys++sf)):zs)

-- //     [18] graph ::= line* end

--ogdl = liftM (ogdlRoot . concat) $ tree `sepEndBy1` whiteSpace
--  where ogdlRoot xs = [Node "OGDL" xs]
tree = do whiteSpace
          indent <?> "correct indentation"
          ts <- list
          whiteSpace
          sf <- many (try tree) >>= return . concat
          popStack
          case ts of
               [] -> unexpected "lack of nodes"
               ((Node x ys):zs) -> return ((Node x (ys++sf)):zs)

-- //     [18] graph ::= line* end

--ogdl = liftM (ogdlRoot . concat) $ tree `sepEndBy1` whiteSpace
--  where ogdlRoot xs = [Node "OGDL" xs]