You are oversimplifying the problem.

I don't know if you have noticed it but perl can't tell where you failed to nest {} 
braces right.

All the block tags in TT end with [% END %] and they all allow nesting... 

[% BLOCK a %]blah
?? blah
[% FOREACH a=b %]blah
?? blah
[% FOREACH c=d %]blah
?? blah
[% END %] blah
?? blah
[% END % ] blah
?? 

Which ?? is the missing END tag?  It is IMPOSSIBLE to tell from either context or 
syntax in a programmatic way. Only something that understands the situational code 
logic can even hope to spot it. All lint can do is tell you it is unbalanced. If it 
finds an extra closing it can complain at the point it finds it, but it can't be sure 
about one missing till it hits the end of file...

--mark

> -----Original Message-----
> From: Matthew Pressly [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 06, 2002 3:53 PM
> To: Perrin Harkins
> Cc: [EMAIL PROTECTED]
> Subject: Re: [Templates] TT2 syntax checker or lint?
> 
> 
> At 03:22 PM 3/6/2002 -0500, you wrote:
> >>This is an *incredibly* hard thing to do.
> >
> >True.
> >
> >The original idea of having a "ttlint" is a really cool one 
> though.  I wonder if there's a way to just re-purpose the 
> parser somehow, or if this would need to be a separate one.  
> It could be much slower and simpler than the real TT parser, 
> if it's just looking for stuff like unclosed IF tags.
> >
> >- Perrin
> 
> 
> I could see reporting all errors being difficult, but I think 
> adding balanced tag checking would not be too difficult.  
> 
> I have not looked at all how the parsing is implemented for 
> TT2, but I think even a separate perl script that reads the 
> templates and checks for and reports unbalanced tags would 
> not be too difficult.  This is the case that I seem to spend 
> the most time debugging.  Even if the template parser was not 
> of any help in writing a ttlint, I was thinking it might be 
> possible to just convert the template into some form of 
> overly simplistic perl (basically perl for the control flow 
> and print statements or strings for everything else), then 
> just run it through perl -w -c and use perl's built in error 
> checking.  Use strict would probably have to be turned off to 
> avoid having to predeclare everything.  Comments could be 
> used to associate line numbers in perl with line numbers in 
> TT2.  I realize that TT2's parser in effect already does this 
> and much more, but in some sense, the ttlint might need to be 
> a little looser so that it could process the whole file into 
> perl without quitting, and it could afford to be looser 
> because it is doing only a static validation.  Some things 
> would be fatal to this type of lint, like [% without %], but 
> that could be checked and reported explicitly first in a 
> preprocessing step. Maybe I am oversimplifying the problem?
> 
> I.e. something like:
> [% FOREACH item = list %]
>    <input name="[% item.name %]" ...>
> [% END %]
> 
> could be turned into something like:
> # line 1
> foreach my $item (@list) {
>   print q[<input name="[% item.name %]">];
> #  line 3
> }
> 
> so that if the [% END %] was missing, the } would be missing in perl.
> 
> 
> Matthew Pressly
> 
> 
> _______________________________________________
> templates mailing list
> [EMAIL PROTECTED]
> http://www.template-toolkit.org/mailman/listinfo/templates
> 


Reply via email to