From: Miles Egan <miles@caddr.com>
To: Pierre Weis <pierre.weis@inria.fr>
Cc: Basile Starynkevitch <basile.starynkevitch@inria.fr>,
caml list <caml-list@inria.fr>
Subject: Re: [Caml-list] unread_char function
Date: Mon, 29 Sep 2003 15:42:09 -0700 [thread overview]
Message-ID: <1064875328.3355.1.camel@car> (raw)
In-Reply-To: <200309292110.XAA16929@pauillac.inria.fr>
[-- 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 --]
prev parent reply other threads:[~2003-09-29 22:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-29 15:42 Miles Egan
2003-09-29 18:44 ` Basile Starynkevitch
2003-09-29 21:10 ` Pierre Weis
2003-09-29 22:42 ` Miles Egan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1064875328.3355.1.camel@car \
--to=miles@caddr.com \
--cc=basile.starynkevitch@inria.fr \
--cc=caml-list@inria.fr \
--cc=pierre.weis@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox