1
1
mirror of https://github.com/github/semantic.git synced 2024-11-23 16:37:50 +03:00

Parse graphs.

This commit is contained in:
Rob Rix 2021-12-17 15:21:31 -05:00
parent ecb25608f8
commit be0c656e9f
No known key found for this signature in database
GPG Key ID: 2BE643E01DC032AE

View File

@ -9,6 +9,7 @@ module Analysis.Syntax
-- * Pretty-printing
, Print(..)
-- * Parsing
, parseGraph
, parseNode
) where
@ -18,6 +19,7 @@ import qualified Data.Aeson as A
import qualified Data.Aeson.Types as A
import qualified Data.IntMap as IntMap
import Data.Text (Text, pack, unpack)
import qualified Data.Vector as V
class Syntax rep where
iff :: rep -> rep -> rep -> rep
@ -71,6 +73,11 @@ infixr 6 <+>
-- Parsing
parseGraph :: Syntax rep => A.Value -> A.Parser (IntMap.IntMap rep)
parseGraph = A.withArray "nodes" $ \ nodes -> do
untied <- IntMap.fromList <$> traverse (A.withObject "node" parseNode) (V.toList nodes)
pure (let tied = ($ tied) <$> untied in tied)
parseNode :: Syntax rep => A.Object -> A.Parser (IntMap.Key, IntMap.IntMap rep -> rep)
parseNode o = do
edges <- o A..: pack "edges"