From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA10816; Tue, 30 Sep 2003 00:42:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA22218 for ; Tue, 30 Sep 2003 00:42:15 +0200 (MET DST) Received: from manly.caddr.com ([192.153.219.146]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8TMgDH12465; Tue, 30 Sep 2003 00:42:13 +0200 (MET DST) Received: from car (car.pixar.com [138.72.15.78]) by manly.caddr.com (Postfix) with ESMTP id 907DC20A08; Mon, 29 Sep 2003 15:43:05 -0700 (PDT) Subject: Re: [Caml-list] unread_char function From: Miles Egan To: Pierre Weis Cc: Basile Starynkevitch , caml list In-Reply-To: <200309292110.XAA16929@pauillac.inria.fr> References: <200309292110.XAA16929@pauillac.inria.fr> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-LUB6WucJG7DAwbIvzSZj" Message-Id: <1064875328.3355.1.camel@car> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Mon, 29 Sep 2003 15:42:09 -0700 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 char:01 egan:01 pierre:01 weis:01 scanf:01 basile:01 tok:99 scanf:01 bscanf:01 bscanf:01 char:01 val:01 tok:99 scanbuf:01 X-Attachments: type="application/pgp-signature" name="signature.asc" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --=-LUB6WucJG7DAwbIvzSZj Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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). >=20 > 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. >=20 > let scan_tok sb =3D > 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 =3D 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. --=20 Miles Egan --=-LUB6WucJG7DAwbIvzSZj Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQA/eLVAU4Jq/wH1PVERAr2UAKC6+ZasoJin2iTW51zMiImzwo0/TwCgjQ6A BoioYl1Q+8q3uWe72xTCfMU= =unQa -----END PGP SIGNATURE----- --=-LUB6WucJG7DAwbIvzSZj-- ------------------- 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