Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mockup-generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dosek-verification
mockup-generator
Commits
3024e6fd
Commit
3024e6fd
authored
8 years ago
by
Hans-Peter Deifel
Browse files
Options
Downloads
Patches
Plain Diff
Add Compare.JSON module
parent
96ea9a75
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
osek-verification.cabal
+1
-0
1 addition, 0 deletions
osek-verification.cabal
src/Compare/JSON.hs
+54
-0
54 additions, 0 deletions
src/Compare/JSON.hs
with
55 additions
and
0 deletions
osek-verification.cabal
+
1
−
0
View file @
3024e6fd
...
@@ -25,6 +25,7 @@ library
...
@@ -25,6 +25,7 @@ library
, Search.Types
, Search.Types
, Search.EpsilonElimination
, Search.EpsilonElimination
, Protocol
, Protocol
, Compare.JSON
, Compare.Types
, Compare.Types
, Compare.Matching
, Compare.Matching
hs-source-dirs: src
hs-source-dirs: src
...
...
This diff is collapsed.
Click to expand it.
src/Compare/JSON.hs
0 → 100644
+
54
−
0
View file @
3024e6fd
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module
Compare.JSON
(
Graph
,
parseFile
)
where
import
Data.Aeson
import
Data.Aeson.Types
(
typeMismatch
)
import
qualified
Data.ByteString.Lazy
as
BS
import
qualified
Data.Graph.Inductive
as
G
import
qualified
Data.Map
as
M
import
Data.Text
(
Text
)
import
Data.Tuple
import
Compare.Types
parseFile
::
BS
.
ByteString
->
Either
String
(
Graph
NodeLabel
EdgeLabel
)
parseFile
=
eitherDecode'
type
NodeLabel
=
Text
type
EdgeLabel
=
Text
newtype
N
=
N
{
unN
::
NodeLabel
}
newtype
E
=
E
{
unE
::
(
NodeLabel
,
NodeLabel
,
EdgeLabel
)
}
instance
FromJSON
(
Graph
NodeLabel
EdgeLabel
)
where
parseJSON
(
Object
v
)
=
mkGraph
<$>
(
map
unN
<$>
v
.:
"nodes"
)
<*>
(
map
unE
<$>
v
.:
"edges"
)
<*>
v
.:
"entry"
parseJSON
invalid
=
typeMismatch
"Graph"
invalid
instance
FromJSON
N
where
parseJSON
(
Object
v
)
=
N
<$>
v
.:
"id"
parseJSON
invalid
=
typeMismatch
"Node"
invalid
instance
FromJSON
E
where
parseJSON
(
Object
v
)
=
E
<$>
((
\
a
b
c
->
(
a
,
b
,
c
))
<$>
v
.:
"from"
<*>
v
.:
"to"
<*>
v
.:
"label"
)
parseJSON
invalid
=
typeMismatch
"Edge"
invalid
mkGraph
::
[
NodeLabel
]
->
[(
NodeLabel
,
NodeLabel
,
EdgeLabel
)]
->
NodeLabel
->
Graph
NodeLabel
EdgeLabel
mkGraph
nodes
labels
entry
=
let
labNodes
=
zip
[
0
..
]
nodes
nodeMap
=
M
.
fromList
$
map
swap
labNodes
labEdges
=
map
(
\
(
from
,
to
,
label
)
->
(
nodeMap
M
.!
from
,
nodeMap
M
.!
to
,
label
))
labels
in
Graph
(
G
.
mkGraph
labNodes
labEdges
)
(
nodeMap
M
.!
entry
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment