Skip to content
Snippets Groups Projects
Commit f949c5cd authored by Paul IANNETTA's avatar Paul IANNETTA Committed by Thomas Wood
Browse files

last changes

parent 70197c81
No related branches found
No related tags found
No related merge requests found
...@@ -3,13 +3,21 @@ open Parsetree ...@@ -3,13 +3,21 @@ open Parsetree
open Typedtree open Typedtree
open Mytools open Mytools
let rec extract_cstr_attrs (cstr : Typedtree.constructor_declaration) : string * string list = let rec extract_cstr_attrs (cstr : Typedtree.constructor_declaration) =
let cstr_name = Ident.name cstr.cd_id in let cstr_name = Ident.name cstr.cd_id in
let cstr_params = cstr.cd_attributes let cstr_params = extract_attrs cstr.cd_attributes
|> List.map (fun (_, pl) -> extract_payload pl)
|> List.flatten
in (cstr_name, cstr_params) in (cstr_name, cstr_params)
and extract_vb_attrs (vb : Typedtree.value_binding) =
extract_attrs vb.vb_attributes
and extract_attrs attrs =
attrs
|> List.map extract_attr
|> List.flatten
and extract_attr (_, pl) = extract_payload pl
and extract_payload = function and extract_payload = function
| PStr s -> extract_structure s | PStr s -> extract_structure s
| PTyp _ -> error "Type found. A tuple or a single value was expected" | PTyp _ -> error "Type found. A tuple or a single value was expected"
......
...@@ -110,11 +110,38 @@ let ppf_single_cstrs typ = ...@@ -110,11 +110,38 @@ let ppf_single_cstrs typ =
let ppf_multiple_cstrs typ rest = let ppf_multiple_cstrs typ rest =
Format.sprintf "{type: \"%s\", %s}" Format.sprintf "{type: \"%s\", %s}"
typ rest typ rest
(**
* Log Part
*)
module Log :
sig
val status : unit -> bool
val init_log : unit -> unit
val toggle : string -> unit
end
=
struct
let s = ref false
let status () = !s
let init_log () = s := false
let toggle update = match update with
| "logged" -> s := true;
| "unlogged" -> s := false;
| _ -> ();
end
(** (**
* Main part * Main part
*) *)
(*let to_javascript typedtree =
js_of_structure typedtree
(** + Log related post processing **)
*)
let rec show_value_binding vb = let rec show_value_binding vb =
js_of_let_pattern vb.vb_pat vb.vb_expr js_of_let_pattern vb.vb_pat vb.vb_expr
...@@ -145,7 +172,12 @@ and js_of_structure_item s = match s.str_desc with ...@@ -145,7 +172,12 @@ and js_of_structure_item s = match s.str_desc with
| Tstr_class _ -> out_of_scope "objects" | Tstr_class _ -> out_of_scope "objects"
| Tstr_class_type _ -> out_of_scope "class types" | Tstr_class_type _ -> out_of_scope "class types"
| Tstr_include _ -> out_of_scope "includes" | Tstr_include _ -> out_of_scope "includes"
| Tstr_attribute _ -> out_of_scope "attributes" | Tstr_attribute attrs ->
let log_status =
match extract_attr attrs with
| [] -> ""
| x :: xs -> x
in Log.toggle log_status; ""
and js_of_branch b obj = and js_of_branch b obj =
let spat, binders = js_of_pattern b.c_lhs obj in let spat, binders = js_of_pattern b.c_lhs obj in
......
...@@ -29,7 +29,7 @@ let initial_env () = ...@@ -29,7 +29,7 @@ let initial_env () =
then Env.open_pers_signature "Stdlib" Env.initial_unsafe_string then Env.open_pers_signature "Stdlib" Env.initial_unsafe_string
else Env.open_pers_signature "Stdlib" Env.initial_unsafe_string else Env.open_pers_signature "Stdlib" Env.initial_unsafe_string
with Not_found -> with Not_found ->
fatal_error "cannot open pervasives" fatal_error "cannot open stdlib"
(** Optionally preprocess a source file *) (** Optionally preprocess a source file *)
let preprocess sourcefile = let preprocess sourcefile =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment