vladb has asked for the wisdom of the Perl Monks concerning the following question:
My question is do you see any problem with the code? I'm sure some of you came across similar problems and might have some knowledge of possible pitfalls/hidden bugs. Please feel free to add/subtract from this code.. all suggestions are much appreciated ;-).# have to search a little differently for nest +ed tags # making sure that an ending tag belonging to # a nested opening tag is not processed as the + ending # tag for the current opening tag. # In case i sounded awkward, here's a little d +iagram: # # <cfif> <--- this tag # <cfif> <--- nested open tag # </cfif> <--- end tag for the nested open +tag # </cfif> <--- end tag for this tag (the on +e that has # to be picked up) # # Actual example: # @chunks = # . . . . . . # 5 "<cfif bool eq 1>\cJ\cI " <--- +chk_i, found_i # 6 "<cfif foo = bar>\cJ\cI\cI " # 7 "<cfif bar = foo>\cJ\cI\cI " # 8 "</cfif>\cJ\cI " # 9 "</cfif>\cJ\cI\cI \cJ\cI BOOL is true!\c +J" # 10 "<cfelse>\cJ\cIBOOL is false!\cJ" # 11 '</cfif> <--- +after: found_i my $opening_tag = $rules->{tag_start}[0] . $ta +g_name; my $nested = 0; # count of nested open tags fo +und. while ((($chunks[++$found_i] =~ m/^$closing_ta +g/) ? ($nested > 0 ? $nested-- : 0) : ($chunks[$found_i] =~ m/^$opening_ta +g/ ? ++$nested : 1)) && $found_i < @chunks) {}
| "There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(crazyinsomniac) Re: Template Parsing - Finding tag pairs.
by crazyinsomniac (Prior) on Dec 25, 2001 at 11:07 UTC | |
by vladb (Vicar) on Dec 25, 2001 at 11:52 UTC | |
|
Re: Template Parsing - Finding tag pairs.
by Juerd (Abbot) on Dec 25, 2001 at 23:20 UTC | |
by IlyaM (Parson) on Dec 25, 2001 at 23:59 UTC | |
by Juerd (Abbot) on Dec 26, 2001 at 00:14 UTC | |
by IlyaM (Parson) on Dec 26, 2001 at 00:17 UTC | |
by Juerd (Abbot) on Dec 26, 2001 at 00:26 UTC | |
| |
by vladb (Vicar) on Dec 26, 2001 at 00:47 UTC | |
|