shithub: martian9

Download patch

ref: 6cec07e20602ff1a19e3179c48ad11203c61c274
parent: 53b4d27243b9b20a6628aa200299c3b5ac6f173a
author: McKay Marston <mckay.marston@greymanlabs.com>
date: Mon Oct 19 18:17:58 EDT 2020

closer

--- a/macro.ml
+++ b/macro.ml
@@ -231,12 +231,13 @@
   let symbol = (Printer.print sym true) in
   let variants = ref Types.M9map.empty in
   let rec register_variants clauses =
+    let new_sym = gen_sym symbol in
     match clauses with
     | [ pattern ] ->
-       variants := Types.M9map.add (gen_sym symbol) pattern !variants;
+       variants := Types.M9map.add new_sym pattern !variants;
        !variants
     | pattern :: rest ->
-       variants := Types.M9map.add (gen_sym symbol) pattern !variants;
+       variants := Types.M9map.add new_sym pattern !variants;
        register_variants rest
     | _ -> raise (Utils.Syntax_error "macro pattern registration botch")
   in
--- a/reader.ml
+++ b/reader.ml
@@ -42,6 +42,22 @@
     raise End_of_file)
 ;;
 
+let fix_pattern sym pattern =
+  let tokenized_pattern = tokenize pattern in
+  let new_pattern = ref [] in
+  let rec replace_token tokens =
+    match tokens with
+    | token :: [] -> let t = if token = "_" then (Printer.print sym true) else token in
+                     new_pattern := !new_pattern @ [t];
+                     !new_pattern
+    | token :: rest -> let t = if token = "_" then (Printer.print sym true) else token in
+                       new_pattern := !new_pattern @ [t];
+                       replace_token rest
+    | _ -> raise (Utils.Syntax_error "unable to fix pattern")
+  in
+  replace_token tokenized_pattern
+;;
+
 let read_atom token =
   match token with
   | "null" -> T.Nil
@@ -121,7 +137,10 @@
         print_endline ("    variants: " ^ (Printer.print (Types.map variants) true));
         let macro_entry = Types.macro sym literals (Types.list clauses) variants in
         Env.set registered_macros sym macro_entry;
-        Types.M9map.iter (fun k v -> print_endline ("  >> " ^ Printer.print k true ^ ":  " ^ Printer.print v true)) variants;
+        Types.M9map.iter (fun k v ->
+            print_endline ("   >>> " ^ String.concat " " (fix_pattern k (Printer.print v true)));
+            print_endline ("  >> " ^ Printer.print k true ^ ":  " ^ Printer.print v true))
+          variants;
         print_endline(" >>>>>> MACRO: " ^ Printer.print macro_entry true)
      | _ -> raise (Utils.Syntax_error "read_macro botch"))
   | _ as x -> print_endline ("  rest: " ^ Printer.dump x));