Commits

camlspotter committed c7ec4f4

hand merged with camlp4-lexer-plug... something went wrong

Comments (0)

Files changed (7)

camlp4/Camlp4/Sig.ml

     (** Token stream from string. *)
     value lex_string : gram -> Loc.t -> string -> not_filtered (Stream.t (Token.t * Loc.t));
 
+    value set_from_lexbuf : 
+      (?quotations: bool -> Lexing.lexbuf -> Stream.t (Token.t * Loc.t)) 
+    -> unit;
+      
     (** Filter a token stream using the {!Token.Filter} module *)
     value filter : gram -> not_filtered (Stream.t (Token.t * Loc.t)) -> token_stream;
 
     (** Token stream from string. *)
     value lex_string : Loc.t -> string -> not_filtered (Stream.t (Token.t * Loc.t));
 
+    value set_from_lexbuf : 
+      (?quotations: bool -> Lexing.lexbuf -> Stream.t (Token.t * Loc.t)) 
+    -> unit;
+
     (** Filter a token stream using the {!Token.Filter} module *)
     value filter : not_filtered (Stream.t (Token.t * Loc.t)) -> token_stream;
 
       The lexer do not use global (mutable) variables: instantiations
       of [Lexer.mk ()] do not perturb each other. *)
   value mk : unit -> (Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t));
+
+  value from_lexbuf : 
+    ?quotations: bool -> Lexing.lexbuf -> Stream.t (Token.t * Loc.t);
+
+  value set_from_lexbuf : 
+    (?quotations: bool -> Lexing.lexbuf -> Stream.t (Token.t * Loc.t)) -> unit;
 end;
 
 

camlp4/Camlp4/Struct/Grammar/Dynamic.ml

  *)
 module Make (Lexer : Sig.Lexer)
 : Sig.Grammar.Dynamic with module Loc = Lexer.Loc
-                         and module Token = Lexer.Token
+                       and module Token = Lexer.Token
+                       and type   token_info = (Structure.MakeTokenInfo Lexer.Loc).t
 = struct
   module Structure = Structure.Make Lexer;
   module Delete    = Delete.Make    Structure;
 
   value lex_string g loc str = lex g loc (Stream.of_string str);
 
+  value set_from_lexbuf = Lexer.set_from_lexbuf;
+
   value filter g ts = Tools.keep_prev_loc (Token.Filter.filter g.gfilter ts);
 
   value parse_tokens_after_filter entry ts = Entry.parse_tokens_after_filter entry ts;

camlp4/Camlp4/Struct/Grammar/Static.ml

 
 module Make (Lexer : Sig.Lexer)
 : Sig.Grammar.Static with module Loc = Lexer.Loc
-                        and module Token = Lexer.Token
+                      and module Token = Lexer.Token
+                      and type   token_info = (Structure.MakeTokenInfo Lexer.Loc).t
 = struct
   module Structure = Structure.Make Lexer;
   module Delete = Delete.Make Structure;
 
   value lex_string loc str = lex loc (Stream.of_string str);
 
+  value set_from_lexbuf = Lexer.set_from_lexbuf;
+
   value filter ts = Tools.keep_prev_loc (Token.Filter.filter gram.gfilter ts);
 
   value parse_tokens_after_filter entry ts = Entry.E.parse_tokens_after_filter entry ts;

camlp4/Camlp4/Struct/Grammar/Structure.ml

 
 open Sig.Grammar;
 
+type token_abs_info 'loc =
+  { prev_loc : 'loc
+  ; cur_loc : 'loc
+  ; prev_loc_only : bool
+  };
+
+module MakeTokenInfo (Loc : Sig.Type) = struct
+  type t = token_abs_info Loc.t;
+end;
+
 module type S = sig
   module Loc          : Sig.Loc;
   module Token        : Sig.Token with module Loc = Loc;
       warning_verbose : ref bool;
       error_verbose   : ref bool };
 
-  type token_info = { prev_loc : Loc.t
-                    ; cur_loc : Loc.t
-                    ; prev_loc_only : bool
-                    };
+  type token_info = (MakeTokenInfo Loc).t;
 
   type token_stream = Stream.t (Token.t * token_info);
 
       warning_verbose : ref bool;
       error_verbose   : ref bool };
 
-  type token_info = { prev_loc : Loc.t
-                    ; cur_loc : Loc.t
-                    ; prev_loc_only : bool
-                    };
+  type token_info = (MakeTokenInfo Loc).t;
 
   type token_stream = Stream.t (Token.t * token_info);
 

camlp4/Camlp4/Struct/Grammar/Tools.ml

 (* PR#5090: don't do lookahead on get_prev_loc. *)
 value get_prev_loc_only = ref False;
 
-module Make (Structure : Structure.S) = struct
-  open Structure;
+open Structure;
+
+module Make (GramStruct : Structure.S) = struct
+  open GramStruct;
 
   value empty_entry ename _ =
     raise (Stream.Error ("entry [" ^ ename ^ "] is empty"));

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

camlp4/Camlp4Top/Top.ml

 open Syntax;
 open Camlp4.Sig;
 module Ast2pt = Camlp4.Struct.Camlp4Ast2OCamlAst.Make Ast;
-module Lexer = Camlp4.Struct.Lexer.Make Token;
+(* module Lexer = Camlp4.Struct.Lexer.Make Token; *)
+module Lexer = PreCast.Lexer;
 
 external not_filtered : 'a -> Gram.not_filtered 'a = "%identity";
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.