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: | Virgile Prevosto <virgile.prevosto@g...> |
| Subject: | Re: [Caml-list] Question re: camlp4 parser |
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