.Net库用于解析源代码文件?

时间:2022-02-12 11:40:42

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)?

有谁知道一个好的.NET库,它允许我解析源代码文件,但不仅仅是.NET源代码文件(如java,perl,ruby等)?

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.

有没有人遇到这样的事情?我在.NET中知道它是合理的可能,并且有一些库,但我需要将其抽象为更多类型的编程语言。

4 个解决方案

#1


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. 您可以选择一个包含大量现有语法的解析框架(如Antlr或像Irony这样的新语法)并使用它。这将提供最高保真度。

  3. If you could stick to just .NET languages, you could use the Common Compiler Infrastructure tools to read the data from a compiled file.
  4. 如果您只能使用.NET语言,则可以使用Common Compiler Infrastructure工具从已编译的文件中读取数据。

  5. You could do a heuristic based approach like the SyntaxHighlighter component uses.
  6. 您可以像SyntaxHighlighter组件一样使用基于启发式的方法。

  7. 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.
  8. 您可以捎带现有工具,这些工具提供可插入语法高亮文件,如VIM。您必须创建或找到理解这些文件的解析器。

#2


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

不是完整的答案,但您可以考虑这样做:使用代码模型发现代码

#3


Would Antlr meet your needs?

Antlr会满足您的需求吗?

#4


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.

用于解析源代码,构建相应的编译器数据结构(树等)的工具,让您导航/操作这些结构,并重新生成有效的源代码(包括注释!)是DMS软件重新设计工具包。

It has a full C# 4.0 front end.

它有一个完整的C#4.0前端。

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#).

它不提供从C#访问这些结构;相反,它为编码程序分析和转换提供了自己的环境,并且相对容易地提供了大量的支持(并且比在纯C#中更容易)。

#1


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. 您可以选择一个包含大量现有语法的解析框架(如Antlr或像Irony这样的新语法)并使用它。这将提供最高保真度。

  3. If you could stick to just .NET languages, you could use the Common Compiler Infrastructure tools to read the data from a compiled file.
  4. 如果您只能使用.NET语言,则可以使用Common Compiler Infrastructure工具从已编译的文件中读取数据。

  5. You could do a heuristic based approach like the SyntaxHighlighter component uses.
  6. 您可以像SyntaxHighlighter组件一样使用基于启发式的方法。

  7. 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.
  8. 您可以捎带现有工具,这些工具提供可插入语法高亮文件,如VIM。您必须创建或找到理解这些文件的解析器。

#2


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

不是完整的答案,但您可以考虑这样做:使用代码模型发现代码

#3


Would Antlr meet your needs?

Antlr会满足您的需求吗?

#4


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.

用于解析源代码,构建相应的编译器数据结构(树等)的工具,让您导航/操作这些结构,并重新生成有效的源代码(包括注释!)是DMS软件重新设计工具包。

It has a full C# 4.0 front end.

它有一个完整的C#4.0前端。

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#).

它不提供从C#访问这些结构;相反,它为编码程序分析和转换提供了自己的环境,并且相对容易地提供了大量的支持(并且比在纯C#中更容易)。