You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--| Parse a @Value@ into an entire graph of terms, as well as a root node, if any exists.
120
+
parseGraph::A.Value->A.Parser (Graph, MaybeTerm)
106
121
parseGraph =A.withArray "nodes"$\ nodes ->do
107
-
(untied, First root) <-foldMap (\ (k, v, r) -> ([(k, v)], First r)) <$>traverse(A.withObject "node"parseNode) (V.toList nodes)
108
-
-- @untied@ is a list of key/value pairs, where the keys are graph node IDs and the values are functions from the final graph to the representations of said graph nodes. Likewise, @root@ is a function of the same variety, wrapped in a @Maybe@.
122
+
(untied, First root) <-fold <$>traverse parseNode (V.toList nodes)
123
+
-- @untied@ is an intmap, where the keys are graph node IDs and the values are functions from the final graph to the representations of said graph nodes. Likewise, @root@ is a function of the same variety, wrapped in a @Maybe@.
109
124
--
110
-
-- We define @tied@ as the fixpoint of the former to yield the former as a graph of type @IntMap.IntMap Term@, and apply the latter to said graph to yield the entry point, if any, from which to evaluate.
-- We define @tied@ as the fixpoint of the former to yield the former as a graph of type @Graph@, and apply the latter to said graph to yield the entry point, if any, from which to evaluate.
--| Parse a node from a JSON @Value@ into a pair of a partial graph of unfixed terms and optionally an unfixed term representing the root node.
130
+
--
131
+
-- The partial graph is represented as an adjacency map relating node IDs to unfixed terms—terms which may make reference to a completed graph to find edges, and which therefore can't be inspected until the full graph is known.
132
+
parseNode::A.Value->A.Parser (IntMap.IntMap (Graph->Term), First (Graph->Term))
133
+
parseNode =A.withObject "node"$\ o ->do
116
134
edges <- o A..: fromString "edges"
117
135
index <- o A..: fromString "id"
118
136
o A..: fromString "attrs">>=A.withObject "attrs" (\ attrs ->do
119
137
ty <- attrs A..: fromString "type"
120
-
node <-parseType attrs edges ty
121
-
pure (index, node, node <$ guard (ty =="module")))
138
+
node <-parseTerm attrs edges ty
139
+
pure (IntMap.singleton index node, node <$First (guard (ty =="module"))))
0 commit comments