* [Caml-list] unread_char function @ 2003-09-29 15:42 Miles Egan 2003-09-29 18:44 ` Basile Starynkevitch 0 siblings, 1 reply; 4+ messages in thread From: Miles Egan @ 2003-09-29 15:42 UTC (permalink / raw) To: caml list [-- Attachment #1: Type: text/plain, Size: 338 bytes --] I need an "unread_char" function to go along with the input_char function for a tool I'm writing in OCaml, but I can't seem to find one in OCaml 3.07beta. Was it excluded for a technical reason? If not, it looks like it would be fairly easy to add. Would there be any objections to adding it? -- Miles Egan <miles@caddr.com> [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] unread_char function 2003-09-29 15:42 [Caml-list] unread_char function Miles Egan @ 2003-09-29 18:44 ` Basile Starynkevitch 2003-09-29 21:10 ` Pierre Weis 0 siblings, 1 reply; 4+ messages in thread From: Basile Starynkevitch @ 2003-09-29 18:44 UTC (permalink / raw) To: Miles Egan; +Cc: caml-list On Mon, Sep 29, 2003 at 08:42:13AM -0700, Miles Egan wrote: > I need an "unread_char" function to go along with the input_char > function for a tool I'm writing in OCaml, but I can't seem to find one > in OCaml 3.07beta. Perhaps you might want to use streams? They provide some form of lookahead (by factorising common prefixes). Ungetting functions might be not always possible in general (i.e. considering reading from a raw serial line, or a raw network...). -- Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359 http://cristal.inria.fr/~starynke --- all opinions are only mine ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] unread_char function 2003-09-29 18:44 ` Basile Starynkevitch @ 2003-09-29 21:10 ` Pierre Weis 2003-09-29 22:42 ` Miles Egan 0 siblings, 1 reply; 4+ messages in thread From: Pierre Weis @ 2003-09-29 21:10 UTC (permalink / raw) To: Basile Starynkevitch; +Cc: miles, caml-list > On Mon, Sep 29, 2003 at 08:42:13AM -0700, Miles Egan wrote: > > I need an "unread_char" function to go along with the input_char > > function for a tool I'm writing in OCaml, but I can't seem to find one > > in OCaml 3.07beta. > > Perhaps you might want to use streams? They provide some form of lookahead > (by factorising common prefixes). > > Ungetting functions might be not always possible in general (i.e. > considering reading from a raw serial line, or a raw network...). > > -- > Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr > Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359 > http://cristal.inria.fr/~starynke --- all opinions are only mine You may also consider scanf and the format %0c that gives you access to the current character without incorporating it to the current token (as Basile said, this is some form of lookahead, limited to 1 character as is normally the case for streams). To give a more concrete example, here is an elementary scanner for strings, numbers, chars, idents and single character symbols: the scanneer just decides on the first character (after proper skipping of spaces) what is the kind of token to read. let scan_tok sb = Scanf.bscanf sb " %0c" (function | '"' -> Scanf.bscanf sb "%S" (fun v -> String v) | '0' .. '9' | '-' | '+' -> Scanf.bscanf sb "%f" (fun v -> Float v) | '\'' -> Scanf.bscanf sb "%C" (fun v -> Char v) | 'a' .. 'z' | 'A' .. 'Z' -> Scanf.bscanf sb "%[a..zA..Z0..9]" (fun v -> Ident v) | c -> Scanf.bscanf sb "%1c" (fun v -> Symbol v));; val scan_tok : Scanf.Scanning.scanbuf -> tok = <fun> Cute, isn't it ? Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] unread_char function 2003-09-29 21:10 ` Pierre Weis @ 2003-09-29 22:42 ` Miles Egan 0 siblings, 0 replies; 4+ messages in thread From: Miles Egan @ 2003-09-29 22:42 UTC (permalink / raw) To: Pierre Weis; +Cc: Basile Starynkevitch, caml list [-- Attachment #1: Type: text/plain, Size: 1342 bytes --] On Mon, 2003-09-29 at 14:10, Pierre Weis wrote: > You may also consider scanf and the format %0c that gives you access > to the current character without incorporating it to the current token > (as Basile said, this is some form of lookahead, limited to 1 > character as is normally the case for streams). > > To give a more concrete example, here is an elementary scanner for > strings, numbers, chars, idents and single character symbols: the > scanneer just decides on the first character (after proper skipping of > spaces) what is the kind of token to read. > > let scan_tok sb = > Scanf.bscanf sb " %0c" (function > | '"' -> > Scanf.bscanf sb "%S" > (fun v -> String v) > | '0' .. '9' | '-' | '+' -> > Scanf.bscanf sb "%f" > (fun v -> Float v) > | '\'' -> > Scanf.bscanf sb "%C" > (fun v -> Char v) > | 'a' .. 'z' | 'A' .. 'Z' -> > Scanf.bscanf sb "%[a..zA..Z0..9]" > (fun v -> Ident v) > | c -> > Scanf.bscanf sb "%1c" > (fun v -> Symbol v));; > val scan_tok : Scanf.Scanning.scanbuf -> tok = <fun> I'm trying to write a function that seeks to an arbitrary string delimiter in an input stream. It's not immediately obvious to me how I'd do this with a parser but I'll poke around with it. -- Miles Egan <miles@caddr.com> [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-09-29 22:42 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-09-29 15:42 [Caml-list] unread_char function Miles Egan 2003-09-29 18:44 ` Basile Starynkevitch 2003-09-29 21:10 ` Pierre Weis 2003-09-29 22:42 ` Miles Egan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox