* update indent
* fix debug semantics
This commit is contained in:
parent
6fda9b0e7e
commit
06ab5bb3c1
1 changed files with 13 additions and 9 deletions
20
test.ml
20
test.ml
|
@ -17,25 +17,25 @@ let debug_parser oc parsed =
|
||||||
| Syntax.Assign d -> "Assign (\"" ^ d.var ^ "\", " ^ fmt_e d.expr ^ ")"
|
| Syntax.Assign d -> "Assign (\"" ^ d.var ^ "\", " ^ fmt_e d.expr ^ ")"
|
||||||
| Syntax.Do d -> "Do (" ^ fmt_e d.expr ^ ")"
|
| Syntax.Do d -> "Do (" ^ fmt_e d.expr ^ ")"
|
||||||
| Syntax.Return d -> "Return (" ^ fmt_e d.expr ^ ")"
|
| Syntax.Return d -> "Return (" ^ fmt_e d.expr ^ ")"
|
||||||
and fmt_b b = "[ " ^ String.concat "\n; " (List.map fmt_i b) ^ " ]"
|
and fmt_b b = " [ " ^ String.concat "\n ; " (List.map fmt_i b) ^ "\n ]"
|
||||||
and fmt_f = function
|
and fmt_f = function
|
||||||
| Syntax.Func d ->
|
| Syntax.Func d ->
|
||||||
"Func ( "
|
"Func ( "
|
||||||
^ string_of_type_t d.type_t
|
^ string_of_type_t d.type_t
|
||||||
^ ", \""
|
^ ", \""
|
||||||
^ d.func
|
^ d.func
|
||||||
^ ", ["
|
^ "\", [ "
|
||||||
^ String.concat
|
^ String.concat
|
||||||
"\n; "
|
", "
|
||||||
(List.map
|
(List.map
|
||||||
(fun a ->
|
(fun a ->
|
||||||
match a with
|
match a with
|
||||||
| Syntax.Arg a -> "(" ^ string_of_type_t a.type_t ^ ")" ^ a.name ^ "")
|
| Syntax.Arg a -> "(" ^ string_of_type_t a.type_t ^ ")" ^ a.name ^ "")
|
||||||
d.args)
|
d.args)
|
||||||
^ "], ["
|
^ " ], [\n"
|
||||||
^ fmt_b d.code
|
^ fmt_b d.code
|
||||||
^ "])\n"
|
^ "])"
|
||||||
and fmt_p p = "[ " ^ String.concat "\n; " (List.map fmt_f p) ^ "]" in
|
and fmt_p p = "[ " ^ String.concat "\n; " (List.map fmt_f p) ^ "\n]" in
|
||||||
Printf.fprintf oc "%s\n" (fmt_p parsed)
|
Printf.fprintf oc "%s\n" (fmt_p parsed)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@ let debug_semantics oc ast =
|
||||||
| Assign (v, e) -> "Assign (\"" ^ v ^ "\", " ^ fmt_e e ^ ")"
|
| Assign (v, e) -> "Assign (\"" ^ v ^ "\", " ^ fmt_e e ^ ")"
|
||||||
| Do e -> "Do (" ^ fmt_e e ^ ")"
|
| Do e -> "Do (" ^ fmt_e e ^ ")"
|
||||||
| Return e -> "Return (" ^ fmt_e e ^ ")"
|
| Return e -> "Return (" ^ fmt_e e ^ ")"
|
||||||
and fmt_b b = "[ " ^ String.concat "\n; " (List.map fmt_i b) ^ " ]" in
|
and fmt_b b = "[ " ^ String.concat "\n; " (List.map fmt_i b) ^ " ]"
|
||||||
Printf.fprintf oc "%s\n" (fmt_b ast)
|
and fmt_f = function
|
||||||
|
| Func (f, args, b) ->
|
||||||
|
"Func ( " ^ f ^ ", [" ^ String.concat " ; " args ^ "],\n[" ^ fmt_b b ^ "])\n"
|
||||||
|
and fmt_p p = "[ " ^ String.concat "\n; " (List.map fmt_f p) ^ "]" in
|
||||||
|
Printf.fprintf oc "%s\n" (fmt_p ast)
|
||||||
;;
|
;;
|
||||||
|
|
Reference in a new issue