module Data.Binding.Hobbits.PatternParser (parsePattern) where
import Language.Haskell.TH
import qualified Language.Haskell.Exts.Parser as Meta
import qualified Language.Haskell.Meta.Parse as Meta
import qualified Language.Haskell.Meta.Parse as Sloppy
import qualified Language.Haskell.Meta.Syntax.Translate as Translate
import qualified Language.Haskell.Exts.Extension as Exts
parsePatternExtensions :: [Extension]
parsePatternExtensions =
(KnownExtension -> Extension) -> [KnownExtension] -> [Extension]
forall a b. (a -> b) -> [a] -> [b]
map KnownExtension -> Extension
Exts.EnableExtension ([KnownExtension] -> [Extension])
-> [KnownExtension] -> [Extension]
forall a b. (a -> b) -> a -> b
$ KnownExtension
Exts.ViewPatterns KnownExtension -> [KnownExtension] -> [KnownExtension]
forall a. a -> [a] -> [a]
: [KnownExtension]
Sloppy.myDefaultExtensions
parsePattern :: String -> String -> Either String Pat
parsePattern :: String -> String -> Either String Pat
parsePattern String
fn =
(Pat SrcSpanInfo -> Pat)
-> Either String (Pat SrcSpanInfo) -> Either String Pat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pat SrcSpanInfo -> Pat
forall a. ToPat a => a -> Pat
Translate.toPat (Either String (Pat SrcSpanInfo) -> Either String Pat)
-> (String -> Either String (Pat SrcSpanInfo))
-> String
-> Either String Pat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseResult (Pat SrcSpanInfo) -> Either String (Pat SrcSpanInfo)
forall a. ParseResult a -> Either String a
Meta.parseResultToEither (ParseResult (Pat SrcSpanInfo) -> Either String (Pat SrcSpanInfo))
-> (String -> ParseResult (Pat SrcSpanInfo))
-> String
-> Either String (Pat SrcSpanInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ParseMode -> String -> ParseResult (Pat SrcSpanInfo)
Meta.parsePatWithMode (ParseMode
Sloppy.myDefaultParseMode
{parseFilename :: String
Meta.parseFilename = String
fn,
extensions :: [Extension]
Meta.extensions = [Extension]
parsePatternExtensions })