Introducing Recursive-Regex

Recursive-Regex is the end result of a weekend of playing with the code I published on Thursday about adding named dispatch functions to CL-PPCRE regular expressions. I kept at it and I think that this approach might have some promise for building up a library of reusable regexp/matcher chunks. I also found that this made it somewhat easier to obtain results from the regular expression search because I get back a full parse tree rather than the bindings typically supplied by CL-PPCRE.

I have it somewhat documented, loadable and testable, with all my current tests passing. There is even a recursive regex csv parser defined in the default dispatch table (mostly as a simple, but practical proof of concept).

Comma-List: [\t ]*(?:(?<body>[^,]*)[\t ]*,)*[\t ]*(?<body>[^,]*)[\t ]*
CSV-Row: (?<comma-list>((?<double-quotes>)|[^\n,]*))(?:\n|$)
CSV-File: (?<csv-row>)*

Double quotes and body both go to custom dispatcher functions. Body defines where the body regex should be matched and what to use if no body is supplied.

I don’t really have long term plans for this project, but it scratched an intellectual itch I was experiencing. Perhaps it will be useful for someone down the road.

3 thoughts on “Introducing Recursive-Regex

  1. I have not use recursive patterns in perl (or much perl) but based on the description, it sounds like this is a slightly more general system, but accomplishes perhaps the same goals

    Some differences I see at a perusal:

    • In recursive-regex every recursion point has a name
    • Cut / Break out is not currently implemented in recursive-regex (though easily could be)
    • It is implemented in Common Lisp so I already have a good sexp parser there. That’s why I chose CSV for the example. Also a sexp parser is considerably harder. You have set me a goal, but I don’t think this system is currently robust enough to handle it. I will post about it again when I have a simple sexp parser example
  2. Pingback: Recursive-Regex Update | Russ’s Tech Blog

Leave a Reply

Your email address will not be published. Required fields are marked *