Skip to content

Commit 046d7dd

Browse files
committed
feat: Reenable asak (using pin-depends for compat patch with OCaml 5)
1 parent 9d757cd commit 046d7dd

File tree

10 files changed

+96
-87
lines changed

10 files changed

+96
-87
lines changed

learn-ocaml.opam

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ depends: [
6565
"uutf" {>= "1.0" }
6666
"vg"
6767
"yojson" {>= "1.4.0" }
68+
"asak" {= "0.5"}
6869
]
6970
build: [
7071
[make "static"]
@@ -86,4 +87,8 @@ pin-depends: [
8687
"ocp-indent-nlfork.1.5.5"
8788
"git+https://[email protected]/OCamlPro/ocp-indent.git#nlfork"
8889
]
90+
[
91+
"asak.0.5"
92+
"git+https://github.com/AltGr/asak#ocaml5"
93+
]
8994
]

learn-ocaml.opam.locked

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bug-reports: "https://github.com/ocaml-sf/learn-ocaml/issues"
1919
dev-repo: "git+https://github.com/ocaml-sf/learn-ocaml"
2020
depends: [
2121
"angstrom" {= "0.15.0"}
22+
"asak" {= "0.5"}
2223
"asn1-combinators" {= "0.2.6"}
2324
"astring" {= "0.8.5"}
2425
"base" {= "v0.16.3"}
@@ -173,6 +174,9 @@ the common files. A demo exercise repository is also provided as example.
173174
run-test: [make "test"]
174175
depexts: ["lsof"] {os-distribution = "alpine"}
175176
pin-depends: [
177+
["asak.0.5" "git+https://github.com/AltGr/asak#ocaml5"]
178+
[
176179
"ocp-indent-nlfork.1.5.5"
177180
"git+https://[email protected]/OCamlPro/ocp-indent.git#nlfork"
178181
]
182+
]

src/server/dune

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
learnocaml_data
1717
learnocaml_api
1818
learnocaml_store
19-
;; learnocaml_partition_create
20-
)
19+
learnocaml_partition_create)
2120
)

src/server/learnocaml_server.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ module Request_handler = struct
496496
status
497497
>>= respond_json cache
498498

