in reply to Re{4): Template Parsing - Finding tag pairs.
in thread Template Parsing - Finding tag pairs.
---# this code is missing a lot. don't expect it to work :) { my @stack; sub start { push @stack, $tag; } sub end { if ($tag eq 'cfif' and $stack[-1] eq 'cfelse'){ pop @stack; } die "Invalid code" if pop(@stack) ne $tag; } sub text { # use @stack to determine where we are... } } my $parser = HTML::Parser->new(start_h => [\&start, 'tagname'], end_h => [\&end, 'tagname'], text => [\&text, 'text'], ); $parser->report_tags(qw/cfif cfelse cfend/); $parser->parse($cfml);
<body><cfif>foo<cfelse><b>bar</b></cfif></body> ==> text '<body>'; start 'cfif'; text 'foo'; start 'cfelse'; text '<b>bar</b>'; end 'cfif';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re{6): Template Parsing - Finding tag pairs.
by IlyaM (Parson) on Dec 26, 2001 at 00:39 UTC | |
by Juerd (Abbot) on Dec 26, 2001 at 00:45 UTC | |
by IlyaM (Parson) on Dec 26, 2001 at 02:30 UTC |