[Python-Dev] Re: selfnanny.py / nanny architecture

gvwilson@nevex.com gvwilson@nevex.com
Sat, 4 Mar 2000 13:26:20 -0500 (EST)


> > Guido van Rossum wrote:
> > Before we all start writing nannies and checkers, how about a standard
> > API design first?  

> Moshe Zadka wrote:
> Here's a strawman API:
> There's a package called Nanny
> Every module in that package should have a function called check_ast.
> It's argument is an AST object, and it's output should be a list 
> of three-tuples: (line-number, error-message, None) or 
> (line-number, error-message, (column-begin, column-end)) (each tuple can
> be a different form). 

Greg Wilson wrote:

The SUIF (Stanford University Intermediate Format) group has been working
on an extensible compiler framework for about ten years now.  The
framework is based on an extensible AST spec; anyone can plug in a new
analysis or optimization algorithm by writing one or more modules that
read and write decorated ASTs. (See http://suif.stanford.edu for more
information.)

Based on their experience, I'd suggest that every nanny take an AST as an
argument, and add complaints in place as decorations to the nodes.  A
terminal nanny could then collect these and display them to the user. I
think this architecture will make it simpler to write meta-nannies.

I'd further suggest that the AST be something that can be manipulated
through DOM, since (a) it's designed for tree-crunching, (b) it's already
documented reasonably well, (c) it'll save us re-inventing a wheel, and
(d) generating human-readable output in a variety of customizable formats
ought to be simple (well, simpler than the alternatives).

Greg