regex-dsl

https://github.com/alk/elisp-regex-dsl.git

git clone 'git://github.com/alk/elisp-regex-dsl.git'
23

Tired of deciphering/writing emacs regexps like that one ? (it's from ruby-mode) “\(^\|[^:]\)\(:\([-+~]@?\|[/%&|^`]\|\\?\|<\(<\|⇒?\)?\|>[>=]?\|===?\|=~\|\[\]=?\|\(\w\|\)+\([!?=]\|\b\)\|#{[^}\n\\]\(\\.[^}\n\\]\)}\)\)”

Then regex-dsl is for you. It allows you to write regular expressions in S-exps. Like this: (this is correct expression for js regexp literal from espresso.el)

(redsl-to-regexp `(concat (char-set “=(,:”) (* (or (whitespace) “\n”)) (cap-group /) (+ (or (neg-char-set “\/”) (concat “\” (anychar)))) (cap-group /)))

which is readable (and writable) version of: “[=(,:]\(?:\s-\|\n\)*\(/\)\(?:[^\/]\|\\.\)+\(/\)”

Obviously, the problem is double escaping of '' which needs to be escaped for regexp and for elisp string. Even single level of escaping can be confusing, but two levels is simply crazy.

Main function of this package is REDSL-TO-REGEXP which takes list and converts it to regular expression string. The following forms are understood:

and others. See source code for more details.

Precedence of regexp expressions are taken into account so you don't need to worry about placing extra braces.

Backward translator (from regexp string to sexp) is missing. If you have some free time, please write one.