@@ -114,19 +114,19 @@ prettyPrintParseException pe = case pe of
114114 ]
115115 CyclicIncludes -> "Cyclic includes"
116116
117−defineAnchor :: Value -> String -> ConduitM e o Parse ()
117+defineAnchor :: Value -> String -> ReaderT JSONPath (ConduitM e o Parse) ()
118118defineAnchor value name = modify (modifyAnchors $ Map.insert name value)
119119 where
120120 modifyAnchors :: (Map String Value -> Map String Value) -> ParseState -> ParseState
121121 modifyAnchors f st = st {parseStateAnchors = f (parseStateAnchors st)}
122122
123−lookupAnchor :: String -> ConduitM e o Parse (Maybe Value)
123+lookupAnchor :: String -> ReaderT JSONPath (ConduitM e o Parse) (Maybe Value)
124124lookupAnchor name = gets (Map.lookup name . parseStateAnchors)
125125
126126data Warning = DuplicateKey JSONPath
127127 deriving (Eq, Show)
128128
129−addWarning :: Warning -> ConduitM e o Parse ()
129+addWarning :: Warning -> ReaderT JSONPath (ConduitM e o Parse) ()
130130addWarning w = modify (modifyWarnings (w :))
131131 where
132132 modifyWarnings :: ([Warning] -> [Warning]) -> ParseState -> ParseState
@@ -137,22 +137,22 @@ data ParseState = ParseState {
137137, parseStateWarnings :: [Warning]
138138}
139139
140−type Parse = ReaderT JSONPath (StateT ParseState (ResourceT IO))
140+type Parse = StateT ParseState (ResourceT IO)
141141
142−requireEvent :: Event -> ConduitM Event o Parse ()
142+requireEvent :: Event -> ReaderT JSONPath (ConduitM Event o Parse) ()
143143requireEvent e = do
144− f <- CL.head
144+ f <- lift CL.head
145145 unless (f == Just e) $ liftIO $ throwIO $ UnexpectedEvent f $ Just e
146146
147−parse :: ConduitM Event o Parse Value
147+parse :: ReaderT JSONPath (ConduitM Event o Parse) Value
148148parse = do
149− streamStart <- CL.head
149+ streamStart <- lift CL.head
150150 case streamStart of
151151 Nothing ->
152152 -- empty string input
153153 return Null
154154 Just EventStreamStart -> do
155− documentStart <- CL.head
155+ documentStart <- lift CL.head
156156 case documentStart of
157157 Just EventStreamEnd ->
158158 -- empty file input, comment only string/file input
@@ -166,7 +166,7 @@ parse = do
166166 _ -> liftIO $ throwIO $ UnexpectedEvent streamStart Nothing
167167
168168parseScalar :: ByteString -> Anchor -> Style -> Tag
169− -> ConduitM Event o Parse Text
169+ -> ReaderT JSONPath (ConduitM Event o Parse) Text
170170parseScalar v a style tag = do
171171 let res = decodeUtf8With lenientDecode v
172172 mapM_ (defineAnchor (textToValue style tag res)) a
@@ -198,9 +198,9 @@ textToScientific = Atto.parseOnly (num <* Atto.endOfInput)
198198 isOctalDigit c = (c >= '0' && c <= '7')
199199 step a c = (a `shiftL` 3) .|. fromIntegral (ord c - 48)
200200
201−parseO :: ConduitM Event o Parse Value
201+parseO :: ReaderT JSONPath (ConduitM Event o Parse) Value
202202parseO = do
203− me <- CL.head
203+ me <- lift CL.head
204204 case me of
205205 Just (EventScalar v tag style a) -> textToValue style tag <$> parseScalar v a style tag
206206 Just (EventSequenceStart _ _ a) -> parseS 0 a id
@@ -215,12 +215,12 @@ parseO = do
215215parseS :: Int
216216 -> Y.Anchor
217217 -> ([Value] -> [Value])
218− -> ConduitM Event o Parse Value
218+ -> ReaderT JSONPath (ConduitM Event o Parse) Value
219219parseS !n a front = do
220− me <- CL.peek
220+ me <- lift CL.peek
221221 case me of
222222 Just EventSequenceEnd -> do
223− CL.drop 1
223+ lift $ CL.drop 1
224224 let res = Array $ V.fromList $ front []
225225 mapM_ (defineAnchor res) a
226226 return res
@@ -231,9 +231,9 @@ parseS !n a front = do
231231parseM :: Set Text
232232 -> Y.Anchor
233233 -> M.HashMap Text Value
234− -> ConduitM Event o Parse Value
234+ -> ReaderT JSONPath (ConduitM Event o Parse) Value
235235parseM mergedKeys a front = do
236− me <- CL.head
236+ me <- lift CL.head
237237 case me of
238238 Just EventMappingEnd -> do
239239 let res = Object front
@@ -276,7 +276,7 @@ decodeHelper src = do
276276 -- This used to be tryAny, but the fact is that catching async
277277 -- exceptions is fine here. We'll rethrow them immediately in the
278278 -- otherwise clause.
279− x <- try $ runResourceT $ runStateT (runReaderT (runConduit $ src .| parse) []) (ParseState Map.empty [])
279+ x <- try $ runResourceT $ runStateT (runConduit $ src .| runReaderT parse []) (ParseState Map.empty [])
280280 case x of
281281 Left e
282282 | Just pe <- fromException e -> return $ Left pe
@@ -288,7 +288,7 @@ decodeHelper_ :: FromJSON a
288288 => ConduitM () Event Parse ()
289289 -> IO (Either ParseException ([Warning], a))
290290decodeHelper_ src = do
291− x <- try $ runResourceT $ runStateT (runReaderT (runConduit $ src .| parse) []) (ParseState Map.empty [])
291+ x <- try $ runResourceT $ runStateT (runConduit $ src .| runReaderT parse []) (ParseState Map.empty [])
292292 return $ case x of
293293 Left e
294294 | Just pe <- fromException e -> Left pe