From c42ebf27e366c7adcc9e03eab4129de29576a273 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 23 Oct 2019 12:11:50 -0400 Subject: [PATCH] Define a helper to select a parser for the given language. --- src/Control/Effect/Parse.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Control/Effect/Parse.hs b/src/Control/Effect/Parse.hs index c391143ec..0c2bb002d 100644 --- a/src/Control/Effect/Parse.hs +++ b/src/Control/Effect/Parse.hs @@ -3,6 +3,7 @@ module Control.Effect.Parse ( -- * Parse effect Parse(..) , parse +, parserForLanguage , parseWith , parsePairWith ) where @@ -37,6 +38,11 @@ parse :: (Member Parse sig, Carrier sig m) parse parser blob = send (Parse parser blob pure) +-- | Select a parser for the given language. +parserForLanguage :: Map.Map Language (SomeParser c ann) -> Language -> Maybe (SomeParser c ann) +parserForLanguage = flip Map.lookup + + -- | Parse a 'Blob' with one of the provided parsers, and run an action on the abstracted term. parseWith :: (Carrier sig m, Member (Error SomeException) sig, Member Parse sig)