From: David Monniaux <David.Monniaux@ens-lyon.fr>
To: Caml-list <caml-list@inria.fr>
Subject: hacks using camlp4
Date: Wed, 26 Nov 1997 19:00:58 +0100 (MET) [thread overview]
Message-ID: <Pine.GSO.3.95.971126184733.28210A-100000@gerland> (raw)
[ J'ai voulu mettre en place des expressions regulieres avec une syntaxe
plus agreable et bien typees, en utilisant camlp4. J'ai quelques
resultats mais aussi quelques problemes... ]
Hi,
I lately checked the camlp4 preprocessor. I think this tool may have lots
of useful applications, since it allows especially custom syntaxes for the
input of certain kind of objects, in a more programmer-friendly fashion
than just inputting raw data structures into the source code.
This also lessens the pressure on putting library-dependent features into
the language itself, as was done for the lists, strings and more
stringently with the format strings for the Printf.*printf functions.
I thus tried to give a type-safe interface to regular expressions. My
small hack (available on request) adds a syntax to do matching on a
regular expression and return components in a friendly and type-safe way,
and also a replace function.
[example:
let x = "meuh je (suis) un [beau] chaton {suis}" =~ item
=> (String.uppercase)
/{item: ['(' '['] ['a'-'z']+ [']' ')']}/
in Printf.printf "%s\n" x;;
will uppercase the substrings enclosed in () or [].
]
To give Perl-like efficiency, I precompile regexps (let-bindings for
precompiled regexps are prepended to the output); that allows efficient
matching even in the middle of a loop. However, this precludes using some
variable parts in the regexps (I for now only allow constant regexps); the
ideal solution would be to compile the regexps at a step in the program
where all the involved values can be computed.
This alas involves some semantic analysis.
I therefore have three problems:
1. Precompiled expressions.
More generally, what would be needed would be some construction to
evaluate an expression as soon as it is possible.
2. It would be nice if regexp precompilation could be done at compile or
preprocessing time (I was thinking of marshalling the precompiled
regexp, but I fear some C-library private data structure inside the
regexp type).
3. The stupid emacs regexp syntax (my code is for now not really
working if you put ^ or ] in ranges).
The third point is only a matter of library, but the others deserve some
thinking, I should say...
next reply other threads:[~1997-11-26 18:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-11-26 18:00 David Monniaux [this message]
1997-11-27 19:45 ` Daniel de Rauglaudre
1997-11-30 9:59 ` Michel Mauny
1997-12-02 17:03 ` Thierry Bravier
1997-12-02 21:06 ` Daniel de Rauglaudre
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=Pine.GSO.3.95.971126184733.28210A-100000@gerland \
--to=david.monniaux@ens-lyon.fr \
--cc=caml-list@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