Monday, February 13, 2012

pattern matching with regexps

This is just a reminder to myself to think about extending pattern matching to regular expressions on strings.  It'd be a great feature, though with the famous caveat about regular expressions.  [I have a problem.  I think I can solve it with regular expressions.  Now I have two problems.]

(define sample
  "(?P<x>[0-9]+)+(?P<y>[0-9]+)" -> (+ (string->int x) (string->int y))
  "[^x]+(?P<nx>x+)[^x]+" -> (string-length nx)

I still remember looking through the ejabberd source code, trying to find their xml parser.  When it finally dawned on me that it was automagically hidden in the pattern matching, I was impressed.