ocaml-indent / filter.ml

camlspotter d31e732 











































open Sexplib.Conv
open Pos
open Reader
open Parser

type 'a t = 
  | Cons of 'a * 'a t lazy_t
  | Null

type 'a info = {
  space : string;
  token : 'a;
  region : Region.t;
  substr : string;
}

let streamer path = 
  let ic = open_in path in
  try
    let reader = LexReader.create_from_channel ic in
    let rec loop last_region = 
      let token = LexReader.lex reader Lexer.token in
      let region = LexReader.region reader in
      let space_between = 
        let last_end = (snd last_region).Position.pos_cnum in
        LexReader.substring 
          reader last_end ((fst region).Position.pos_cnum - last_end)
      in
      (* token's string *)
      let substr = LexReader.current_substring reader in
      
      Cons ({ space = space_between; token; region; substr },
            lazy (match token with
            | EOF -> close_in ic; Null
            | _ -> loop region))
    in
    loop Region.zero
  with
  | e -> 
      close_in ic;
      raise e

let destr = function
  | lazy Null -> None
  | lazy (Cons (car, cdr)) -> Some (car, cdr)
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.