views:

301

answers:

4

Does anyone know of a good .NET library that allows me to parse source code files, but not only .NET source code files (like java, perl, ruby, etc)?

I need programmatic access to the contents of various source code files (e.g. class/method /parameter names, types, etc.).

Has anyone come across something like this? I know within .NET it is reasonably possible and there are some libraries out there, but I need that to be abstracted to more types of programming languages.

A: 

Not a full answer, but you might consider looking at this: Discovering Code with the Code Model

NoahD
A: 

Would Antlr meet your needs?

Onorio Catenacci
Well Antlr does seem nice, but like a whole new world to explore / learn and get used to. I am more or less looking for a 'finished' product tailored for specific languages (e.g. something like http://www.metaspec.net for c#, but also for other languages)...
Jörg B.
+1  A: 

A few options:

  1. You could pick a parsing framework that has a lot of existing grammars (like Antlr or newer ones like Irony) and use that. This will offer the most fidelity.
  2. If you could stick to just .NET languages, you could use the Common Compiler Infrastructure tools to read the data from a compiled file.
  3. You could do a heuristic based approach like the SyntaxHighlighter component uses.
  4. You could piggy-back off existing tools that offer pluggable syntax highlighting files like VIM. You'd have to create or find a parser that understood those files though.
Jeff Moser
Irony looks way more comfortable to me.. gonna go with that for a deeper evaluation.. thanks Jeff!
Jörg B.
A: 

A tool designed to parse source code, build corresponding compiler data structures (trees, etc.), let you navigate/manipulate those structures, and regenerate valid source code (including comments!) is the DMS Software Reengineering Toolkit.

It has a full C# 4.0 front end.

It doesn't provide access to those structures from C#; rather, it provides its own environment for coding program analysis and transformations, with a huge amount of support for doing this relatively easily (and considerably easier than doing in pure C#).

Ira Baxter