help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ANN] drx.el --- declarative dynamic regexps


From: Thorsten Jolitz
Subject: [ANN] drx.el --- declarative dynamic regexps
Date: Thu, 10 Apr 2014 19:43:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Hi List, 

I wrote a library ([[https://github.com/tj64/drx][drx.el]]) that allows
to write regexps in Emacs Lisp in a more declarative style and to
replace static regexp strings with function calls that calculate a
regexp dynamically at runtime.

Unfortunately I learned about rx.el only when I was almost done, but
anyway, maybe drx.el has a different approach and its use cases too.

Its main purpose is to abstract from hardcoded  "^", "$" and "\\*" in
regexps. Here are a few examples:

# basic usage
#+begin_src emacs-lisp
 (drx "foo" t nil t)
#+end_src

#+results:
: ^foo$

# org-mode version
#+begin_src emacs-lisp
 (drx " foo" t '(t "+") t)
#+end_src

#+results:
: ^\(\*+\) foo$

# css-mode version with # as star 
#+begin_src emacs-lisp
  (let ((drx-BOL "^/* ")
        (drx-EOL "*/$")
        (drx-STAR "#"))
    (drx " foo" t '(t "+") t))
#+end_src

#+results:
: ^/* \(#+\) foo*/$

Many more things are possible, the more than 80 ERT tests in drx.el give
many examples with expected output.

-- 
cheers,
Thorsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]