-- | Interface to the Futhark parser.
module Language.Futhark.Parser
  ( parseFuthark,
    parseExp,
    parseModExp,
    parseType,
    parseValue,
    parseValues,
    parseDecOrExpIncrM,
    ParseError (..),
    scanTokensText,
    L (..),
    Token (..),
  )
where

import qualified Data.Text as T
import Language.Futhark.Parser.Lexer
import Language.Futhark.Parser.Parser
import Language.Futhark.Prop
import Language.Futhark.Syntax

-- | Parse an entire Futhark program from the given 'T.Text', using
-- the 'FilePath' as the source name for error messages.
parseFuthark ::
  FilePath ->
  T.Text ->
  Either ParseError UncheckedProg
parseFuthark :: FilePath -> Text -> Either ParseError UncheckedProg
parseFuthark = ParserMonad UncheckedProg
-> FilePath -> Text -> Either ParseError UncheckedProg
forall a. ParserMonad a -> FilePath -> Text -> Either ParseError a
parse ParserMonad UncheckedProg
prog

-- | Parse an Futhark expression from the given 'String', using the
-- 'FilePath' as the source name for error messages.
parseExp ::
  FilePath ->
  T.Text ->
  Either ParseError UncheckedExp
parseExp :: FilePath -> Text -> Either ParseError UncheckedExp
parseExp = ParserMonad UncheckedExp
-> FilePath -> Text -> Either ParseError UncheckedExp
forall a. ParserMonad a -> FilePath -> Text -> Either ParseError a
parse ParserMonad UncheckedExp
expression

-- | Parse a Futhark module expression from the given 'String', using the
-- 'FilePath' as the source name for error messages.
parseModExp ::
  FilePath ->
  T.Text ->
  Either ParseError (ModExpBase NoInfo Name)
parseModExp :: FilePath -> Text -> Either ParseError (ModExpBase NoInfo Name)
parseModExp = ParserMonad (ModExpBase NoInfo Name)
-> FilePath -> Text -> Either ParseError (ModExpBase NoInfo Name)
forall a. ParserMonad a -> FilePath -> Text -> Either ParseError a
parse ParserMonad (ModExpBase NoInfo Name)
modExpression

-- | Parse an Futhark type from the given 'String', using the
-- 'FilePath' as the source name for error messages.
parseType ::
  FilePath ->
  T.Text ->
  Either ParseError UncheckedTypeExp
parseType :: FilePath -> Text -> Either ParseError UncheckedTypeExp
parseType = ParserMonad UncheckedTypeExp
-> FilePath -> Text -> Either ParseError UncheckedTypeExp
forall a. ParserMonad a -> FilePath -> Text -> Either ParseError a
parse ParserMonad UncheckedTypeExp
futharkType

-- | Parse any Futhark value from the given 'String', using the 'FilePath'
-- as the source name for error messages.
parseValue ::
  FilePath ->
  T.Text ->
  Either ParseError Value
parseValue :: FilePath -> Text -> Either ParseError Value
parseValue = ParserMonad Value -> FilePath -> Text -> Either ParseError Value
forall a. ParserMonad a -> FilePath -> Text -> Either ParseError a
parse ParserMonad Value
anyValue

-- | Parse several Futhark values (separated by anything) from the given
-- 'String', using the 'FilePath' as the source name for error
-- messages.
parseValues ::
  FilePath ->
  T.Text ->
  Either ParseError [Value]
parseValues :: FilePath -> Text -> Either ParseError [Value]
parseValues = ParserMonad [Value]
-> FilePath -> Text -> Either ParseError [Value]
forall a. ParserMonad a -> FilePath -> Text -> Either ParseError a
parse ParserMonad [Value]
anyValues