From: Peng Yu on
Suppose I have some C++ code like the following, I want to match the
whole namespace x block.

namespace x
{
namespace y
{
....
}

}

The following webpage shows brace-matching for perl regex. But I don't
find the matchpairs module. (I'm using perl 5.10.1). Would you please
let me know if there is a way to match block of nested braces in perl?

http://dev.perl.org/perl6/rfc/145.html
From: Charlton Wilbur on
>>>>> "PY" == Peng Yu <pengyu.ut(a)gmail.com> writes:

PY> Would you please let me know if there is a way to match block of
PY> nested braces in perl?

Yes, there is. What did you find when you consulted the FAQ?

Charlton


--
Charlton Wilbur
cwilbur(a)chromatico.net
From: Peng Yu on
On Jun 13, 7:07 pm, Charlton Wilbur <cwil...(a)chromatico.net> wrote:
> >>>>> "PY" == Peng Yu <pengyu...(a)gmail.com> writes:
>
>     PY> Would you please let me know if there is a way to match block of
>     PY> nested braces in perl?
>
> Yes, there is.  What did you find when you consulted the FAQ?

http://faq.perl.org/perlfaq6.html#Can_I_use_Perl_regul

The example on this link is daunting to me. I have read perlre.

$re = qr{ ( # paren group 1
(full function)
foo
( # paren group 2
(parens)
\(
( # paren group 3
(contents of parens)
(?:
(?> [^()]+ ) # Non-parens without
backtracking
|
(?2) # Recurse to start
of paren group 2
)*
)
\)
)
)
}x;

I still don't understand it how it works. What doesn't "Recurse to
start of paren group 2"?

For my specific problem (C++ namespace), would you please show me how
to do it and explain it to me how it works? Thank you!
From: Charlton Wilbur on
>>>>> "PY" == Peng Yu <pengyu.ut(a)gmail.com> writes:

PY> The example on this link is daunting to me. I have read perlre.

PY> I still don't understand it how it works. What doesn't "Recurse
PY> to start of paren group 2"?

Do you understand what "recurse" means? Do you understand what "paren
group 2" means?

PY> For my specific problem (C++ namespace), would you please show
PY> me how to do it and explain it to me how it works? Thank you!

Frankly, no, because if I do, you'll ignore the explanation and ask
comp.lang.perl.misc the next time you have a problem to solve, and I'm
already tired of seeing you ask FAQs. You really have two options: you
can put in the work to understand what you're doing, or you can hire
someone, for money, who will write code to your specification.

Charlton


--
Charlton Wilbur
cwilbur(a)chromatico.net
From: Ben Morrow on

Quoth Peng Yu <pengyu.ut(a)gmail.com>:
> Suppose I have some C++ code like the following, I want to match the
> whole namespace x block.
>
> namespace x
> {
> namespace y
> {
> ....
> }
>
> }
>
> The following webpage shows brace-matching for perl regex. But I don't
> find the matchpairs module. (I'm using perl 5.10.1). Would you please
> let me know if there is a way to match block of nested braces in perl?
>
> http://dev.perl.org/perl6/rfc/145.html
^^^^^ ^^^
This was a speculative design document during the early part of the
development of Perl 6. None of these RFCs apply to Perl 5.

As far as balanced matching goes, check the FAQ. (Please do so *before*
posting in future.)

Ben