{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}

module Text.Heterocephalus.Parse
  ( module Text.Heterocephalus.Parse
  , module Text.Heterocephalus.Parse.Control
  , module Text.Heterocephalus.Parse.Doc
  , module Text.Heterocephalus.Parse.Option
  ) where

import Text.Heterocephalus.Parse.Control (Content(..), parseLineControl)
import Text.Heterocephalus.Parse.Doc
       (Doc(..), parseDocFromControls)
import Text.Heterocephalus.Parse.Option
       (ParseOptions(..), createParseOptions, defaultParseOptions)

docFromString :: ParseOptions -> String -> [Doc]
docFromString :: ParseOptions -> String -> [Doc]
docFromString ParseOptions
opts String
s =
  case ParseOptions -> String -> Either String [Doc]
parseDoc ParseOptions
opts String
s of
    Left String
s' -> String -> [Doc]
forall a. HasCallStack => String -> a
error String
s'
    Right [Doc]
d -> [Doc]
d

parseDoc :: ParseOptions -> String -> Either String [Doc]
parseDoc :: ParseOptions -> String -> Either String [Doc]
parseDoc ParseOptions
opts String
s = do
  [Control]
controls <- ParseOptions -> String -> Either String [Control]
parseLineControl ParseOptions
opts String
s
  case [Control] -> Either ParseError [Doc]
parseDocFromControls [Control]
controls of
    Left ParseError
parseError -> String -> Either String [Doc]
forall a b. a -> Either a b
Left (String -> Either String [Doc]) -> String -> Either String [Doc]
forall a b. (a -> b) -> a -> b
$ ParseError -> String
forall a. Show a => a -> String
show ParseError
parseError
    Right [Doc]
docs -> [Doc] -> Either String [Doc]
forall a b. b -> Either a b
Right [Doc]
docs