1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00

Port Control.Effect.Parse forward.

This commit is contained in:
Rob Rix 2019-10-07 09:07:02 -04:00
parent 3c3ff4aefc
commit 13a6989a01
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -5,9 +5,11 @@ module Control.Effect.Parse
, parse , parse
, parseWith , parseWith
, parsePairWith , parsePairWith
-- * Re-exports
, Has
) where ) where
import Control.Effect.Carrier import Control.Carrier
import Control.Effect.Error import Control.Effect.Error
import Control.Exception (SomeException) import Control.Exception (SomeException)
import Data.Bifunctor.Join import Data.Bifunctor.Join
@ -30,7 +32,7 @@ instance Effect Parse where
-- | Parse a 'Blob' with the given 'Parser'. -- | Parse a 'Blob' with the given 'Parser'.
parse :: (Member Parse sig, Carrier sig m) parse :: Has Parse sig m
=> Parser term => Parser term
-> Blob -> Blob
-> m term -> m term
@ -39,7 +41,7 @@ parse parser blob = send (Parse parser blob pure)
-- | Parse a 'Blob' with one of the provided parsers, and run an action on the abstracted term. -- | Parse a 'Blob' with one of the provided parsers, and run an action on the abstracted term.
parseWith parseWith
:: (Carrier sig m, Member (Error SomeException) sig, Member Parse sig) :: (Has (Error SomeException) sig m, Has Parse sig m)
=> Map.Map Language (SomeParser c ann) -- ^ The set of parsers to select from. => Map.Map Language (SomeParser c ann) -- ^ The set of parsers to select from.
-> (forall term . c term => term ann -> m a) -- ^ A function to run on the parsed term. Note that the term is abstract, but constrained by @c@, allowing you to do anything @c@ allows, and requiring that all the input parsers produce terms supporting @c@. -> (forall term . c term => term ann -> m a) -- ^ A function to run on the parsed term. Note that the term is abstract, but constrained by @c@, allowing you to do anything @c@ allows, and requiring that all the input parsers produce terms supporting @c@.
-> Blob -- ^ The blob to parse. -> Blob -- ^ The blob to parse.
@ -50,7 +52,7 @@ parseWith parsers with blob = case Map.lookup (blobLanguage blob) parsers of
-- | Parse a 'BlobPair' with one of the provided parsers, and run an action on the abstracted term pair. -- | Parse a 'BlobPair' with one of the provided parsers, and run an action on the abstracted term pair.
parsePairWith parsePairWith
:: (Carrier sig m, Member (Error SomeException) sig, Member Parse sig) :: (Has (Error SomeException) sig m, Has Parse sig m)
=> Map.Map Language (SomeParser c ann) -- ^ The set of parsers to select from. => Map.Map Language (SomeParser c ann) -- ^ The set of parsers to select from.
-> (forall term . c term => These (term ann) (term ann) -> m a) -- ^ A function to run on the parsed terms. Note that the terms are abstract, but constrained by @c@, allowing you to do anything @c@ allows, and requiring that all the input parsers produce terms supporting @c@. -> (forall term . c term => These (term ann) (term ann) -> m a) -- ^ A function to run on the parsed terms. Note that the terms are abstract, but constrained by @c@, allowing you to do anything @c@ allows, and requiring that all the input parsers produce terms supporting @c@.
-> BlobPair -- ^ The blob pair to parse. -> BlobPair -- ^ The blob pair to parse.