From 2d56b922007818f07fa2c8ae7f8533c15b4d23c5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 3 Feb 2022 11:34:50 -0500 Subject: [PATCH] Inline edge into resolveWith. --- semantic-analysis/src/Analysis/Syntax.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/semantic-analysis/src/Analysis/Syntax.hs b/semantic-analysis/src/Analysis/Syntax.hs index cfd26bcd3..695f41be3 100644 --- a/semantic-analysis/src/Analysis/Syntax.hs +++ b/semantic-analysis/src/Analysis/Syntax.hs @@ -162,12 +162,12 @@ parseNode o = do "if" -> liftA3 iff <$> findEdgeNamed "condition" <*> findEdgeNamed "consequence" <*> findEdgeNamed "alternative" <|> pure (const noop) "block" -> fmap (foldr (\ (i, v) r -> let_ (nameI i) v (const r)) noop . zip [0..]) . sequenceA <$> traverse resolve edges t -> A.parseFail ("unrecognized type: " <> t) - edge :: (IntMap.Key -> A.Object -> A.Parser a) -> A.Value -> A.Parser a - edge f = A.withObject "edge" (\ edge -> do + resolve = resolveWith (const (pure ())) + resolveWith :: (A.Object -> A.Parser ()) -> A.Value -> A.Parser (IntMap.IntMap rep -> rep) + resolveWith f = A.withObject "edge" (\ edge -> do sink <- edge A..: pack "sink" attrs <- edge A..: pack "attrs" - f sink attrs) - resolve = resolveWith (const (pure ())) - resolveWith f = edge (\ sink attrs -> f attrs >> pure (IntMap.! sink)) + f attrs + pure (IntMap.! sink)) findEdgeNamed name = foldMap (resolveWith (\ attrs -> attrs A..: pack "type" >>= guard . (== name))) edges o A..: pack "attrs" >>= A.withObject "attrs" (fmap (index,) . parseType)