planck / lib / pbuffer.mli

(** Monadic parser for buffered char streams *)

(** Extend(Str)(Base) extends Base for Str with buffered string operations
    Typical usage is:

    module MyParser = struct
      module Base = ...(Str)... (* creation of Base *)
      include Base
      include Pbuffer.Extend(Str)(Base)
    end

    It includes the extensions of Pchar.Extend. If you use Pbuffer.Extend, 
    no need of using Pchar.Extend.

    See a use example in test/expr.ml
*)

module type X = sig

  type +'a t (** stream type *)

  val prefix : int -> string t
  (** fast retrieval of the prefix string of the given length *)

  val takeWhile : (char -> bool) -> string t
  (** [takeWhile p] matches the longest prefix string where all the chars hold [p] *)

  val ( ??** ) : (char -> bool) -> string t
  val ( ??* ) : (char -> bool) -> unit t
  (** Same as [Planck_intf.( ?** )] and [Planck_intf.( ?* )] but specialized for char stream *)   

  val string : string -> unit t
  (** Efficient version of [Pchar.string] using Sbuffer. 
      [string s] succeeds if the prefix of the stream is [s]. *)

  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.
  *)

  val matched : unit t -> string t
  (** [matched t] returns the matched string part of [t].
      It is far more efficient than manual concatenation of chars using [chars_to_string].
  *)

  val with_matched : 'a t -> ('a * string) t
  (** [with_matched t] returns the matched string part of [t] 
      along with the original result of [t]. *)

  val ( </> ) : 'a t -> 'a t -> 'a t
  (** Longest match. [a </> b] succeeds if either [a] or [b] succeeds.
      If the both of [a] and [b] succeeds, the longer match is used as the result of [a </> b].

      Note: [a </> b] runs both [a] and [b]. Too many uses of [</>] affects the parsing performance badly.
  *)
end


module Extend
  (SBase : sig
    include Stream_intf.S with type Elem.t = char
                          and  type Pos.t = Position.File.t
    val substr : t -> int -> int -> string * t
    val takeWhile : (char -> bool) -> t -> string * t
    val bytes : t -> int
  end)
  (PBase : Planck_intf.S 
     with type Str.desc   = SBase.desc (* I want to say Str.t = SBase.t but not possible *)
     and  type Str.Elem.t = char
     and  type Str.Pos.t  = Position.File.t
     and  type Str.Attr.t = SBase.Attr.t )
  : X with type 'a t := 'a PBase.t


module Make(SBase : sig
  include Stream_intf.S with type Elem.t = char
                        and  type Pos.t = Position.File.t
  val substr : t -> int -> int -> string * t
  val takeWhile : (char -> bool) -> t -> string * t
  val bytes : t -> int
end) : sig
  include Pbase.S 
    with type Str.desc   = SBase.desc (* I want to say Str.t = SBase.t but not possible *)
    and  type Str.Elem.t = char
    and  type Str.Pos.t  = Position.File.t
    and  type Str.Attr.t = SBase.Attr.t
    and  type 'a t = SBase.t -> ('a * SBase.t, SBase.Pos.t * string (* =error *)) Result.t
  include X with type 'a t := 'a Pbase.Make(SBase).t
end
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.