in reply to Re{4): Template Parsing - Finding tag pairs.
in thread Template Parsing - Finding tag pairs.

Precisely to the point IlyaM ;-). It all boils down to parsing a CFML code like this:
<cfset var = "foobar"> <cfset bool = "true"> <cfif bool eq "true"> print something here if bool is true. <cfelse> <cfif var eq "foobar"> foobar... Will dump query: <cfquery name="foobar_query"> #foo#, #bar# </cfquery> <cfoutput>foobar = #foobar#</cfoutput> </cfif> </cfif>
This has nothing to do with HTML and therefore, using HTML::Parser(s) is either an overkill or plain useless in my case. I've posted a node in meditations explaining my design behind the module (ColdFusion parser). Read more here.

"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith

Replies are listed 'Best First'.
Re: Re: Re{4): Template Parsing - Finding tag pairs.
by Juerd (Abbot) on Dec 26, 2001 at 01:07 UTC
    with
    @stack = ( ['cfif', 'bool eq "true"'], ['cfelse'] );
    the subs could start with something like
    sub start { return if $stack[-1][0] eq 'cfif' and $tag ne 'cfelse' and not istrue +($stack[-1][1]); return if $stack[-1][0] eq 'cfelse' and istrue($stack[-2][1]); } sub end { return if $stack[-1][0] eq 'cfif' and $tag ne 'cfif' and not istrue(. +..); return if $stack[-1][0] eq 'cfelse' and istrue(...); } sub text { something like what i used in start() }
    This piece of pseudo-code doesn't handle nested cfif's, but nothing is impossible. Maybe the bool eq "true" syntax is too hard for HTML::Parser, but nesting and ignoring will of course be up to you, just like when you use your own parser.

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$