Guest User

Untitled

a guest
Oct 1st, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.04 KB | None | 0 0
  1.  
  2. open Lexing
  3.  
  4. let concat lb1 lb2 =
  5.   { lb1 with refill_buff =
  6.     let in_lb2 = ref false in
  7.     fun lb ->
  8.       if !in_lb2 then lb2.refill_buff lb
  9.       else begin
  10.     lb1.refill_buff lb;
  11.     if lb.lex_eof_reached
  12.     then begin
  13.       in_lb2 := true;
  14.       lb.lex_buffer      <- lb2.lex_buffer;
  15.       lb.lex_buffer_len  <- lb2.lex_buffer_len;
  16.       lb.lex_abs_pos     <- lb2.lex_abs_pos;
  17.       lb.lex_start_pos   <- lb2.lex_start_pos;
  18.       lb.lex_curr_pos    <- lb2.lex_curr_pos;
  19.       lb.lex_last_pos    <- lb2.lex_last_pos;
  20.       lb.lex_last_action <- lb2.lex_last_action;
  21.       lb.lex_eof_reached <- lb2.lex_eof_reached;
  22.       lb.lex_mem         <- lb2.lex_mem;
  23.       lb.lex_start_p     <- lb2.lex_start_p;
  24.       lb.lex_curr_p      <- lb2.lex_curr_p;
  25.       lb2.refill_buff lb
  26.     end
  27.       end
  28.   }
  29.  
  30. let rec read lexbuf =
  31.   lexbuf.refill_buff lexbuf;
  32.   print_string lexbuf.lex_buffer;
  33.   if lexbuf.lex_eof_reached then print_string "\nDone reading.\n"
  34.   else read lexbuf
  35.  
  36. let () = read (concat (from_channel stdin) (from_string "\nEND OF INPUT\n"))
Advertisement
Add Comment
Please, Sign In to add comment