caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stephane Glondu <Stephane.Glondu@crans.org>
To: caml-list@yquem.inria.fr
Cc: Paul Snively <psnively@mac.com>
Subject: Re: [Caml-list] Question re: camlp4 parser
Date: Tue, 26 Jul 2005 10:05:20 -0700	[thread overview]
Message-ID: <200507261005.20779.Stephane.Glondu@crans.org> (raw)
In-Reply-To: <0C774C67-0FD2-49F3-9293-B81BB3A0991E@mac.com>

On Tuesday 26 July 2005 09:43, Paul Snively wrote:
> 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 '='.

I don't know whether there is a way to do this directly. You can split your 
range so that it avoids '=' and '[', or do something like this:

let printable s =
  let buf = Buffer.create 100 in
  let rec aux = parser
      [< '  ('=' | '[') >] -> Buffer.contents buf
    | [< '' '..'~' as c; x = (Buffer.add_char buf c; aux) >] -> x
    | [< >] -> Buffer.contents buf
  in aux s ;;

printable (Stream.of_string "path=/usr/src") ;;
--> - : string = "path"

Bear in mind that the '=' or '?' will be discarded by the parser. If you 
don't want so, you can use Stream.peek (but it's much more annoying).


-- 
Stephane Glondu.


  reply	other threads:[~2005-07-26 17:05 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 [this message]
2005-07-27  7:04     ` Virgile Prevosto
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=200507261005.20779.Stephane.Glondu@crans.org \
    --to=stephane.glondu@crans.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=psnively@mac.com \
    /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;
as well as URLs for NNTP newsgroup(s).