Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/grader/dune
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
%{ocaml-config:standard_library}/compiler-libs/ast_mapper.cmi
%{ocaml-config:standard_library}/compiler-libs/parsetree.cmi
%{ocaml-config:standard_library}/compiler-libs/location.cmi
%{ocaml-config:standard_library}/compiler-libs/parse.cmi)
%{ocaml-config:standard_library}/compiler-libs/parse.cmi
%{ocaml-config:standard_library}/compiler-libs/pprintast.cmi)
(:generated-cmis
../ppx-metaquot/.ty.objs/byte/ty.cmi
../ppx-metaquot/.fun_ty.objs/byte/fun_ty.cmi
Expand Down
20 changes: 20 additions & 0 deletions src/ppx-metaquot/ppx_metaquot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ module Main : sig val expander: string list -> Ast_mapper.mapper end = struct
fun_ty_next
(Typ.constr fun_ty_id [glob_cty_ty; ucty; ret])
| _ -> invalid_arg "fun_ty_of: not an arrow type"

let printable_of this e =
(* [%printable e] is a shortcut for
[Test_lib.printable_fun e (Pprintast.string_of_expression [%expr e])] *)
app (evar "Test_lib.printable_fun")
[app (evar "Pprintast.string_of_expression")
[(exp_lifter !loc this) # lift_Parsetree_expression e]; e]

let code_of this e =
(* [%code e] is a shortcut for [(Code.(e), Solution.(e), [%expr e])] *)
let open_module name e =
Exp.open_ (Opn.mk (Mod.ident (lid name))) e
in
tuple [open_module "Code" e;
open_module "Solution" e;
(exp_lifter !loc this) # lift_Parsetree_expression e]
(* ------ </edited for learn-ocaml> ------ *)

let expander _args =
Expand Down Expand Up @@ -303,6 +319,10 @@ module Main : sig val expander: string list -> Ast_mapper.mapper end = struct
ty_of this ty
| Pexp_extension({txt="funty";loc=l}, e) ->
fun_ty_of this l e
| Pexp_extension({txt="printable";loc=l}, e) ->
printable_of this (get_exp l e)
| Pexp_extension({txt="code";loc=l}, e) ->
code_of this (get_exp l e)
(* ------ </edited for learn-ocaml> ------ *)
| _ ->
super.expr this e
Expand Down