Commits

camlspotter committed 438fd07

cosmetics #IGNORE

Comments (0)

Files changed (11)

 
   let show t = 
     let kind = match t.kind with
-      | `Infix `Left -> "infix left"
-      | `Infix `Right -> "infix right"
+      | `Infix `Left    -> "infix left"
+      | `Infix `Right   -> "infix right"
       | `Infix `Noassoc -> "infix noassoc"
-      | `Prefix -> "prefix"
-      | `Postfix -> "postfix"
+      | `Prefix         -> "prefix"
+      | `Postfix        -> "postfix"
     in
     Printf.sprintf "%s %f" kind t.prec
 end
 
   (* List like e1, e2, ..., en is implemented as infix with special builder *)
   type t = 
-    | Infix of O.t * A.op option * t * t (* None means application *)
-    | Postfix of O.t * A.op * t
-    | Prefix of O.t * A.op * t
+    | Infix    of O.t * A.op option * t * t (* None means application *)
+    | Postfix  of O.t * A.op * t
+    | Prefix   of O.t * A.op * t
     | Terminal of A.t
 
   type error = 
-    | Ambiguous of O.t * A.op option * O.t * A.op option
+    | Ambiguous  of O.t * A.op option * O.t * A.op option
     | Empty
     | NoRightArg of O.t * A.op
-    | NoLeftArg of O.t * A.op
+    | NoLeftArg  of O.t * A.op
 
   let format_op ppf (o, aop) =
     let show_aop_opt = function
 
   let rec build = function
     | Terminal a -> a
-    | Infix (_, None, t1, t2) -> A.app (build t1) (build t2)
+    | Infix (_, None,    t1, t2) -> A.app (build t1) (build t2)
     | Infix (_, Some op, t1, t2) -> A.binop op (build t1) (build t2)
     | Postfix (_, op, t) | Prefix (_, op, t) -> A.unop op (build t)
 
   type t
   type op
   val show_op : op -> string
-  val app : t -> t -> t
+  val app   : t -> t -> t
   val binop : op -> t -> t -> t
-  val unop : op -> t -> t
+  val unop  : op -> t -> t
 end) : sig
 
   type error = 
   type t
 
   val terminal : A.t -> t
+
   val infix    : Operator.t -> A.op option -> t -> t -> t
-    (** None for function application *)
+  (** Second arg: None for function application *)
+
   val prefix   : Operator.t -> A.op -> t -> t
   val postfix  : Operator.t -> A.op -> t -> t
   val build : t -> A.t
   type 'a t = Str.t -> ('a * Str.t, error) Result.t
   val run : 'a t -> Str.t -> ('a * Str.t, error) Result.t
 
-  include Planck_intf.S with module Str := Str and type 'a t := 'a t and type error := error
+  include Planck_intf.S with module Str := Str 
+                        and type 'a t := 'a t 
+                        and type error := error
 
 end
 
 
   val chars_to_string : char list t -> string t
   (** Type conversion from [char list t] to [string t].
-      For efficiency reason, users is not encouraged to use this function. Use [matched] instead.
+      For efficiency reason, use [match] instead of [chars_to_string] if possible.
   *)
 
   val matched : unit t -> string t
 
 module type S = sig
   module Str : Stream_intf.S
-  (** Underlied stream *)
+  (** Underlying stream *)
 
   type error = Str.Pos.t * string
   (** Error is a pair of a source position and a message string. *)
 
   val tokens : Str.Elem.t list -> unit t
   (** [tokens elems] matches with a sequence of elements [elems]. 
-      It is faster than using sequence of token. Tail recursion. 
+      It is faster than using sequence of token. Tail recursive.
   *)
 
 
   (** Backtrack, unlike [<|>]. (try_ a <|> b) == (a <!> b)
 
       [a <!> b] first tries [a]. If [a] succeeds, returns it results as the result of the whole expression.
-      If [a] fails, no matter whether it consuming any input or not, [b] is tried. 
+      If [a] fails, no matter whether it consumed any input or not, 
+      [b] is tried against the original input. 
 
       Be careful. Careless uses of [<!>] slow down parser efficiency, a lot.
       If you have to use it, think about memoization.
       the error of [a] is reported instead of [b] *)
 
   val ( <&> ) : 'a t -> ('a -> 'b t) -> 'b t
