>>>>> "MTM" == Mike T Machenry <[EMAIL PROTECTED]> writes:

  MTM> It's always the first question a program asks. "Can I have foo?"
  MTM> "Why?" I just figured I wouldn't bore anyone with it unless I was
  MTM> asked since I'm fairly certain I need a Perl AST to do what I
  MTM> want to do. I have a series of small Perl code snippets that are
  MTM> evaled in a known context. I also write new ones. I want to
  MTM> perform many different static checks to these pieces of code that
  MTM> will reduce bugs in my code base. The checks involve:

  MTM> 1) Ensuring that the arguments to certain functions are always within a 
  MTM>    predetermined set of literals.
  MTM> 2) Listing the free variables of the code and checking them against my 
eval 
  MTM>    environment.
  MTM> 3) Ensuring keys accessed from the environments hash are not dynamically 
  MTM>    created and fall within my fixed set of keys.
  MTM> 3.5) Listing those hash keys that were accessed.
  MTM> 4) Ensuring that values assigned to certain variables are litteral 
strings 
  MTM>    of a fixed set.
  MTM> 5) Ensuring that functions call from the code are within my environment.

  MTM> In short, I'm writing a pour-man's type checker since writing an
  MTM> actual type checker for Perl is likely impossible. I can afford
  MTM> the restrictions I have put on the code though, so for what I
  MTM> need, it'll work just fine.

from what little i know about PPI, i think it can do that level of
parsing. you seem to want basic info and not a true parse tree.

and your reason seems ok but i would love to chat with you sometime on
what this library of code is doing and how to make it more checkable
before compiling. i can see several other ways to do this including
templating, code generation (which is a form of templating), closures
and possibly even basic objects. i would need to know much more about
the goals and such. but if you already have a decent investement in your
design, then try to use PPI to get the info you want parsed from the
code.

purl on irc has this factoid about it:

        rumour has it PPI is a perl syntax parser that is good enough to
        actually use, and is quite capable of handling most
        non-DamianWare :) or useful for automating perl golfing. or at
        http://www.perl.com/pub/a/2005/06/09/ppi.html or "100 percent
        round-trip safe, and it's been stress tested against the 38,000
        (non-Acme) modules in CPAN, handling all but 28 of the most
        broken and bizarre"

sounds like it will do the job for you.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to