[cl-ppcre-devel] [PATCH] Patches to mix parse trees and regex string.

Frédéric Jolliton cl-ppcre-devel at frederic.jolliton.com
Sat Jul 1 13:57:26 UTC 2006


Here is 2 patches (attached, if mailman doesn't drop them) for
CL-PPCRE for mixing parse trees and regex strings.

The first patch add a (?.<name>) syntax, where <name> designate a
keyword, and is case sensitive. The ?. was chosen to match the idea of
the #. reader macro. It includes the synonym parse tree from the
corresponding keyword while the regex is parsed.

The second patch add the (:REGEX <regex>) construct to use regex
string into parse tree. It's the opposite idea of the former patch.

The rationale is that sometimes it's preferable to use regex strings
(for compactness), while sometimes it's better to use parse tree (when
programmatically computed), but to my knowledge it was impossible to
mix them easily.

I hope that these patches are not too "hackish". In particular, the
reference to a synonym must be a keyword, it's not possible to specify
symbols in other packages. Also, since cl-ppcre use symbol property,
it's worst to use keywords (unless one take cares to avoid name
clashes.) I'm not sure how to fix that.

These patches are more to describe what I've in mind rather than
providing production quality patches.

What do you think about these suggestions ?

Examples of use:

-=-=-
CL> (define-parse-tree-synonym :foo
       (:sequence #\a (:greedy-repetition 1 3 (:alternation #\b #\c))))
CL> (scan-to-strings "b(ar(?.FOO))a" "baracca")
"baracca"
#("aracc")
-=-=-

Mixing the other way:

-=-=-
CL> (scan-to-strings '(:sequence "b"
                        (:register (:sequence "ar"
                                      (:regex "a(?:b|c){1,3}")))
                        "a")
                     "baracca")
"baracca"
#("aracc")
CL> 
-=-=-

-------------- next part --------------
A non-text attachment was scrubbed...
Name: synonym-reference.patch
Type: text/x-patch
Size: 2911 bytes
Desc: [PATCH 1/2] Add a syntax (?.<name>) to reference a tree	synonym.
URL: <https://mailman.common-lisp.net/pipermail/cl-ppcre-devel/attachments/20060701/6d51aca0/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: regex-tree.patch
Type: text/x-patch
Size: 719 bytes
Desc: [PATCH 2/2] Add a (:REGEX <regex>) construct to use	regex string into parse tree.
URL: <https://mailman.common-lisp.net/pipermail/cl-ppcre-devel/attachments/20060701/6d51aca0/attachment-0001.bin>
-------------- next part --------------

-- 
Fr?d?ric Jolliton


More information about the Cl-ppcre-devel mailing list