-- |
-- Module       : Data.TPTP.Parse.Text
-- Description  : An attoparsec-based parser for the TPTP language.
-- Copyright    : (c) Evgenii Kotelnikov, 2019-2021
-- License      : GPL-3
-- Maintainer   : evgeny.kotelnikov@gmail.com
-- Stability    : experimental
--

module Data.TPTP.Parse.Text (
  -- * Runners of parsers for TPTP units
  parseUnit,
  parseUnitOnly,
  parseUnitWith,

  -- * Runners of parsers for TPTP inputs
  parseTPTP,
  parseTPTPOnly,
  parseTPTPWith,

  -- * Runners of parsers for TSTP inputs
  parseTSTP,
  parseTSTPOnly,
  parseTSTPWith,
) where

import Data.Attoparsec.Text (Result, parse, parseOnly, parseWith)
import Data.Text (Text)

import Data.TPTP (Unit, TPTP, TSTP)
import Data.TPTP.Parse.Combinators (input, unit, tptp, tstp)


-- | Run a parser for a single TPTP unit on 'Text'.
parseUnit :: Text -> Result Unit
parseUnit :: Text -> Result Unit
parseUnit = Parser Unit -> Text -> Result Unit
forall a. Parser a -> Text -> Result a
parse (Parser Unit -> Parser Unit
forall a. Parser a -> Parser a
input Parser Unit
unit)

-- | Run a parser for a single TPTP unit that cannot be resupplied
-- via a 'Data.Attoparsec.Text.Partial' result.
parseUnitOnly :: Text -> Either String Unit
parseUnitOnly :: Text -> Either String Unit
parseUnitOnly = Parser Unit -> Text -> Either String Unit
forall a. Parser a -> Text -> Either String a
parseOnly (Parser Unit -> Parser Unit
forall a. Parser a -> Parser a
input Parser Unit
unit)

-- | Run a parser for a single TPTP unit with an initial input string,
-- and a monadic action that can supply more input if needed.
parseUnitWith :: Monad m => m Text -> Text -> m (Result Unit)
parseUnitWith :: m Text -> Text -> m (Result Unit)
parseUnitWith m Text
m = m Text -> Parser Unit -> Text -> m (Result Unit)
forall (m :: * -> *) a.
Monad m =>
m Text -> Parser a -> Text -> m (Result a)
parseWith m Text
m (Parser Unit -> Parser Unit
forall a. Parser a -> Parser a
input Parser Unit
unit)

-- | Run a parser for a TPTP input on 'Text'.
parseTPTP :: Text -> Result TPTP
parseTPTP :: Text -> Result TPTP
parseTPTP = Parser TPTP -> Text -> Result TPTP
forall a. Parser a -> Text -> Result a
parse (Parser TPTP -> Parser TPTP
forall a. Parser a -> Parser a
input Parser TPTP
tptp)

-- | Run a parser for a TPTP input that cannot be resupplied
-- via a 'Data.Attoparsec.Text.Partial' result.
parseTPTPOnly :: Text -> Either String TPTP
parseTPTPOnly :: Text -> Either String TPTP
parseTPTPOnly = Parser TPTP -> Text -> Either String TPTP
forall a. Parser a -> Text -> Either String a
parseOnly (Parser TPTP -> Parser TPTP
forall a. Parser a -> Parser a
input Parser TPTP
tptp)

-- | Run a parser for a TPTP input with an initial input string,
-- and a monadic action that can supply more input if needed.
parseTPTPWith :: Monad m => m Text -> Text -> m (Result TPTP)
parseTPTPWith :: m Text -> Text -> m (Result TPTP)
parseTPTPWith m Text
m = m Text -> Parser TPTP -> Text -> m (Result TPTP)
forall (m :: * -> *) a.
Monad m =>
m Text -> Parser a -> Text -> m (Result a)
parseWith m Text
m (Parser TPTP -> Parser TPTP
forall a. Parser a -> Parser a
input Parser TPTP
tptp)

-- | Run a parser for a TSTP input on 'Text'.
parseTSTP :: Text -> Result TSTP
parseTSTP :: Text -> Result TSTP
parseTSTP = Parser TSTP -> Text -> Result TSTP
forall a. Parser a -> Text -> Result a
parse Parser TSTP
tstp

-- | Run a parser for a TSTP input that cannot be resupplied
-- via a 'Data.Attoparsec.Text.Partial' result.
parseTSTPOnly :: Text -> Either String TSTP
parseTSTPOnly :: Text -> Either String TSTP
parseTSTPOnly = Parser TSTP -> Text -> Either String TSTP
forall a. Parser a -> Text -> Either String a
parseOnly Parser TSTP
tstp

-- | Run a parser for a TSTP input with an initial input string,
-- and a monadic action that can supply more input if needed.
parseTSTPWith :: Monad m => m Text -> Text -> m (Result TSTP)
parseTSTPWith :: m Text -> Text -> m (Result TSTP)
parseTSTPWith m Text
m = m Text -> Parser TSTP -> Text -> m (Result TSTP)
forall (m :: * -> *) a.
Monad m =>
m Text -> Parser a -> Text -> m (Result a)
parseWith m Text
m Parser TSTP
tstp