I have written a string processing library for Common Lisp,
which I call "Chio" (with the "ch" pronounced softly, as in
"char"). It handles matching using regular expressions,
substitution, and splitting of strings in a thoroughly
Lisp-like way.
I have tested Chio only in MCL, but encourage users of
other platforms to give it a try and report their
experiences.
You can download the program at the web site
www.toiling-in-obscurity.net/chio/
where you will also find more than 80 examples demonstrating
the capabilities of Chio and a document, "Chio: a String
Processing Library for Common Lisp", describing Chio in detail.
Features:
Simple string searches are described by function objects
called "simple-tests".
A library of routines that perform algebraic
operations on simple-tests, producing new ones from old
in various ways.
More complicated search descriptions are encapsulated in
structures called "binding-trees" that also specify bindings
to capture search results. These are compiled into
"compiled-binding-trees" and this compilation, being under
the user's control, can be held outside of iterative loops,
thereby speeding processing and conserving resources.
Chio's "simple-test-reader" is a Lisp read-time macro that
expands a regular expression into Lisp code that evaluates
to a simple-test. Viewing output of the Lisp reader thus
offers instant feedback regarding the action of a regular
expression.
Though regular expressions offer convenience, their use
is optional because the user is always free to write code instead.
This means that the particular regular expression syntax
that Chio offers does in no way limit the capabilities of
Chio or dictate what a programmer is allowed to do. Indeed,
the simple-test-reader is an independent module of Chio; a
user could theoretically substitute another reader to
achieve any desired syntax, or not use regular expressions
at all and still use the rest of the Chio library.
Three macros: with-test-binds, with-test-format, and
with-test-split, perform matching, substitution, and
splitting operations on strings. The behavior of these
macros is highly flexible, governed by numerous keyword
options.
Because it is built on top of Lisp, Chio inherits all of
the power of that language. It can therefore handle complex
tasks easily that might be awkward in more rigid languages.
I am releasing Chio's code under the Lisp GNU Lesser General
Public License (http://opensource.franz.com/preamble.html).
Jonathan Spingarn
email: spingarn at toiling-in-obscurity dot net
site: www.toiling-in-obscurity.net/chio/