From 1ed8183066d1fb33da601cb24e6f0fba1eae2a0d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 7 Feb 2022 11:01:14 -0500 Subject: [PATCH] Factor out lists of child nodes. --- semantic-analysis/src/Analysis/Syntax.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/semantic-analysis/src/Analysis/Syntax.hs b/semantic-analysis/src/Analysis/Syntax.hs index 8eed38641..e4ca3ad55 100644 --- a/semantic-analysis/src/Analysis/Syntax.hs +++ b/semantic-analysis/src/Analysis/Syntax.hs @@ -162,9 +162,10 @@ parseNode o = do "false" -> pure (const (bool False)) "throw" -> fmap throw <$> resolve (head edges) "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 - "module" -> fmap (foldr (\ (i, v) r -> let_ (nameI i) v (const r)) noop . zip [0..]) . sequenceA <$> traverse resolve edges + "block" -> children + "module" -> children t -> A.parseFail ("unrecognized type: " <> t) + children = fmap (foldr (\ (i, v) r -> let_ (nameI i) v (const r)) noop . zip [0..]) . sequenceA <$> traverse resolve edges resolve = resolveWith (const (pure ())) resolveWith :: (A.Object -> A.Parser ()) -> A.Value -> A.Parser (IntMap.IntMap rep -> rep) resolveWith f = A.withObject "edge" (\ edge -> do