Browse thread
Question re: camlp4 parser
-
Paul Snively
-
Stephane Glondu
-
Paul Snively
- Stephane Glondu
- Virgile Prevosto
-
Paul Snively
-
Stephane Glondu
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Stephane Glondu <Stephane.Glondu@c...> |
| Subject: | Re: [Caml-list] Question re: camlp4 parser |
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.