all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* regexp-opt for all kinds of strings
@ 2007-07-18 16:21 Nordlöw
  2007-07-19  1:58 ` David Hansen
  2007-07-20  3:04 ` Tim X
  0 siblings, 2 replies; 7+ messages in thread
From: Nordlöw @ 2007-07-18 16:21 UTC (permalink / raw)
  To: help-gnu-emacs

Hey there!

Why aren't all kinds of characters allowed in regexp-opt()? I am doing
syntax highlighting of operators in c-mode and would like regexp-opt
to work for lists such:
  '("+" "-" "*" "/" "++" "--")

Have I missed something. Or is the feature a TODO?


Thanks in advance,
Nordlöw

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

* regexp-opt for all kinds of strings
@ 2007-07-18 19:52 Nordlöw
  2007-07-18 20:19 ` Stefan Monnier
  2007-07-20  4:17 ` Tim X
  0 siblings, 2 replies; 7+ messages in thread
From: Nordlöw @ 2007-07-18 19:52 UTC (permalink / raw)
  To: help-gnu-emacs

Hey!

Is there a version of regexp-opt() that can take a list of regular
expression (regexps) as argument. If not, why?

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

* Re: regexp-opt for all kinds of strings
  2007-07-18 19:52 regexp-opt for all kinds of strings Nordlöw
@ 2007-07-18 20:19 ` Stefan Monnier
  2007-07-20  4:17 ` Tim X
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2007-07-18 20:19 UTC (permalink / raw)
  To: help-gnu-emacs

> Is there a version of regexp-opt() that can take a list of regular
> expression (regexps) as argument.

No.

> If not, why?

Because nobody wrote the code for it.


        Stefan

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

* Re: regexp-opt for all kinds of strings
  2007-07-18 16:21 Nordlöw
@ 2007-07-19  1:58 ` David Hansen
  2007-07-20  3:04 ` Tim X
  1 sibling, 0 replies; 7+ messages in thread
From: David Hansen @ 2007-07-19  1:58 UTC (permalink / raw)
  To: help-gnu-emacs

On Wed, 18 Jul 2007 09:21:34 -0700 Nordlöw wrote:

> Why aren't all kinds of characters allowed in regexp-opt()? I am doing
> syntax highlighting of operators in c-mode and would like regexp-opt
> to work for lists such:
>   '("+" "-" "*" "/" "++" "--")

What's wrong with

ELISP> (regexp-opt '("+" "-" "*" "/" "++" "--"))
"\\+\\+\\|--\\|[*+/-]"

?

BTW "[-+*/>!]" should do the job.

David

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

* Re: regexp-opt for all kinds of strings
  2007-07-18 16:21 Nordlöw
  2007-07-19  1:58 ` David Hansen
@ 2007-07-20  3:04 ` Tim X
  1 sibling, 0 replies; 7+ messages in thread
From: Tim X @ 2007-07-20  3:04 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw <per.nordlow@gmail.com> writes:

> Hey there!
>
> Why aren't all kinds of characters allowed in regexp-opt()? I am doing
> syntax highlighting of operators in c-mode and would like regexp-opt
> to work for lists such:
>   '("+" "-" "*" "/" "++" "--")
>
> Have I missed something. Or is the feature a TODO?
>
>

As far as I know, the restrictions you reference don't exist. However, it is
possible you are trying to use the wrong tool. In what way did you find it
didn't work? The problem could be with boundry situations i.e. only matches
' ++ ' and not the ++ in ++foo or foo++ etc.

The regexp-opt is really best applied when you have sets of distinct "words"
that you want to match. From your description, I suspect that what you want is
just a fairly simple regexp. (One restriction of regexp-opt is that you cannot
have regexps in the list). 

If you just want to match the operators like ++, * and - etc, I suspect you
would be better off with just a normal regexp. While regexp-opt is really handy
when you have quite long lists of words to match and is pretty good at
optimizing the resulting regexp, for simpler patterns, it really is overkill. 

Maybe if you explain exactly what you are trying to achieve people on this list
may be able to provide useful examples/suggestions.

regards,

Tim

-- 
tcross (at) rapttech dot com dot au

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

* Re: regexp-opt for all kinds of strings
  2007-07-18 19:52 regexp-opt for all kinds of strings Nordlöw
  2007-07-18 20:19 ` Stefan Monnier
@ 2007-07-20  4:17 ` Tim X
  2007-07-20  8:06   ` Nordlöw
  1 sibling, 1 reply; 7+ messages in thread
From: Tim X @ 2007-07-20  4:17 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw <per.nordlow@gmail.com> writes:

> Hey!
>
> Is there a version of regexp-opt() that can take a list of regular
> expression (regexps) as argument. If not, why?
>

No, I don't know of any that will do that. The problem I think is that parsing
a list which also includes regexp would make the optimisation process very
complex as you would have to parse the regexps and work out how to combine them
with the non-regexp elements to obtain a final optimised regexp. The parsing
would likely require a full implementation of the regexp engine.

regards,

Tim

-- 
tcross (at) rapttech dot com dot au

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

* Re: regexp-opt for all kinds of strings
  2007-07-20  4:17 ` Tim X
@ 2007-07-20  8:06   ` Nordlöw
  0 siblings, 0 replies; 7+ messages in thread
From: Nordlöw @ 2007-07-20  8:06 UTC (permalink / raw)
  To: help-gnu-emacs

Thanks!

I realize now that my question was a bit ill-formulated. My real
questions have anyway been answered.


Thanks very much everyone,

Nordlöw

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

end of thread, other threads:[~2007-07-20  8:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-18 19:52 regexp-opt for all kinds of strings Nordlöw
2007-07-18 20:19 ` Stefan Monnier
2007-07-20  4:17 ` Tim X
2007-07-20  8:06   ` Nordlöw
  -- strict thread matches above, loose matches on Subject: below --
2007-07-18 16:21 Nordlöw
2007-07-19  1:58 ` David Hansen
2007-07-20  3:04 ` Tim X

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.