camlspotter avatar camlspotter committed 9d8eb37

planck update

Comments (0)

Files changed (7)

parsing/OMakefile

 
 FILES0[] =
    token
-   tokenStream
    lex
    lextest
 
 
 FILES1[] =
    token
-   tokenStream
-   tokenParser
+   parser
    lex
 
 MyOCamlProgram(lexer1, $(FILES1))
          return ())
   <!> return ()
 
+(*
 let ocaml_token_stream = TokenStream.create (perform
   (v, pos) <-- ocaml_token;
   match v with
   | EOF -> return (None, pos)
   | _ -> return (Some v, pos))
+*)
 open Pfile.Parser
 
 val ocaml_token : (Token.t * Position.Region.t) t
-val ocaml_token_stream : Pfile.Stream.t -> TokenStream.t
+(* val ocaml_token_stream : Pfile.Stream.t -> TokenStream.t *)
 val skip_sharp_bang : unit t
 
 (* higher interface *)

parsing/tokenParser.ml

 open Planck
 
-module Stream = TokenStream
+include Ptoken.Make(TokenStream)
 
-include Pbase.Make(TokenStream)
-
-let last_position : Position.Region.t t = perform
-  st <-- stream;
-  return (match Stream.last_position st with
-    | Some reg -> reg
-    | None -> Position.Region.none)
-
-(** Efficient version of with_region *)
-let with_region (t : 'a t) : ('a * Position.Region.t) t = perform
-  last_bot_pos <-- last_position;
-  last_top_pos <-- position;
-  res <-- t;
-  top_pos <-- position;
-  bot_pos <-- last_position;
-  let pos = 
-    let open Position.Region in
-    if last_top_pos = top_pos then 
-      (* No advancement. OCaml's behaviour is: return the end of the last consumed position *)
-      { last_bot_pos with start = last_bot_pos.end_ }
-    else
-      { start = last_top_pos.start; 
-        end_ = bot_pos.end_ }
-  in
-  (* \ assert (is_valid pos); *)
-  return (res, pos)
-
+let with_region x = with_region Position.Region.merge x

parsing/tokenParser.mli

 open Planck
 
 include Pbase.S 
-with type Str.Elem.t = TokenStream.Elem.t
-and  type Str.Attr.t = TokenStream.Attr.t
-and  type Str.Pos.t  = TokenStream.Pos.t
-and  type error = TokenStream.Pos.t * string
-and  type 'a t = TokenStream.t -> ('a * TokenStream.t, TokenStream.Pos.t * string) Result.t
+  with type Str.Elem.t = Token.t
+  and  type Str.Attr.t = TokenStream.Attr.t
+  and  type Str.Pos.t  = Position.Region.t
+  and  type Str.desc   = TokenStream.desc
 
-val with_region : 'a t -> ('a * Planck.Position.Region.t) t
+val last_position : Position.Region.t t
+val with_region : 'a t -> ('a * Position.Region.t) t

parsing/tokenStream.ml

 open Planck
 
-module Base = struct
-
-  module Elem = Token
-  module Pos = Position.Region
-
-  module Attr = struct
-    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)
-include Str
-
-include Smemo.Extend(struct
-  include Str
-  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) Pfile.Parser.t) = fun st ->
-  let rec f last_pos st = lazy begin
-    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)
+include Stoken.Make(Token)(Position.Region)(Pfile.Parser)

parsing/tokenStream.mli

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