|
@@ -49,31 +49,64 @@ let s_date d =
|
|
|
|
|
|
let s_hash key = create_ascii (EvalHash.rev_hash key)
|
|
let s_hash key = create_ascii (EvalHash.rev_hash key)
|
|
|
|
|
|
-let rec s_object depth o =
|
|
|
|
|
|
+let rec indent buf s n =
|
|
|
|
+ match n with
|
|
|
|
+ | 0 -> ()
|
|
|
|
+ | _ -> begin
|
|
|
|
+ Buffer.add_string buf s;
|
|
|
|
+ indent buf s (n - 1)
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+let rec s_object depth indent_level o =
|
|
let fields = object_fields o in
|
|
let fields = object_fields o in
|
|
let buf = Buffer.create 0 in
|
|
let buf = Buffer.create 0 in
|
|
|
|
+ let inner_indent_level = indent_level + 1 in
|
|
|
|
+
|
|
Buffer.add_string buf "{";
|
|
Buffer.add_string buf "{";
|
|
|
|
+ (match (get_ctx()).print_indentation with
|
|
|
|
+ | None -> ()
|
|
|
|
+ | Some s -> begin
|
|
|
|
+ Buffer.add_string buf "\n";
|
|
|
|
+ indent buf s inner_indent_level
|
|
|
|
+ end);
|
|
|
|
+
|
|
List.iteri (fun i (k,v) ->
|
|
List.iteri (fun i (k,v) ->
|
|
- if i > 0 then Buffer.add_string buf ", ";
|
|
|
|
|
|
+ if i > 0 then begin
|
|
|
|
+ match (get_ctx()).print_indentation with
|
|
|
|
+ | None -> Buffer.add_string buf ", "
|
|
|
|
+ | Some s -> begin
|
|
|
|
+ Buffer.add_string buf ",\n";
|
|
|
|
+ indent buf s inner_indent_level
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
Buffer.add_string buf (rev_hash k);
|
|
Buffer.add_string buf (rev_hash k);
|
|
Buffer.add_string buf ": ";
|
|
Buffer.add_string buf ": ";
|
|
- Buffer.add_string buf (s_value depth v).sstring;
|
|
|
|
|
|
+ Buffer.add_string buf (s_value ~indent_level:inner_indent_level depth v).sstring;
|
|
) fields;
|
|
) fields;
|
|
|
|
+
|
|
|
|
+ (match (get_ctx()).print_indentation with
|
|
|
|
+ | None -> ()
|
|
|
|
+ | Some s -> begin
|
|
|
|
+ Buffer.add_string buf "\n";
|
|
|
|
+ indent buf s indent_level
|
|
|
|
+ end);
|
|
|
|
+
|
|
Buffer.add_string buf "}";
|
|
Buffer.add_string buf "}";
|
|
let s = Buffer.contents buf in
|
|
let s = Buffer.contents buf in
|
|
create_with_length s (try UTF8.length s with _ -> String.length s)
|
|
create_with_length s (try UTF8.length s with _ -> String.length s)
|
|
|
|
|
|
-and s_array depth va =
|
|
|
|
|
|
+and s_array depth indent_level va =
|
|
join empty_string [
|
|
join empty_string [
|
|
rbkopen;
|
|
rbkopen;
|
|
- EvalArray.join va (s_value depth) rcomma;
|
|
|
|
|
|
+ EvalArray.join va (s_value ~indent_level depth) rcomma;
|
|
rbkclose;
|
|
rbkclose;
|
|
]
|
|
]
|
|
|
|
|
|
-and s_vector depth vv =
|
|
|
|
|
|
+and s_vector depth indent_level vv =
|
|
join empty_string [
|
|
join empty_string [
|
|
rbkopen;
|
|
rbkopen;
|
|
- EvalArray.join (EvalArray.create vv) (s_value depth) rcomma;
|
|
|
|
|
|
+ EvalArray.join (EvalArray.create vv) (s_value ~indent_level depth) rcomma;
|
|
rbkclose;
|
|
rbkclose;
|
|
]
|
|
]
|
|
|
|
|
|
@@ -85,7 +118,7 @@ and s_enum_ctor_name ve =
|
|
end
|
|
end
|
|
with Not_found -> "#unknown"
|
|
with Not_found -> "#unknown"
|
|
|
|
|
|
-and s_enum_value depth ve =
|
|
|
|
|
|
+and s_enum_value depth indent_level ve =
|
|
let name = s_enum_ctor_name ve in
|
|
let name = s_enum_ctor_name ve in
|
|
match ve.eargs with
|
|
match ve.eargs with
|
|
| [||] -> create_ascii name
|
|
| [||] -> create_ascii name
|
|
@@ -93,7 +126,7 @@ and s_enum_value depth ve =
|
|
join empty_string [
|
|
join empty_string [
|
|
create_ascii name;
|
|
create_ascii name;
|
|
rpopen;
|
|
rpopen;
|
|
- join rcomma (Array.to_list (Array.map (s_value (depth + 1)) vl));
|
|
|
|
|
|
+ join rcomma (Array.to_list (Array.map (s_value ~indent_level (depth + 1)) vl));
|
|
rpclose;
|
|
rpclose;
|
|
]
|
|
]
|
|
|
|
|
|
@@ -102,10 +135,10 @@ and s_proto_kind proto = match proto.pkind with
|
|
| PEnum _ -> join empty_string [create_ascii "Enum<"; s_hash proto.ppath; rgt]
|
|
| PEnum _ -> join empty_string [create_ascii "Enum<"; s_hash proto.ppath; rgt]
|
|
| PInstance | PObject -> die "" __LOC__
|
|
| PInstance | PObject -> die "" __LOC__
|
|
|
|
|
|
-and s_value depth v =
|
|
|
|
|
|
+and s_value ?(indent_level=0) depth v =
|
|
let call_to_string () =
|
|
let call_to_string () =
|
|
let vf = field_raise v EvalHash.key_toString in
|
|
let vf = field_raise v EvalHash.key_toString in
|
|
- s_value (depth + 1) (call_value_on v vf [])
|
|
|
|
|
|
+ s_value ~indent_level (depth + 1) (call_value_on v vf [])
|
|
in
|
|
in
|
|
if depth > (get_ctx()).max_print_depth then rstop
|
|
if depth > (get_ctx()).max_print_depth then rstop
|
|
else match v with
|
|
else match v with
|
|
@@ -122,17 +155,17 @@ and s_value depth v =
|
|
| VFunction (f,_) -> rfun
|
|
| VFunction (f,_) -> rfun
|
|
| VFieldClosure _ -> rclosure
|
|
| VFieldClosure _ -> rclosure
|
|
| VHandle _ -> rhandle
|
|
| VHandle _ -> rhandle
|
|
- | VEnumValue ve -> s_enum_value depth ve
|
|
|
|
|
|
+ | VEnumValue ve -> s_enum_value depth indent_level ve
|
|
| VString s -> s
|
|
| VString s -> s
|
|
| VNativeString s -> create_unknown_vstring s
|
|
| VNativeString s -> create_unknown_vstring s
|
|
- | VArray va -> s_array (depth + 1) va
|
|
|
|
- | VVector vv -> s_vector (depth + 1) vv
|
|
|
|
|
|
+ | VArray va -> s_array (depth + 1) indent_level va
|
|
|
|
+ | VVector vv -> s_vector (depth + 1) indent_level vv
|
|
| VInstance {ikind=IDate d} -> s_date d
|
|
| VInstance {ikind=IDate d} -> s_date d
|
|
| VInstance {ikind=IPos p} -> create_ascii ("#pos(" ^ Lexer.get_error_pos (Printf.sprintf "%s:%d:") p ^ ")") (* STODO: not ascii? *)
|
|
| VInstance {ikind=IPos p} -> create_ascii ("#pos(" ^ Lexer.get_error_pos (Printf.sprintf "%s:%d:") p ^ ")") (* STODO: not ascii? *)
|
|
| VInstance {ikind=IRegex r} -> r.r_rex_string
|
|
| VInstance {ikind=IRegex r} -> r.r_rex_string
|
|
| VInstance i -> (try call_to_string () with Not_found -> s_hash i.iproto.ppath)
|
|
| VInstance i -> (try call_to_string () with Not_found -> s_hash i.iproto.ppath)
|
|
- | VObject o -> (try call_to_string () with Not_found -> s_object (depth + 1) o)
|
|
|
|
- | VLazy f -> s_value depth (!f())
|
|
|
|
|
|
+ | VObject o -> (try call_to_string () with Not_found -> s_object (depth + 1) indent_level o)
|
|
|
|
+ | VLazy f -> s_value ~indent_level depth (!f())
|
|
| VPrototype proto ->
|
|
| VPrototype proto ->
|
|
try
|
|
try
|
|
call_to_string()
|
|
call_to_string()
|