简体   繁体   English

我怎样才能得到从 Roslyn 中提取的 C# 解析器(语法树)

[英]How can I get just the C# parser (Syntax Tree) extracted from Roslyn

I'm trying to pull in the Roslyn source code to a Unity 3D video game that will have live C# editing in it.我正在尝试将 Roslyn 源代码引入到 Unity 3D 视频游戏中,该游戏将在其中进行实时 C# 编辑。 I'm wanting the Syntax Tree, to help with debugging, formatting and analysis, and was originally planning to roll my own parser for this purpose.我想要语法树,以帮助调试、格式化和分析,并且最初计划为此目的推出我自己的解析器。 But if I can extract Roslyn's syntax tree to execute in Unity, that would make things a lot easier.但是,如果我可以提取 Roslyn 的语法树以在 Unity 中执行,那将使事情变得容易得多。

However, I have probably put 12 hours of time into trying to reduce the Roslyn project down (see escapades here: https://codavore.blogspot.com/2019/11/c-parser-part-2.html ) and I haven't succeeded in reducing the project.但是,我可能花了 12 个小时的时间来尝试减少 Roslyn 项目(请参阅此处的转义: https : //codavore.blogspot.com/2019/11/c-parser-part-2.html )并且我还没有没有成功地减少项目。 Ie removing the VB parts affect the dual test cases for C#/VB, and removing one superfluous thing affects a dozen others.即删除 VB 部分会影响 C#/VB 的双重测试用例,删除一个多余的部分会影响其他十几个。

Anyone have advice for extracting out jut the C# Syntax Tree's source code?有人对提取 C# 语法树的源代码有什么建议吗?

I was originally hoping to pull in source code, but per @Jonathon Marolf's comments, I attempted to pull it in via nuget.我最初希望引入源代码,但根据 @Jonathon Marolf 的评论,我试图通过 nuget 引入它。 But Unity overwrites most of what nuget does, anytime I change the files, so that didn't work.但是 Unity 会覆盖 nuget 所做的大部分事情,无论何时我更改文件,因此这不起作用。 To get around this, I found and installed NuGet for Unity .为了解决这个问题,我找到并安装了NuGet for Unity Then ran the nuget "Install-Package Microsoft.CodeAnalysis.CSharp -Version 3.3.1".然后运行nuget“Install-Package Microsoft.CodeAnalysis.CSharp -Version 3.3.1”。

Of course this broke the project, because its designed for VS projects, not Unity.当然,这破坏了项目,因为它是为 VS 项目而不是 Unity 设计的。 I had to delete the duplicate DLLs, and also all the language support files.我不得不删除重复的 DLL,以及所有语言支持文件。 It still had an error with a couple analysis dlls that were unloaded when trying to run, but it was able to parse out part of the source code I passed it.它仍然有几个分析 dll 在尝试运行时被卸载的错误,但它能够解析出我传递给它的部分源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM