module Language.Futhark.Parser
( parseFuthark,
parseFutharkWithComments,
parseExp,
parseExpAt,
parseModExp,
parseType,
parseDecOrExp,
SyntaxError (..),
Comment (..),
)
where
import Data.Text qualified as T
import Futhark.Util.Loc (Pos (..))
import Language.Futhark.Parser.Parser
import Language.Futhark.Prop
import Language.Futhark.Syntax
initialPos :: FilePath -> Pos
initialPos :: FilePath -> Pos
initialPos FilePath
fname = FilePath -> Int -> Int -> Int -> Pos
Pos FilePath
fname Int
1 Int
1 Int
0
parseFuthark ::
FilePath ->
T.Text ->
Either SyntaxError UncheckedProg
parseFuthark :: FilePath -> Text -> Either SyntaxError UncheckedProg
parseFuthark FilePath
fname = ParserMonad UncheckedProg
-> Pos -> Text -> Either SyntaxError UncheckedProg
forall a. ParserMonad a -> Pos -> Text -> Either SyntaxError a
parse ParserMonad UncheckedProg
prog (FilePath -> Pos
initialPos FilePath
fname)
parseFutharkWithComments ::
FilePath ->
T.Text ->
Either SyntaxError (UncheckedProg, [Comment])
FilePath
fname = ParserMonad UncheckedProg
-> Pos -> Text -> Either SyntaxError (UncheckedProg, [Comment])
forall a.
ParserMonad a -> Pos -> Text -> Either SyntaxError (a, [Comment])
parseWithComments ParserMonad UncheckedProg
prog (FilePath -> Pos
initialPos FilePath
fname)
parseExp ::
FilePath ->
T.Text ->
Either SyntaxError UncheckedExp
parseExp :: FilePath -> Text -> Either SyntaxError UncheckedExp
parseExp FilePath
fname = ParserMonad UncheckedExp
-> Pos -> Text -> Either SyntaxError UncheckedExp
forall a. ParserMonad a -> Pos -> Text -> Either SyntaxError a
parse ParserMonad UncheckedExp
expression (FilePath -> Pos
initialPos FilePath
fname)
parseExpAt ::
Pos ->
T.Text ->
Either SyntaxError UncheckedExp
parseExpAt :: Pos -> Text -> Either SyntaxError UncheckedExp
parseExpAt = ParserMonad UncheckedExp
-> Pos -> Text -> Either SyntaxError UncheckedExp
forall a. ParserMonad a -> Pos -> 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 FilePath
fname = ParserMonad (ModExpBase NoInfo Name)
-> Pos -> Text -> Either SyntaxError (ModExpBase NoInfo Name)
forall a. ParserMonad a -> Pos -> Text -> Either SyntaxError a
parse ParserMonad (ModExpBase NoInfo Name)
modExpression (FilePath -> Pos
initialPos FilePath
fname)
parseType ::
FilePath ->
T.Text ->
Either SyntaxError UncheckedTypeExp
parseType :: FilePath -> Text -> Either SyntaxError UncheckedTypeExp
parseType FilePath
fname = ParserMonad UncheckedTypeExp
-> Pos -> Text -> Either SyntaxError UncheckedTypeExp
forall a. ParserMonad a -> Pos -> Text -> Either SyntaxError a
parse ParserMonad UncheckedTypeExp
futharkType (FilePath -> Pos
initialPos FilePath
fname)
parseDecOrExp ::
FilePath ->
T.Text ->
Either SyntaxError (Either UncheckedDec UncheckedExp)
parseDecOrExp :: FilePath
-> Text -> Either SyntaxError (Either UncheckedDec UncheckedExp)
parseDecOrExp FilePath
fname Text
input =
case ParserMonad UncheckedDec
-> Pos -> Text -> Either SyntaxError UncheckedDec
forall a. ParserMonad a -> Pos -> Text -> Either SyntaxError a
parse ParserMonad UncheckedDec
declaration (FilePath -> Pos
initialPos FilePath
fname) Text
input of
Left {} -> UncheckedExp -> Either UncheckedDec UncheckedExp
forall a b. b -> Either a b
Right (UncheckedExp -> Either UncheckedDec UncheckedExp)
-> Either SyntaxError UncheckedExp
-> Either SyntaxError (Either UncheckedDec UncheckedExp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> Text -> Either SyntaxError UncheckedExp
parseExp FilePath
fname Text
input
Right UncheckedDec
d -> 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