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

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

Re: multiline regex mode?


From: Perry Smith
Subject: Re: multiline regex mode?
Date: Sat, 25 Nov 2006 10:32:20 -0600

On Nov 25, 2006, at 7:14 AM, Peter Dyballa wrote:
Am 25.11.2006 um 04:01 schrieb Dieter Wilhelm:
So "{[^}]*}" stands for 'a region that starts with `{´ and has no `}´
until the final `}´ is hit; between both braces any number (starting
with 0) of any character except `}´ can appear.'

Thanks Peter for the hassle.  Maybe I expressed myself in a confusing
manner: The period and the character alternatives I understand.  What
I really wanted to know is where to look for a possibility of
searching for *balanced* brackets like { { } } because I'll need this
in my own Elisp stuff.  It's clear that there is some code in Emacs
for it (e. g. C-M-f etc.) but I have a hunch that there might be
something else out there.  Maybe a regexp extension in Perl or ...

I think you can't use one regular _expression_ for a variety of nested "*balanced* brackets like { { } }".

Correct.

For the curious: regular expressions create what is called a deterministic finite automata (DFA).  Also known as a state machine.  They can not "count" which is what you ask asking for.  A simple "reason" is because the count can be infinite (although that explanation leaves out much).

The next level up in language parsing theory is a push down automata (PDA).  This is, roughly speaking, a DFA coupled with a stack.  The stack is infinite.  So, it now has the power to count.

The easiest way to do a PDA in lisp is with recursive decent and a rather simple lisp function can call itself when it hits a second { and return when it hits a }.  When the last function returns, you have hit the matching } of the first {.

All that aside, emacs has code written to balance parens, braces, brackets, etc.  You can look at forward-sexp as a starting point.  And, in the case of emacs, it is pretty flexible.  By specifying syntax tables, you can tell it what characters match each other.  Look at modify-syntax-entry for that piece of the puzzle.

Hope this helps...

Perry Smith ( address@hidden )
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems



reply via email to

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