Source of parsers for programming languages?
- by Arkaaito
I'm dusting off an old project of mine which calculates a number of simple metrics about large software projects.  One of the metrics is the length of files/classes/methods.  Currently my code "guesses" where class/method boundaries are based on a very crude algorithm (traverse the file, maintaining a "current depth" and adjusting it whenever you encounter unquoted brackets; when you return to the level a class or method began on, consider it exited).  However, there are many problems with this procedure, and a "simple" way of detecting when your depth has changed is not always effective.
To make this give accurate results, I need to use the canonical way (in each language) of detecting function definitions, class definitions and depth changes.  This amounts to writing a simple parser to generate parse trees containing at least these elements for every language I want my project to be applicable to.
Obviously parsers have been written for all these languages before, so it seems like I shouldn't have to duplicate that effort (even though writing parsers is fun).  Is there some open-source project which collects ready-to-use parser libraries for a bunch of source languages?  Or should I just be using ANTLR to make my own from scratch?  (Note: I'd be delighted to port the project to another language to make use of a great existing resource, so if you know of one, it doesn't matter what language it's written in.)