    {-# OPTIONS_GHC -fno-warn-orphans #-}

    module Futhark.IR.SyntaxTests (parseString) where

    import Data.String
    import Data.Text qualified as T
    import Futhark.IR.Parse
    import Futhark.IR.Syntax

    -- There isn't anything to test in this module, but we define some
    -- convenience instances.

    parseString :: String -> (FilePath -> T.Text -> Either T.Text a) -> String -> a
    parseString :: forall a.
    String -> (String -> Text -> Either Text a) -> String -> a
    parseString String
    desc String -> Text -> Either Text a
    p =
      (Text -> a) -> (a -> a) -> Either Text a -> a
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
    either (String -> a
    forall a. HasCallStack => String -> a
    error (String -> a) -> (Text -> String) -> Text -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> String
    T.unpack) a -> a
    forall a. a -> a
    id (Either Text a -> a) -> (String -> Either Text a) -> String -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Text -> Either Text a
    p (String
    "IsString " String -> String -> String
    forall a. Semigroup a => a -> a -> a
    <> String
    desc) (Text -> Either Text a)
    -> (String -> Text) -> String -> Either Text a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Text
    T.pack

    instance IsString Type where
      fromString :: String -> Type
    fromString = String -> (String -> Text -> Either Text Type) -> String -> Type
    forall a.
    String -> (String -> Text -> Either Text a) -> String -> a
    parseString String
    "Type" String -> Text -> Either Text Type
    parseType

    instance IsString DeclExtType where
      fromString :: String -> DeclExtType
    fromString = String
    -> (String -> Text -> Either Text DeclExtType)
    -> String
    -> DeclExtType
    forall a.
    String -> (String -> Text -> Either Text a) -> String -> a
    parseString String
    "DeclExtType" String -> Text -> Either Text DeclExtType
    parseDeclExtType

    instance IsString DeclType where
      fromString :: String -> DeclType
    fromString = String
    -> (String -> Text -> Either Text DeclType) -> String -> DeclType
    forall a.
    String -> (String -> Text -> Either Text a) -> String -> a
    parseString String
    "DeclType" String -> Text -> Either Text DeclType
    parseDeclType

    instance IsString VName where
      fromString :: String -> VName
    fromString = String -> (String -> Text -> Either Text VName) -> String -> VName
    forall a.
    String -> (String -> Text -> Either Text a) -> String -> a
    parseString String
    "VName" String -> Text -> Either Text VName
    parseVName

    instance IsString SubExp where
      fromString :: String -> SubExp
    fromString = String
    -> (String -> Text -> Either Text SubExp) -> String -> SubExp
    forall a.
    String -> (String -> Text -> Either Text a) -> String -> a
    parseString String
    "SubExp" String -> Text -> Either Text SubExp
    parseSubExp

    instance IsString SubExpRes where
      fromString :: String -> SubExpRes
    fromString = String
    -> (String -> Text -> Either Text SubExpRes) -> String -> SubExpRes
    forall a.
    String -> (String -> Text -> Either Text a) -> String -> a
    parseString String
    "SubExpRes" String -> Text -> Either Text SubExpRes
    parseSubExpRes