Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [Caml-list] Setting the EOL character....
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] Setting the EOL character....


Richard Lyman wrote:
> Ok...
> 
> That doesn't look too bad - and I think I almost understand it. : )
> 
> ... so then - there's no OCaml concept of a global EOL variable, or method
> that deals with reading in from a stream until the EOL??
> 
> I was hoping more for something along the lines of -
> 
> (start pseudocode)
> 
> myStream = Unix.accepted_socket_stream
> while(true){
>     a_line = myStream.read_until("\000")
>     deal_with_line(a_line)
> }
> 
> (end pseudocode)
> 
> Thanks for your thoughts!
> 
> -Rich

How about the following:

let process_line out_channel line = .... in
let read_until_null in_channel out_channel =
    Scanf.fscanf in_channel "[^\000]\000"
      (process_line out_channel) in
let process_request in_channel out_channel =
    try while true do
       read_until_null in_channel out_channel
    done with End_of_file -> ()
let sockaddr = <server_socket_specification> in
Unix.establish_server process_request sockaddr


Nonetheless, let me suggest that you look into ocamllex and 
ocamlyacc--lexer and parser generators respectively. They 
are probably your best choice for lexing and parsing the 
input stream, no matter how weird its structure.

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners