From eb0d0d1c7b78a5c592105f09648acbd1cd9c61ad Mon Sep 17 00:00:00 2001
From: Thomas Wood <thomas.wood09@imperial.ac.uk>
Date: Wed, 25 Nov 2015 10:24:15 +0000
Subject: [PATCH] Revert "Or Patterns"

This reverts commit 0f46d81bbb28ea4706d6f3a4e1ce5f69684cf4da.
---
 generator/js_of_ast.ml | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml
index 7a424ee..d8f62c2 100644
--- a/generator/js_of_ast.ml
+++ b/generator/js_of_ast.ml
@@ -77,17 +77,9 @@ let ppf_lambda_wrap s =
   Printf.sprintf "(function () {@;<1 2>@[<v 0>%s@]@,}())@," s
 
 let ppf_branch case binders expr =
-  Printf.sprintf "%s: @[<v 0>%s%s@]@,"
+  Printf.sprintf "%s: @[<v 0>%s@,return %s;@]"
                  case binders expr
 
-let rec ppf_branches branches expr =
-  match branches with
-  | (case, binders) :: [] ->
-    let expr = Printf.sprintf "@,return %s;" expr in
-    ppf_branch case binders expr
-  | (case, binders) :: l' -> (ppf_branch case binders "") ^ (ppf_branches l' expr)
-  | [] -> ""
-
 let ppf_let_in decl exp =
   let s =
     Printf.sprintf "%s@,return %s;"
@@ -247,16 +239,14 @@ and js_of_structure_item s =
   | Tstr_attribute  _  -> out_of_scope loc "attributes"
 
 and js_of_branch b obj =
-  let patterns = js_of_pattern b.c_lhs obj in
+  let spat, binders = js_of_pattern b.c_lhs obj in
   let se = js_of_expression b.c_rhs in
-  (*if binders = "" then *)ppf_branches patterns se
-  (* FIXME: Logging
-   else
+  if binders = "" then ppf_branch spat binders se
+  else
     let typ = match List.rev (Str.split (Str.regexp " ") spat) with
       | [] -> assert false
       | x :: xs -> String.sub x 0 (String.length x)
     in L.log_line (ppf_branch spat binders se) (L.Add (binders, typ))
-  *)
 
 and js_of_expression e =
   let loc = e.exp_loc in
@@ -367,9 +357,9 @@ and js_of_let_pattern pat expr =
 and js_of_pattern pat obj =
   let loc = pat.pat_loc in
   match pat.pat_desc with
-  | Tpat_any                     -> ["default", ""]
-  | Tpat_constant   c            -> [ppf_match_case (js_of_constant c), ""]
-  | Tpat_var       (id, _)       -> ["default", (ppf_match_binders [ppf_match_binder (ppf_ident id) ""])]
+  | Tpat_any                     -> "default", ""
+  | Tpat_constant   c            -> ppf_match_case (js_of_constant c), ""
+  | Tpat_var       (id, _)       -> "default", (ppf_match_binders [ppf_match_binder (ppf_ident id) ""])
   | Tpat_construct (_, cd, el) ->
      let c = cd.cstr_name in
      let spat = if is_sbool c then ppf_match_case c else ppf_match_case ("\"" ^ c ^ "\"") in
@@ -378,11 +368,11 @@ and js_of_pattern pat obj =
      | Tpat_any         -> ""
      | _                -> out_of_scope var.pat_loc "Nested pattern matching") in
      let binders = if el = [] then "" else ppf_match_binders (map_cstr_fields ~loc bind cd el) in
-     [spat, binders]
-  | Tpat_or (p1,p2,_) -> (js_of_pattern p1 obj) @ (js_of_pattern p2 obj)
+     spat, binders
   | Tpat_tuple el -> unsupported ~loc "tuple matching"
   | Tpat_array el -> unsupported ~loc "array-match"
   | Tpat_record (_,_) -> unsupported ~loc "record"
+  | Tpat_or (_,_,_) -> error ~loc "not implemented yet"
   | Tpat_alias (_,_,_) -> out_of_scope loc "alias-pattern"
   | Tpat_variant (_,_,_) -> out_of_scope loc "polymorphic variants in pattern matching"
   | Tpat_lazy _ -> out_of_scope loc "lazy-pattern"
-- 
GitLab