499-
(* | Api.Partition (token, eid, fid, prof) ->
500-
* lwt_catch_fail (fun () ->
501-
* verify_teacher_token token
502-
* >?= fun () ->
503-
* Learnocaml_partition_create.partition eid fid prof
504-
* >>= respond_json cache
505-
* )
506-
* (fun exn -> (`Not_found, Printexc.to_string exn)) *)
499+
| Api.Partition (token, eid, fid, prof) ->
500+
lwt_catch_fail (fun () ->
501+
verify_teacher_token token
502+
>?= fun () ->
503+
Learnocaml_partition_create.partition eid fid prof
504+
>>= respond_json cache
505+
)
506+
(fun exn -> (`Not_found, Printexc.to_string exn))
507507

508508
| Api.Invalid_request body ->
509509
lwt_fail (`Bad_request, body)

src/state/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
(name learnocaml_data)
99
(wrapped false)
1010
(modules Learnocaml_data)
11-
(libraries sha
11+
(libraries asak
12+
sha
1213
unix
1314
learnocaml_toplevel_history
1415
learnocaml_report

src/state/learnocaml_api.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ type _ request =
145145
| Set_exercise_status:
146146
teacher token * (Exercise.Status.t * Exercise.Status.t) list -> unit request
147147

148-
(* | Partition:
149-
* teacher token * Exercise.id * string * int -> Partition.t request *)
148+
| Partition:
149+
teacher token * Exercise.id * string * int -> Partition.t request
150150

151151
| Invalid_request:
152152
string -> string request
@@ -177,7 +177,7 @@ let supported_versions
177177
| Exercise_status_index _
178178
| Exercise_status (_, _)
179179
| Set_exercise_status (_, _)
180-
(* | Partition (_, _, _, _) *)
180+
| Partition (_, _, _, _)
181181
| Invalid_request _ -> Compat.(Since (v "0.12"))
182182

183183
let is_supported
@@ -266,8 +266,8 @@ module Conversions (Json: JSON_CODEC) = struct
266266
| Set_exercise_status _ ->
267267
json J.unit
268268

269-
(* | Partition _ ->
270-
* json Partition.enc *)
269+
| Partition _ ->
270+
json Partition.enc
271271

272272
| Invalid_request _ ->
273273
str
@@ -372,9 +372,9 @@ module Conversions (Json: JSON_CODEC) = struct
372372
(J.list (J.tup2 Exercise.Status.enc Exercise.Status.enc))
373373
status)
374374

375-
(* | Partition (token, eid, fid, prof) ->
376-
* get ~token
377-
* ["partition"; eid; fid; string_of_int prof] *)
375+
| Partition (token, eid, fid, prof) ->
376+
get ~token
377+
["partition"; eid; fid; string_of_int prof]
378378

379379
| Invalid_request s ->
380380
failwith ("Error request "^s)
@@ -504,9 +504,9 @@ module Server (Json: JSON_CODEC) (Rh: REQUEST_HANDLER) = struct
504504
| `GET, ["playgrounds"; f], _ when Filename.check_suffix f ".json" ->
505505
Playground (Filename.chop_suffix f ".json") |> k
506506

507-
(* | `GET, ["partition"; eid; fid; prof], Some token
508-
* when Token.is_teacher token ->
509-
* Partition (token, eid, fid, int_of_string prof) |> k *)
507+
| `GET, ["partition"; eid; fid; prof], Some token
508+
when Token.is_teacher token ->
509+
Partition (token, eid, fid, int_of_string prof) |> k
510510

511511
| `GET, ["teacher"; "exercise-status.json"], Some token
512512
when Token.is_teacher token ->

src/state/learnocaml_api.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ type _ request =
137137
(** The two Status.t correspond to the states before and after changes, used
138138
for three-way merge *)
139139

140-
(* | Partition:
141-
* teacher token * Exercise.id * string * int -> Partition.t request *)
140+
| Partition:
141+
teacher token * Exercise.id * string * int -> Partition.t request
142142

143143
| Invalid_request:
144144
string -> string request

src/state/learnocaml_data.ml

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,49 +1403,49 @@ module Tutorial = struct
14031403
end
14041404
end
14051405

1406-
(* module Partition = struct
1407-
* type t =
1408-
* {
1409-
* not_graded : Token.t list;
1410-
* bad_type : Token.t list;
1411-
* partition_by_grade :
1412-
* (int *
1413-
* (((Token.t * string) list) Asak.Wtree.wtree list))
1414-
* list;
1415-
* }
1416-
*
1417-
* let token_list = J.list Token.enc
1418-
*
1419-
* let tree_enc leaf_enc =
1420-
* let open Asak.Wtree in
1421-
* J.mu "tree" @@ fun self ->
1422-
* J.union
1423-
* [ J.case (J.obj1 (J.req "leaf" leaf_enc))
1424-
* (function Leaf x -> Some x | Node _ -> None)
1425-
* (fun x -> Leaf x) ;
1426-
* J.case (J.obj3 (J.req "coef" J.int) (J.req "left" self) (J.req "right" self))
1427-
* (function Node (t,l,r) -> Some (t,l,r) | Leaf _ -> None)
1428-
* (fun (t,l,r) -> Node (t,l,r)) ]
1429-
*
1430-
* let leaf_enc =
1431-
* J.list (J.tup2 Token.enc J.string)
1432-
*
1433-
* let innerlist = J.list (tree_enc leaf_enc)
1434-
*
1435-
* let int_assoc =
1436-
* J.tup2 J.int innerlist
1437-
*
1438-
* let enc =
1439-
* J.conv
1440-
* (fun t ->
1441-
* (t.not_graded, t.bad_type, t.partition_by_grade))
1442-
* (fun (not_graded, bad_type, partition_by_grade) ->
1443-
* {not_graded; bad_type; partition_by_grade}) @@
1444-
* J.obj3
1445-
* J.(req "not_graded" token_list)
1446-
* J.(req "bad_type" token_list)
1447-
* J.(req "patition_by_grade" (J.list int_assoc))
1448-
* end *)
1406+
module Partition = struct
1407+
type t =
1408+
{
1409+
not_graded : Token.t list;
1410+
bad_type : Token.t list;
1411+
partition_by_grade :
1412+
(int *
1413+
(((Token.t * string) list) Asak.Wtree.wtree list))
1414+
list;
1415+
}
1416+
1417+
let token_list = J.list Token.enc
1418+
1419+
let tree_enc leaf_enc =
1420+
let open Asak.Wtree in
1421+
J.mu "tree" @@ fun self ->
1422+
J.union
1423+
[ J.case (J.obj1 (J.req "leaf" leaf_enc))
1424+
(function Leaf x -> Some x | Node _ -> None)
1425+
(fun x -> Leaf x) ;
1426+
J.case (J.obj3 (J.req "coef" J.int) (J.req "left" self) (J.req "right" self))
1427+
(function Node (t,l,r) -> Some (t,l,r) | Leaf _ -> None)
1428+
(fun (t,l,r) -> Node (t,l,r)) ]
1429+
1430+
let leaf_enc =
1431+
J.list (J.tup2 Token.enc J.string)
1432+
1433+
let innerlist = J.list (tree_enc leaf_enc)
1434+
1435+
let int_assoc =
1436+
J.tup2 J.int innerlist
1437+
1438+
let enc =
1439+
J.conv
1440+
(fun t ->
1441+
(t.not_graded, t.bad_type, t.partition_by_grade))
1442+
(fun (not_graded, bad_type, partition_by_grade) ->
1443+
{not_graded; bad_type; partition_by_grade}) @@
1444+
J.obj3
1445+
J.(req "not_graded" token_list)
1446+
J.(req "bad_type" token_list)
1447+
J.(req "patition_by_grade" (J.list int_assoc))
1448+
end
14491449

14501450
module Playground = struct
14511451
type id = string

src/state/learnocaml_data.mli

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -453,19 +453,19 @@ module Tutorial: sig
453453

454454
end
455455

456-
(* module Partition : sig
457-
* type t =
458-
* {
459-
* not_graded : Token.t list;
460-
* bad_type : Token.t list;
461-
* partition_by_grade :
462-
* (int *
463-
* (((Token.t * string) list) Asak.Wtree.wtree list))
464-
* list;
465-
* }
466-
*
467-
* val enc: t Json_encoding.encoding
468-
* end *)
456+
module Partition : sig
457+
type t =
458+
{
459+
not_graded : Token.t list;
460+
bad_type : Token.t list;
461+
partition_by_grade :
462+
(int *
463+
(((Token.t * string) list) Asak.Wtree.wtree list))
464+
list;
465+
}
466+
467+
val enc: t Json_encoding.encoding
468+
end
469469

470470
module Playground : sig
471471
type id = string

src/utils/dune

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
(modules sha)
4242
)
4343

44-
;; (library
45-
;; (name learnocaml_partition_create)
46-
;; (wrapped false)
47-
;; (flags :standard -warn-error A-4-42-44-45-48)
48-
;; (libraries lwt learnocaml_store learnocaml_data)
49-
;; (modules learnocaml_partition_create)
50-
;; )
44+
(library
45+
(name learnocaml_partition_create)
46+
(wrapped false)
47+
(flags :standard -warn-error A-4-42-44-45-48)
48+
(libraries asak lwt learnocaml_store learnocaml_data)
49+
(modules learnocaml_partition_create)
50+
)

0 commit comments

Comments
 (0)