Gnus development mailing list
 help / color / mirror / Atom feed
* Regular expression converter.
@ 2003-11-09 19:45 Lloyd Zusman
  2003-11-09 19:58 ` Jesper Harder
  2003-11-10  0:23 ` Lloyd Zusman
  0 siblings, 2 replies; 4+ messages in thread
From: Lloyd Zusman @ 2003-11-09 19:45 UTC (permalink / raw)


Before I re-invent the wheel ...

Has anyone here written or obtained an elisp function or macro that will
convert perl-like regular expressions into Emacs regexp's?

I know this isn't strictly a Gnus question, but I have a feeling that
someone here might already be using something like this.

As an example, this proposed function/macro would convert the expression
marked as "Perl" to the one marked "Emacs" (note that I'm writing these
as if they would appear inside of an Elisp string, and therefore, the
backslashes are all doubled):

  Perl:   ^(.+?\\.)+(com|net|org)$
  Emacs:  ^\\(.+?\\.\\)+\\(com\\|net\\|org\\)$

If the input contains any perl-isms that can't be converted to an
appropriate Emacs regexp construct, I don't mind if this function fails.
My main goal is to use a regular expression syntax with fewer
backslashes in my elisp code, in order to aid readablility and speed up
debugging.

Thanks in advance.

-- 
 Lloyd Zusman
 ljz@asfast.com



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Regular expression converter.
  2003-11-09 19:45 Regular expression converter Lloyd Zusman
@ 2003-11-09 19:58 ` Jesper Harder
  2003-11-09 22:56   ` Lloyd Zusman
  2003-11-10  0:23 ` Lloyd Zusman
  1 sibling, 1 reply; 4+ messages in thread
From: Jesper Harder @ 2003-11-09 19:58 UTC (permalink / raw)


Lloyd Zusman <ljz@asfast.com> writes:

> My main goal is to use a regular expression syntax with fewer
> backslashes in my elisp code, in order to aid readablility and speed
> up debugging.

Are you aware of rx.el?  IMHO, this provides a much more readable and
nicer syntax than Perl regexps.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Regular expression converter.
  2003-11-09 19:58 ` Jesper Harder
@ 2003-11-09 22:56   ` Lloyd Zusman
  0 siblings, 0 replies; 4+ messages in thread
From: Lloyd Zusman @ 2003-11-09 22:56 UTC (permalink / raw)


Jesper Harder <harder@ifa.au.dk> writes:

> Lloyd Zusman <ljz@asfast.com> writes:
>
>> My main goal is to use a regular expression syntax with fewer
>> backslashes in my elisp code, in order to aid readablility and speed
>> up debugging.
>
> Are you aware of rx.el?  IMHO, this provides a much more readable and
> nicer syntax than Perl regexps.

Thank you.  I wasn't aware of rx.el, and I have looked into it.  It
indeed provides a more readable syntax, and it seems like a very
useful package.

However, given my own idiosyncratic tastes, I prefer regular expression
syntax, and I like the flavor that does not backslash parentheses,
braces, vertical bars, etc.

Therefore, I'm still looking for a converter.

-- 
 Lloyd Zusman
 ljz@asfast.com



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Regular expression converter.
  2003-11-09 19:45 Regular expression converter Lloyd Zusman
  2003-11-09 19:58 ` Jesper Harder
@ 2003-11-10  0:23 ` Lloyd Zusman
  1 sibling, 0 replies; 4+ messages in thread
From: Lloyd Zusman @ 2003-11-10  0:23 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1661 bytes --]

Lloyd Zusman <ljz@asfast.com> writes:

> [ ... ]
>
> As an example, this proposed function/macro would convert the expression
> marked as "Perl" to the one marked "Emacs" (note that I'm writing these
> as if they would appear inside of an Elisp string, and therefore, the
> backslashes are all doubled):
>
>   Perl:   ^(.+?\\.)+(com|net|org)$
>   Emacs:  ^\\(.+?\\.\\)+\\(com\\|net\\|org\\)$
>
> [ ... ]

Well, I found something.  In case anyone is interested, I'm enclosing
it.

It's something that was originally called "rx.el", and it implements
some functions and macros that permit a less-backslash-laden regular
expression syntax.  It's by Will Mengarini <seldon@eskimo.com> and it
was written in 1998/1999.

Because its name conflicts with the current "rx.el", I have renamed it
to "xr.el" (with the package name being "xr" instead of "rx").

It implements the syntax I want, with the small exception being that it
uses the backtick (`) instead of the backslash (\) as its escape
character.  To me, that's a small price to pay for more readability.

The xr syntax for the regular expression above would be this:

  ^(.+?`.)+(com|net|org)$

It also implements a few functions that correspond to standard elisp
functions, but which use this alternate regexp syntax:

  xr=                  corresponds to `string-match'
  xr@                  corresponds to `looking-at'
  xr-search-forward    corresponds to `re-search-forward'
  xr-search-backward   corresponds to `re-search-backward'
  xr-query-replace     corresponds to `query-replace-regexp'


I've already put this package into much of my commonly used elisp code,
and it is working very nicely.



[-- Attachment #2: xr.el --]
[-- Type: application/emacs-lisp, Size: 17105 bytes --]

[-- Attachment #3: Type: text/plain, Size: 36 bytes --]



-- 
 Lloyd Zusman
 ljz@asfast.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-11-10  0:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-09 19:45 Regular expression converter Lloyd Zusman
2003-11-09 19:58 ` Jesper Harder
2003-11-09 22:56   ` Lloyd Zusman
2003-11-10  0:23 ` Lloyd Zusman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).