-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJson.tla
36 lines (29 loc) · 1.51 KB
/
Json.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-------------------------------- MODULE Json --------------------------------
LOCAL INSTANCE Sequences
LOCAL INSTANCE TLC
(*************************************************************************)
(* Imports the definitions from the modules, but doesn't export them. *)
(*************************************************************************)
-----------------------------------------------------------------------------
LOCAL ToJsonKeyValue(F, d) ==
ToString(ToString(d)) \o ":" \o ToString(F[d])
RECURSIVE ToJson(_,_)
LOCAL ToJson(F, D) == \* LOCAL just a hint for humans.
LET d == CHOOSE d \in D: TRUE
IN IF D = DOMAIN F
THEN "{" \o ToJsonKeyValue(F, d) \o IF D \ {d} = {}
THEN "}"
ELSE ToJson(F, D \ {d})
ELSE ", " \o ToJsonKeyValue(F, d) \o IF D \ {d} = {}
THEN "}"
ELSE ToJson(F, D \ {d})
ToJsonObject(F) ==
(*************************************************************************)
(* This equals a string that is the Json representation of the given *)
(* function F s.t. DOMAIN F \subseteq Nat and Range(F) \subseteq STRING *)
(* with Range(g) == { g[x] : x \in DOMAIN g }. *)
(*************************************************************************)
IF DOMAIN F = {}
THEN "{}"
ELSE ToJson(F, DOMAIN F)
=============================================================================