Skip to content

Commit 17a8ef8

Browse files
committed
finish up comand line for petrinets
1 parent e092559 commit 17a8ef8

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Main.idr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ checkFSM fileContent = do
6464
checkPetri : String -> FSMCheck ()
6565
checkPetri fileContent = do
6666
content <- maybe (Left JSONError) Right (parse fileContent)
67-
petri <- either (const $ Left InvalidFSM) Right (Typedefs.TermParse.deserialiseJSON TPetriExec
67+
petri' <- either (const $ Left InvalidFSM) Right (Typedefs.TermParse.deserialiseJSON TPetriExec
6868
[ (Nat ** expectNat)
6969
, (List (List Nat, List Nat) ** expectListListEdges)
7070
, (List Nat ** expectListNat)
7171
]
7272
content)
73-
let True = isJust $ composeWithId (Spec petri) (Path petri) (State Petri)
73+
petri <- maybe (Left InvalidFSM) Right (convertExec $ petri')
74+
let True = isJust $ composeWithId (Spec petri) (Path petri) (State petri)
7475
| Left InvalidFSM
7576
pure ()
7677

src/PetriFormat.idr

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ import Typedefs.Names
66
import Data.Vect
77
import PetriGraph
88

9+
public export
910
TNat : TDefR 2
1011
TNat = RRef 0
1112

13+
public export
1214
TEdges : TDefR 2
1315
TEdges = RRef 1
1416

17+
public export
1518
TState : TDefR 3
1619
TState = RRef 2
1720

21+
public export
1822
TPetriSpec : TDefR 2
1923
TPetriSpec = TProd [TNat, TEdges]
2024

25+
public export
2126
convertSpec : Ty [Nat, List (List Nat, List Nat)] TPetriSpec -> Maybe (n ** PetriSpec n)
2227
convertSpec (places, edges) =
2328
MkDPair (length edges) . MkPetriSpec places <$> convertList places (fromList edges)
@@ -27,6 +32,7 @@ convertSpec (places, edges) =
2732
convertList p = traverse (\(a, b) => [| MkPair (traverse (\v => natToFin v p) a)
2833
(traverse (\v => natToFin v p) b) |])
2934

35+
public export
3036
TTree : TDefR 1
3137
TTree = TMu
3238
[ ("Tensor", TProd [TVar 0, TVar 0])
@@ -36,13 +42,25 @@ TTree = TMu
3642
, ("Mor", TVar 1)
3743
]
3844

45+
-- converts from TDef to Tree
3946
convertTree : Ty [Nat] TTree -> (Tree Nat Nat)
4047
convertTree (Inn (Left (a, b))) = Tensor (convertTree a) (convertTree b)
4148
convertTree (Inn (Right (Left (a, b)))) = Sequence (convertTree a) (convertTree b)
4249
convertTree (Inn (Right (Right (Left (a, b))))) = Sym a b
4350
convertTree (Inn (Right (Right (Right (Left i))))) = Id i
4451
convertTree (Inn (Right (Right (Right (Right m))))) = Mor m
4552

53+
54+
-- converts from Tree to TDef
55+
export
56+
convertTree' : Tree Nat Nat -> Ty [Nat] TTree
57+
convertTree' (Tensor a b) = (Inn (Left (convertTree' a, convertTree' b)))
58+
convertTree' (Sequence a b) = (Inn (Right (Left (convertTree' a, convertTree' b))))
59+
convertTree' (Sym a b) = (Inn (Right (Right (Left (a, b)))))
60+
convertTree' (Id x) = (Inn (Right (Right (Right (Left x)))))
61+
convertTree' (Mor x) = (Inn (Right (Right (Right (Right x)))))
62+
63+
public export
4664
convertState : (spec : PetriSpec k) -> List Nat -> Maybe (PetriState spec)
4765
convertState spec = traverse (\s => natToFin s (Places spec))
4866

@@ -51,8 +69,9 @@ TPetriExec : TDefR 3
5169
TPetriExec = TProd [TProd [RRef 0 , RRef 1], RRef 2, weakenTDef TTree 3 (LTESucc LTEZero)]
5270

5371
dropContext : Ty [Nat, a, b] (weakenTDef TTree 3 (LTESucc LTEZero)) -> Ty [Nat] TTree
72+
dropContext tdef = really_believe_me tdef
5473

55-
export
74+
public export
5675
convertExec : Ty [Nat, List (List Nat, List Nat), List Nat] TPetriExec -> Maybe PetriExec
5776
convertExec ((a, b), c, d) = do (k ** spec) <- convertSpec (a , b)
5877
path <- checkTree spec (convertTree $ dropContext d)

0 commit comments

Comments
 (0)