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

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

Re: Extending forward-list to include multi-letter tags


From: Thomas A. Russ
Subject: Re: Extending forward-list to include multi-letter tags
Date: 22 Oct 2007 13:53:10 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

gnuist006@gmail.com writes:

> I am sure this is a trivial problem for many of you, and it is one of
> those problems that is like a mathematical puzzle with definite
> solutions. I am interested in seeing multiple solutions to it.
> 
> Here is the problem:
> 
> The pair of functions forward-list and backward-list allow moving
> the cursor to the next matching paren, bracket or brace. So it
> works for characters like
> {[(  )]}
> 
> The main utility of this function is mainly due to the nesting that
> may be there, so a simple forward search wont take care of it.

Well, not exactly, but a fairly simple counting verison of forward
search works just fine.  The only fly in the ointment, which afflicts
the Emacs versions, BTW, is if you have the possibility of encountering
escape or comment contexts where you don't want the matching to happen.

This is particularly a problem for the backward movement verison, since
the forward verison can typically manage to do the parsing correctly.

But for a quick outline of what you want to do, this is the basic
algorithm:

  1.  Set open counter = 1
  2.  Search character by character.
  3.  If an open character is encountered increment open counter.
  4.  If a close character is encountered increment close counter.
  5.  If the open counter = close counter value, you are done.

> Here, I would like to find out how one can find matching multi
> letter tags.

It works the same way, except that there is more lookahead in the
matching function.  You might also want to consider something like a
Boyer-Moore search algorithm for the multi-tag case.  Or even some
other, syntax-aware parsing of the content.

-- 
Thomas A. Russ,  USC/Information Sciences Institute


reply via email to

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