1
1
mirror of https://github.com/github/semantic.git synced 2024-11-27 12:57:49 +03:00

Factor out lists of child nodes.

This commit is contained in:
Rob Rix 2022-02-07 11:01:14 -05:00
parent 82e00e4af0
commit 1ed8183066
No known key found for this signature in database
GPG Key ID: 2BE643E01DC032AE

View File

@ -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