Commits

camlspotter committed e1bcbff

update for planck

Comments (0)

Files changed (11)

parsing/.#funcking_module.ml

-jun@ubuntu.2396:1351132903

parsing/.#lexer.ml

-jun@ubuntu.2396:1351132903

parsing/.#tokenParser.auto.mli

-jun@ubuntu.2396:1351132903

parsing/OMakefile

 NO_INSTALL=true
 
 FILES0[] =
-   input
    token
    tokenStream
    lex
 
 
 FILES1[] =
-   input
    token
    tokenStream
    tokenParser

parsing/input.ml

-open Planck
-
-module Stream = Strfile.Buffered
-
-module Parser = struct
-  module Base = Pbase.Make(Stream)
-
-  include Base
-  include Pbuffer.Extend(Stream)(Base)
-end
-
-
-open Planck
 open Printf
 open Token
 
-open Input.Parser
+open Planck
+open Planck.Pfile.Parser
 
 module From_OCaml_source_code = struct
   (* Identical or almost identical code *)
           pos <-- position;
           str <-- stream;
           let name = match name_opt with Some name -> name | None -> pos.Position.File.fname in
-          let str' = Input.Stream.set_position str { pos with Position.File.fname = name; line = int_of_string num; column = 0 } in
+          let str' = Pfile.Stream.set_position str { pos with Position.File.fname = name; line = int_of_string num; column = 0 } in
           set_stream str';
           ocaml_token ())
        <!> (token '#'  >>= fun () -> return_with_pos SHARP)) 
 open Planck
-open Input.Parser
+open Pfile.Parser
 
 val ocaml_token : (Token.t * Position.Region.t) t
-val ocaml_token_stream : Input.Stream.t -> TokenStream.t
+val ocaml_token_stream : Pfile.Stream.t -> TokenStream.t
 val skip_sharp_bang : unit t
 
 (* higher interface *)

parsing/lexer

-lexer.opt

parsing/lextest.ml

 open Planck
 
 let rec parse_and_print stream = 
-  match Input.Parser.run (Input.Parser.eos_as_none Lex.ocaml_token) stream with
+  match Pfile.Parser.run (Pfile.Parser.eos_as_none Lex.ocaml_token) stream with
   | Result.Ok (None, _) -> () (* EOS *)
   | Result.Ok (Some (v, pos), stream') ->
       let show t = Sexplib.Sexp.to_string_hum (Token.sexp_of_t t) in
 
 let _ = Arg.parse [] (fun x ->
   let ic = open_in x in
-  let stream = Input.Stream.from_chan ~filename:"" ic in
+  let stream = Pfile.Stream.from_chan ~filename:"" ic in
   parse_and_print stream;
   close_in ic) "lextest files"
 

parsing/tokenStream.ml

 open Planck
 
-module MemoKey = struct
-  type t = string
-  let hash = Hashtbl.hash
-  let equal (x : string) y = x = y
-end
-
-module Memo = Hashtbl.Make(MemoKey)
-
 module Base = struct
 
+  module Elem = Token
   module Pos = Position.Region
 
-  module Elem = Token
-
   module Attr = struct
-    type t = Pos.t option (* last consumed token position *) * Pos.t * (Obj.t, exn) Result.t Memo.t
-    let position (_, pos, _) = pos
-    let last_position (last_pos,_,_) = last_pos 
-    (* let default : t = None, Pos.none, Memo.create 1 *)
-    let memo (_,_,memo) = memo
-    (* let buf (_,buf,_) = buf *)
+    type t = { last_position : Pos.t option (* last consumed token position *);
+               position      : Pos.t;
+               memo          : Smemo.memo
+             }
+    let position t = t.position
+    let last_position t = t.last_position
+    let memo t = t.memo
   end
 
 end
 
-module Str = Stream.Make(Base)
-
+module Str =Stream.Make(Base)
 include Str
 
 include Smemo.Extend(struct
   include Str
-  module Memo = Memo
-  let memo st = Base.Attr.memo (attr st)
+  let memo = Base.Attr.memo
 end)
 
+open Base
+
 (* CR jfuruse: generalize it and port back to Planck.Core *)
-let create (m : ('a option * Position.Region.t) Input.Parser.t) = fun st ->
+let create (m : ('a option * Position.Region.t) Pfile.Parser.t) = fun st ->
   let rec f last_pos st = lazy begin
-    match Input.Parser.run m st with
-    | Result.Ok ((None, pos), _st') -> null_desc (last_pos, pos, Memo.create 107) (* EOS case *)
-    | Result.Ok ((Some v, pos), st') -> cons_desc v (last_pos, pos, Memo.create 107) (f (Some pos) st')
-    | Result.Error (pos, s) -> raise (Input.Parser.Critical_error (pos, s))
+    match Pfile.Parser.run m st with
+    | Result.Ok ((None, pos), _st') -> 
+        null_desc { Attr.last_position = last_pos; 
+                    position      = pos; 
+                    memo          = Smemo.create () } (* EOS case *)
+    | Result.Ok ((Some v, pos), st') -> 
+        cons_desc v { Attr.last_position = last_pos;
+                      position = pos;
+                      memo = Smemo.create () } (f (Some pos) st')
+    | Result.Error (pos, s) -> raise (Pfile.Parser.Critical_error (pos, s))
   end
   in
   f None st
 ;;
 
 let last_position st : Position.Region.t option = Base.Attr.last_position (attr st)
-

parsing/tokenStream.mli

 open Planck
 
-include Stream_intf.S with type Elem.t = Token.t
-                      and  type Pos.t  = Position.Region.t
-
-val memoize : string -> (t -> 'a) -> (t -> 'a)
+include Smemo.S with type Elem.t = Token.t
+                and  type Pos.t  = Position.Region.t
 
 val create : 
-  (Token.t option * Position.Region.t) Input.Parser.t 
-  -> Input.Stream.t
+  (Token.t option * Position.Region.t) Pfile.t 
+  -> Pfile.Stream.t
   -> t
 
 val last_position : t -> Position.Region.t option
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.