Convert string regexp to rx notation
xr-1.13.tar, 2019-Aug-04, 90.0 KiB
Home page
Browse ELPA's repository
CGit or Gitweb

To install this package, run in Emacs:

M-x package-install RET xr RET

Full description

#+TITLE: xr.el

XR converts Emacs regular expressions to the structured rx form, thus
being an inverse of ~rx~. It can also find mistakes and questionable
constructs inside regexp strings.

It can be useful for:
- Migrating existing code to rx form
- Understanding what a regexp string really means
- Finding errors in regexp strings

It can also parse and find mistakes in skip-sets, the regexp-like
arguments to ~skip-chars-forward~ and ~skip-chars-backward~.

The xr package can be used interactively or by other code as a library.

* Example

: (xr-pp "\\`\\(?:[^^]\\|\\^\\(?: \\*\\|\\[\\)\\)")


: (seq bos 
:      (or (not (any "^"))
:          (seq "^"
:               (or " *" "["))))

* Installation

From [[][GNU ELPA]]:

: M-x package-install RET xr RET

* Interface

Functions parsing regexp strings:

| ~xr~      | convert regexp to rx                  |
| ~xr-pp~   | convert regexp to rx and pretty-print |
| ~xr-lint~ | find mistakes in regexp               |

Functions parsing skip sets:

| ~xr-skip-set~      | convert skip-set to rx                  |
| ~xr-skip-set-pp~   | convert skip-set to rx and pretty-print |
| ~xr-skip-set-lint~ | find mistakes in skip-set               |


| ~xr-pp-rx-to-str~ | pretty-print rx expression to string |

* See also

The [[][relint]] package uses xr to find regexp mistakes in elisp code.

The [[][lex]] package, a lexical analyser generator, provides the
~lex-parse-re~ function which translates regexps to rx, but does not
attempt to handle all the edge cases of Elisp's regexp syntax or
pretty-print the result.

The [[][pcre2el]] package, a regexp syntax converter and interactive regexp
explainer, can also be used for translating regexps to rx. However, xr
is more accurate for this purpose.

Old versions

xr-1.12.tar2019-May-2680.0 KiB
xr-1.11.tar2019-Apr-1370.0 KiB
xr-1.10.tar2019-Apr-0170.0 KiB
xr-1.9.tar2019-Mar-2170.0 KiB
xr-1.7.tar2019-Mar-1760.0 KiB
xr-1.6.tar2019-Mar-1550.0 KiB
xr-1.5.tar2019-Mar-0250.0 KiB
xr-1.4.tar2019-Mar-0150.0 KiB
xr-1.3.tar2019-Feb-2540.0 KiB
xr-1.2.tar2019-Feb-2040.0 KiB
xr-1.1.tar2019-Feb-1340.0 KiB
xr-1.0.el2019-Feb-0527.7 KiB


Version 1.13:
- More robust pretty-printing, especially for characters
- Generate (category CHAR) for unknown categories
Version 1.12:
- Warn about branch subsumption, like [AB]\|A
Version 1.11:
- Warn about repetition of empty-matching expressions
- Detect `-' not first or last in char alternatives or skip-sets
- Stronger ad-hoc [...] check in skip-sets
Version 1.10:
- Warn about [[:class:]] in skip-sets
- Warn about two-character ranges like [*-+] in regexps
Version 1.9:
- Don't complain about [z-a] and [^z-a] specifically
- Improved skip set checks
Version 1.8:
- Improved skip set checks
Version 1.7:
- Parse skip-sets, adding `xr-skip-set', `xr-skip-set-pp' and
- Ad-hoc check for misplaced `]' in regexps
Version 1.6:
- Detect duplicated branches like A\|A
Version 1.5:
- Add dialect option to `xr' and `xr-pp'
- Negative empty sets, [^z-a], now become `anything'
Version 1.4:
- Detect overlap in character alternatives
Version 1.3:
- Improved xr-lint warnings
Version 1.2:
- `xr-lint' added