-  (** For push back. [t <&> f] is like [t >>= f], but the result monad's stream position
-      is the same as [t]. 
+  (** For push back. [t <&> f] is like [t >>= f], but the stream position
+      given to [f] is the same as [t]. 
 
       [a <&> f] first tries [a]. If [a] fails, the entire expression fails.
       If [a] succeeds, [f] is run over the same input [a] takes.
 
 module File = struct
   type t = {
-    fname : string;
-    byte : int; (* in bytes from 0 *)
-    line : int; (* from 1 *)
+    fname  : string;
+    byte   : int; (* in bytes from 0 *)
+    line   : int; (* from 1 *)
     column : int; (* in bytes from 0 *)
   } with sexp
 
+  let none = { fname = ""; byte = -1; line = -1; column = -1; }
+
   let top fname = { fname = fname; byte = 0; line = 1; column = 0; } 
+
   let add_newlines t n = { t with byte = t.byte + n; line = t.line + n; column = 0; }
+
   let add_columns t n = { t with byte = t.byte + n; column = t.column + n; }
-  let none = { fname = ""; byte = -1; line = -1; column = -1; }
+
   let show_filename = function
     | "" -> ""
     | s -> Printf.sprintf  "File %s: " s
+
   let show t = 
     if t.byte < 0 then Printf.sprintf "%s<no location>" (show_filename t.fname)
     else Printf.sprintf "%sline %d, character %d" (show_filename t.fname) t.line t.column
+
   let format ppf t = 
     if t.byte < 0 then Format.fprintf ppf "%s<no location>" (show_filename t.fname)
     else Format.fprintf ppf "%sline %d, character %d" (show_filename t.fname) t.line t.column
+
   let format_detailed ppf t = 
     if t.byte < 0 then Format.fprintf ppf "%s<no location>" (show_filename t.fname)
     else Format.fprintf ppf "%sline %d, character %d, byte %d" (show_filename t.fname) t.line t.column t.byte
 module Region = struct
   type t = {
     start : File.t;
-    end_ : File.t;
+    end_  : File.t;
   } with sexp
 
   let top fname = { start = File.top fname; end_ = File.top fname }
+
   let none = { start = File.none; end_ = File.none }
+
   let show t = 
     if t.start.File.byte < 0 then Printf.sprintf "<no location>"
     else 
 
 module File : sig
   type t = {
-    fname : string; (* file name *) 
-    byte : int;     (* in bytes from 0 *)
-    line : int;     (* from 1 *)
-    column : int;   (* in bytes from 0 *)
+    fname  : string; (** file name *) 
+    byte   : int;    (** in bytes from 0 *)
+    line   : int;    (** from 1 *)
+    column : int;    (** in bytes from 0 *)
   } with sexp
 
   include S with type t := t
 
   val add_newlines : t -> int -> t
-  val add_columns : t -> int -> t
+  val add_columns  : t -> int -> t
   val format_detailed : Format.formatter -> t -> unit
 end
 
 module Region : sig
   type t = { start : File.t; end_ : File.t; } with sexp
+
   include S with type t := t
+
   val merge : [< `Between of t * t | `EndOf of t ] -> t
   (** [merge (`Between (p1, p2))] returns the position starts at the start point of [p1]
       and ends at the end point of [p2].
       [merge (`EndOf p)] returns the 0-length position starts and ends 
       at the end point of [p] 
   *)
-      
 end
-let all_total = ref 0
+let all_total  = ref 0
 let all_wasted = ref 0
-let total = ref 0
-let wasted = ref 0
-let top_ref = ref (ref 0)
-let stack = ref [!top_ref]
+let total      = ref 0
+let wasted     = ref 0
+let top_ref    = ref (ref 0)
+let stack      = ref [!top_ref]
+
 let start () = 
   top_ref := ref 0;
   stack := !top_ref :: !stack
+
 let stop () = 
   match !stack with
   | r::r'::rs -> 
       stack := (r'::rs); 
       !r
   | _ -> assert false
+
 let incr () =
   incr total;
   incr !top_ref
 open Spotlib.Spot
 val start : unit -> unit
-val stop : unit -> int
-val incr : unit -> unit
-val add : int -> unit
+val stop  : unit -> int
+val incr  : unit -> unit
+val add   : int -> unit
 val format : Format.t -> unit
 val reset : unit -> unit
 val recover_all : unit -> unit (* format will print the over all result *)
 
   type error = Str.Pos.t * string
 
-  type 'a t = Str.t -> State.t -> ('a * Str.t * State.t, Str.Pos.t * string) Result.t
-  (* CR jfuruse: Damn, we must expose the definition for the recursive definitions! *)
+  type +'a t
 
   include Planck_intf.S 
     with module Str = Str
   val get : State.t t
   val put : State.t -> unit t
 
-  val run : 'a t -> Str.t -> State.t -> ('a * Str.t * State.t, Str.Pos.t * string) Result.t
+  val run : 'a t -> 
+    Str.t -> State.t -> ('a * Str.t * State.t, Str.Pos.t * string) Result.t
 
 end = struct
   module Str = Str
 
   let set_stream new_st = fun _st state -> `Ok ((), new_st, state)
 
-  let run _t = failwith "use run_with_state"
-  let run_with_state : 'a t -> Str.t -> State.t -> ('a * Str.t * State.t, error) Result.t = 
-    fun t st stat -> t st stat
+  let run t = t
 
   (** state manipulation *)
 
+open Spotlib.Spot
 open Stream_intf
 
 (** Import the constructors *)
-type 'a desc = 'a Spotlib.Spot.Stream.desc = 
+type 'a desc = 'a Stream.desc = 
   | Cons of 'a * 'a desc lazy_t
   | Null
 
   type pos = P.Pos.t
   type attr = P.Attr.t
 
-  open Spotlib.Spot.Stream
+  open Stream
   open P
 
-  type desc = (Elem.t option * Attr.t) Spotlib.Spot.Stream.desc
-  type t = (Elem.t option * Attr.t) Spotlib.Spot.Stream.t (* None means EOS *)
+  type desc = (Elem.t option * Attr.t) Stream.desc
+  type t = (Elem.t option * Attr.t) Stream.t (* None means EOS *)
 
   let cons_desc e attr v = Cons ((Some e,attr), v)
-  let null_desc attr = Cons ((None, attr), Spotlib.Spot.Stream.null)
+  let null_desc attr = Cons ((None, attr), Stream.null)
   let null attr = Lazy.lazy_from_val (null_desc attr)
 
   let peek = function