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

Factor out resolution of edges.

This commit is contained in:
Rob Rix 2022-02-01 13:47:34 -05:00
parent caf3c3f1cd
commit 374c8f990d
No known key found for this signature in database
GPG Key ID: 2BE643E01DC032AE

View File

@ -135,7 +135,7 @@ parseNode o = do
"string" -> const . string <$> attrs A..: pack "text"
"true" -> pure (const (bool True))
"false" -> pure (const (bool False))
"throw" -> fmap throw <$> edge (const . pure . flip (IntMap.!)) (head edges)
"throw" -> fmap throw <$> resolve (head edges)
"if" -> liftA3 iff <$> findEdge (edgeNamed "condition") <*> findEdge (edgeNamed "consequence") <*> findEdge (edgeNamed "alternative") <|> pure (const noop)
"block" -> pure (const (bool True))
t -> A.parseFail ("unrecognized type: " <> t)
@ -144,6 +144,7 @@ parseNode o = do
sink <- edge A..: pack "sink"
attrs <- edge A..: pack "attrs"
f sink attrs)
resolve = edge (const . pure . flip (IntMap.!))
edgeNamed name sink attrs = attrs A..: pack "type" >>= guard . (== name) >> pure (IntMap.! sink)
findEdge f = foldMap (edge f) edges
o A..: pack "attrs" >>= A.withObject "attrs" (fmap (index,) . parseType)