#!/usr/bin/perl $cparens = qr/ (?<intern> \< (?: [^<>]++ | (?$+{intern}) )*+ \> ) /x; $ks="BinaryNode<OpAdd1<OpAdd2>,OpMulAdd2<OpMulAdd>>"; if ($ks =~ m/ ([^<>]++) \<(?'part1'[^<>]++(?:$cparens)?) \,(?'part2'[^<>]++(?:$cparens)?) \> /x) { print "ok\n"; } print "p1 $+{part1}\n"; print "p2 $+{part2}\n";
This matches as supposed and prints the part1 and part2 of the toplevel template:
p1 OpAdd1<OpAdd2>
p2 OpMulAdd2<OpMulAdd>
But, when I add one more level of recursion, like adding to one of the parts:
p1
p2
it doesn't match anymore!
I don't follow this logic. Does anybody know why this behaviour is shown?
Frank
In reply to recursive pattern
by Anonymous Monk
For:
Use:
& & < < > > [ [ ] ]