basic filter, sort, emit
This commit is contained in:
parent
947e666706
commit
e463d43047
9 changed files with 149 additions and 87 deletions
96
lib/pipes.ml
96
lib/pipes.ml
|
@ -1,89 +1,15 @@
|
|||
open Angstrom.Buffered
|
||||
open Parse
|
||||
|
||||
let print_buf buf = print_endline ("buffer has " ^ Bigstringaf.to_string buf)
|
||||
|
||||
(* let read_all () =
|
||||
let parser = Angstrom.Unbuffered.parse culr_parse
|
||||
and buf = Bigstringaf.create 4096 in
|
||||
In_channel.set_binary_mode stdin true;
|
||||
print_endline "doing it";
|
||||
let rec loop parser =
|
||||
parser |> function
|
||||
(* START CONDITION *)
|
||||
| Partial { committed = 0; continue } -> (
|
||||
match In_channel.input_bigarray stdin buf 0 4096 with
|
||||
| 0 ->
|
||||
print_endline "got 0 end";
|
||||
raise End_of_file
|
||||
| _ ->
|
||||
print_buf buf;
|
||||
print_endline "got partial 0";
|
||||
loop (continue buf ~off:0 ~len:4096 Incomplete) (* CONTINUE *))
|
||||
| Partial { continue; _ } -> (
|
||||
match In_channel.input_bigarray stdin buf 0 4096 with
|
||||
| 0 ->
|
||||
print_endline "got + end";
|
||||
raise End_of_file
|
||||
| _ ->
|
||||
print_buf buf;
|
||||
print_endline "got partial +";
|
||||
loop (continue buf ~off:0 ~len:4096 Incomplete))
|
||||
| Done (_, _) ->
|
||||
print_endline "got done";
|
||||
raise End_of_file
|
||||
| Fail (_, _, _) -> print_endline "got fail"
|
||||
in
|
||||
try loop parser
|
||||
with End_of_file -> (
|
||||
print_endline "eof";
|
||||
parser |> state_to_option |> function
|
||||
| Some chunks ->
|
||||
print_endline "chunks:";
|
||||
List.iter (fun x -> debug_print x) chunks
|
||||
| None ->
|
||||
print_endline "no chunks";
|
||||
()) *)
|
||||
|
||||
(* let read_all_3 () =
|
||||
let parser = parse ~initial_buffer_size:4096 culr_parse
|
||||
and buf = Bigstringaf.create 4096 in
|
||||
In_channel.set_binary_mode stdin true;
|
||||
print_endline "doing it";
|
||||
let rec loop parser =
|
||||
Bigarray.Array1.fill buf '\x00';
|
||||
match In_channel.input_bigarray stdin buf 0 4096 with
|
||||
| 0 -> (
|
||||
print_endline "got eof";
|
||||
parser
|
||||
|> (function Partial cont -> cont `Eof | _ -> parser)
|
||||
|> state_to_option
|
||||
|> function
|
||||
| Some chunks -> List.iter debug_print chunks
|
||||
| None -> print_endline "nothing")
|
||||
| _ -> (
|
||||
print_endline "got buf:";
|
||||
print_buf buf;
|
||||
parser |> function
|
||||
| Partial cont -> loop (cont (`Bigstring buf))
|
||||
| Done (_, chunks) ->
|
||||
print_endline "got done";
|
||||
List.iter debug_print chunks
|
||||
| Fail (_, _, _) -> print_endline "got fail")
|
||||
in
|
||||
loop parser *)
|
||||
|
||||
(* let rec loop state =
|
||||
state |> function
|
||||
| Partial {committed; continue} -> continue
|
||||
| Done(_,_) -> ()
|
||||
| Fail (_,_,_) -> () *)
|
||||
|
||||
let read_all () =
|
||||
In_channel.set_binary_mode stdin true;
|
||||
Angstrom_unix.parse_many ~buf_size:4096 culr_parse (fun c -> debug_print c) In_channel.stdin
|
||||
let t = Emitter.create
|
||||
and culr = Processing.Culriser.create [ Simple 4; Simple 1 ] in
|
||||
Angstrom_unix.parse_many ~buf_size:4096 Parse.culr_parse
|
||||
(fun c ->
|
||||
c |> Processing.ansi_filter
|
||||
|> Processing.Culriser.add_colour culr
|
||||
|> List.iter (Emitter.serialise t))
|
||||
stdin
|
||||
|> function
|
||||
| unparsed, Ok _ ->
|
||||
print_endline ("didn't parse this much: " ^ string_of_int unparsed.len ^ "\nunparsed:\n" ^ (Bigstringaf.substring unparsed.buf ~off:unparsed.off ~len:unparsed.len) );
|
||||
()
|
||||
| _, Ok _ ->
|
||||
Emitter.flush t
|
||||
(* print_endline ("didn't parse this much: " ^ string_of_int unparsed.len ^ "\nunparsed:\n" ^ (Bigstringaf.substring unparsed.buf ~off:unparsed.off ~len:unparsed.len) ); *)
|
||||
| _ -> ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue