From: Virgile Prevosto <virgile.prevosto@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Question re: camlp4 parser
Date: Wed, 27 Jul 2005 09:04:07 +0200 [thread overview]
Message-ID: <2787337705072700045a275ce6@mail.gmail.com> (raw)
In-Reply-To: <0C774C67-0FD2-49F3-9293-B81BB3A0991E@mac.com>
2005/7/26, Paul Snively <psnively@mac.com>:
> One hopefully final question: is there a convenient shorthand for
> saying something like "all printable characters except '=' or '['?" I
> assume not--that is, we have ranges (' '..'~') or we have variants
> ('A' | 'B' | 'C'...) and that's it. I'm somewhat spoiled, I think, by
> Spirit in C++, and its notion of "character sets" and operations on
> them, so I can say, e.g. "print_p - '='" that that will match all
> printable characters other than '='.
>
As any other pattern, stream patterns can be refined with a 'when' condition:
let printable s =
let buf = Buffer.create 100 in
let rec aux = parser
| [< '' '..'~' as c when c <> '=' && c <> '[';
x = (Buffer.add_char buf c; aux) >] -> x
| [< >] -> Buffer.contents buf
in aux s ;;
should do the trick. It might not be that convenient for a more
complex set of excluded characters, but it is possible to write a char
-> bool test outside of the stream parser.
--
E tutto per oggi, a la prossima volta
Virgile
next prev parent reply other threads:[~2005-07-27 7:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-26 0:11 Paul Snively
2005-07-26 1:17 ` [Caml-list] " Stephane Glondu
2005-07-26 16:43 ` Paul Snively
2005-07-26 17:05 ` Stephane Glondu
2005-07-27 7:04 ` Virgile Prevosto [this message]
2005-07-28 1:27 ` Paul Snively
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=2787337705072700045a275ce6@mail.gmail.com \
--to=virgile.prevosto@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=virgile.prevosto@m4x.org \
/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