{-# LANGUAGE OverloadedStrings #-}
module Language.Futhark.Parser
( parseFuthark,
parseExp,
parseModExp,
parseType,
parseValue,
parseValues,
parseDecOrExpIncrM,
SyntaxError (..),
)
where
import qualified Data.Text as T
import Language.Futhark.Parser.Parser
import Language.Futhark.Prop
import Language.Futhark.Syntax
parseFuthark ::
FilePath ->
T.Text ->
Either SyntaxError UncheckedProg
parseFuthark :: FilePath -> Text -> Either SyntaxError UncheckedProg
parseFuthark = ParserMonad UncheckedProg
-> FilePath -> Text -> Either SyntaxError UncheckedProg
forall a. ParserMonad a -> FilePath -> Text -> Either SyntaxError a
parse ParserMonad UncheckedProg
prog
parseExp ::
FilePath ->
T.Text ->
Either SyntaxError UncheckedExp
parseExp :: FilePath -> Text -> Either SyntaxError UncheckedExp
parseExp = ParserMonad UncheckedExp
-> FilePath -> Text -> Either SyntaxError UncheckedExp
forall a. ParserMonad a -> FilePath -> Text -> Either SyntaxError a
parse ParserMonad UncheckedExp
expression
parseModExp ::
FilePath ->
T.Text ->
Either SyntaxError (ModExpBase NoInfo Name)
parseModExp :: FilePath -> Text -> Either SyntaxError (ModExpBase NoInfo Name)
parseModExp = ParserMonad (ModExpBase NoInfo Name)
-> FilePath -> Text -> Either SyntaxError (ModExpBase NoInfo Name)
forall a. ParserMonad a -> FilePath -> Text -> Either SyntaxError a
parse ParserMonad (ModExpBase NoInfo Name)
modExpression
parseType ::
FilePath ->
T.Text ->
Either SyntaxError UncheckedTypeExp
parseType :: FilePath -> Text -> Either SyntaxError UncheckedTypeExp
parseType = ParserMonad UncheckedTypeExp
-> FilePath -> Text -> Either SyntaxError UncheckedTypeExp
forall a. ParserMonad a -> FilePath -> Text -> Either SyntaxError a
parse ParserMonad UncheckedTypeExp
futharkType
parseValue ::
FilePath ->
T.Text ->
Either SyntaxError Value
parseValue :: FilePath -> Text -> Either SyntaxError Value
parseValue = ParserMonad Value -> FilePath -> Text -> Either SyntaxError Value
forall a. ParserMonad a -> FilePath -> Text -> Either SyntaxError a
parse ParserMonad Value
anyValue
parseValues ::
FilePath ->
T.Text ->
Either SyntaxError [Value]
parseValues :: FilePath -> Text -> Either SyntaxError [Value]
parseValues = ParserMonad [Value]
-> FilePath -> Text -> Either SyntaxError [Value]
forall a. ParserMonad a -> FilePath -> Text -> Either SyntaxError a
parse ParserMonad [Value]
anyValues
parseExpIncrM ::
Monad m =>
m T.Text ->
FilePath ->
T.Text ->
m (Either SyntaxError UncheckedExp)
parseExpIncrM :: m Text -> FilePath -> Text -> m (Either SyntaxError UncheckedExp)
parseExpIncrM m Text
fetch FilePath
file Text
program =
m Text
-> ReadLineMonad (Either SyntaxError UncheckedExp)
-> m (Either SyntaxError UncheckedExp)
forall (m :: * -> *) a. Monad m => m Text -> ReadLineMonad a -> m a
getLinesFromM m Text
fetch (ReadLineMonad (Either SyntaxError UncheckedExp)
-> m (Either SyntaxError UncheckedExp))
-> ReadLineMonad (Either SyntaxError UncheckedExp)
-> m (Either SyntaxError UncheckedExp)
forall a b. (a -> b) -> a -> b
$ ParserMonad UncheckedExp
-> FilePath
-> Text
-> ReadLineMonad (Either SyntaxError UncheckedExp)
forall a.
ParserMonad a
-> FilePath -> Text -> ReadLineMonad (Either SyntaxError a)
parseInMonad ParserMonad UncheckedExp
expression FilePath
file Text
program
parseDecOrExpIncrM ::
Monad m =>
m T.Text ->
FilePath ->
T.Text ->
m (Either SyntaxError (Either UncheckedDec UncheckedExp))
parseDecOrExpIncrM :: m Text
-> FilePath
-> Text
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp))
parseDecOrExpIncrM m Text
fetch FilePath
file Text
input =
case ParserMonad UncheckedDec
-> FilePath
-> Text
-> ReadLineMonad (Either SyntaxError UncheckedDec)
forall a.
ParserMonad a
-> FilePath -> Text -> ReadLineMonad (Either SyntaxError a)
parseInMonad ParserMonad UncheckedDec
declaration FilePath
file Text
input of
Value Left {} -> (UncheckedExp -> Either UncheckedDec UncheckedExp)
-> Either SyntaxError UncheckedExp
-> Either SyntaxError (Either UncheckedDec UncheckedExp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap UncheckedExp -> Either UncheckedDec UncheckedExp
forall a b. b -> Either a b
Right (Either SyntaxError UncheckedExp
-> Either SyntaxError (Either UncheckedDec UncheckedExp))
-> m (Either SyntaxError UncheckedExp)
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text -> FilePath -> Text -> m (Either SyntaxError UncheckedExp)
forall (m :: * -> *).
Monad m =>
m Text -> FilePath -> Text -> m (Either SyntaxError UncheckedExp)
parseExpIncrM m Text
fetch FilePath
file Text
input
Value (Right UncheckedDec
d) -> Either SyntaxError (Either UncheckedDec UncheckedExp)
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SyntaxError (Either UncheckedDec UncheckedExp)
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp)))
-> Either SyntaxError (Either UncheckedDec UncheckedExp)
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp))
forall a b. (a -> b) -> a -> b
$ Either UncheckedDec UncheckedExp
-> Either SyntaxError (Either UncheckedDec UncheckedExp)
forall a b. b -> Either a b
Right (Either UncheckedDec UncheckedExp
-> Either SyntaxError (Either UncheckedDec UncheckedExp))
-> Either UncheckedDec UncheckedExp
-> Either SyntaxError (Either UncheckedDec UncheckedExp)
forall a b. (a -> b) -> a -> b
$ UncheckedDec -> Either UncheckedDec UncheckedExp
forall a b. a -> Either a b
Left UncheckedDec
d
GetLine Maybe Text -> ReadLineMonad (Either SyntaxError UncheckedDec)
_ -> do
Text
l <- m Text
fetch
m Text
-> FilePath
-> Text
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp))
forall (m :: * -> *).
Monad m =>
m Text
-> FilePath
-> Text
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp))
parseDecOrExpIncrM m Text
fetch FilePath
file (Text -> m (Either SyntaxError (Either UncheckedDec UncheckedExp)))
-> Text
-> m (Either SyntaxError (Either UncheckedDec UncheckedExp))
forall a b. (a -> b) -> a -> b
$ Text
input Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
l