Source

mutated_ocaml / camlp4 / Camlp4 / Struct / Lexer.mll

Diff from to

camlp4/Camlp4/Struct/Lexer.mll

     in
     self 0 s
 
-  let from_context c =
+  let from_context quotations lb =
+    let c = { (default_context lb) with
+              loc        = Loc.of_lexbuf lb;
+              antiquots  = !Camlp4_config.antiquotations;
+              quotations = quotations      }
+    in
     let next _ =
       let tok = with_curr_loc token c in
       let loc = Loc.of_lexbuf c.lexbuf in
     in Stream.from next
 
   let from_lexbuf ?(quotations = true) lb =
-    let c = { (default_context lb) with
-              loc        = Loc.of_lexbuf lb;
-              antiquots  = !Camlp4_config.antiquotations;
-              quotations = quotations      }
-    in from_context c
+    from_context quotations lb
+
+  let from_lexbuf_ref = ref from_lexbuf
+
+  let set_from_lexbuf from_lexbuf = from_lexbuf_ref := from_lexbuf
+
+  let from_lexbuf ?(quotations = true) lb =
+    let zstream = lazy (!from_lexbuf_ref ~quotations lb) in
+    Stream.from (fun _ ->
+      try
+	Some (Stream.next (Lazy.force zstream))
+      with
+      | Stream.Failure -> None)
 
   let setup_loc lb loc =
     let start_pos = Loc.start_pos loc in