Antlr4 C#目标和生成文件的输出路径

编程入门 行业动态 更新时间:2024-10-16 16:42:48
本文介绍了Antlr4 C#目标和生成文件的输出路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个带有 Antlr3 语法文件的 C# 解决方案,我正在尝试升级到 Anltr4.事实证明,语法是最简单的部分(它变得更好了,而且体积缩小了三分之一!).生成解析器被证明是棘手的部分.

I have a C# solution with an Antlr3 grammar file, and I'm trying to upgrade to Anltr4. It turns out the grammar was the easy part (it became better, and one third the size!). Generating the parser turned out to be the tricky part.

在旧的解决方案中,当语法文件发生变化时,我只是运行 AntlrWorks 来更新词法分析器和解析器 .cs 文件.词法分析器和解析器与语法直接包含在同一个项目中,因此围绕解析器的框架可以直接使用它们.

In the old solution I merely ran AntlrWorks to update the lexer and parser .cs files when the grammar file changed. The lexer and parser were included directly in the same project as the grammar so the framework around the parser could make use of them directly.

对于 C# 的 Antlr4 目标,我注意到(至少默认情况下)生成的 Parser C# 类的输出路径位于中间目录中,例如对象\调试.这意味着我不能在同一个项目中直接使用解析器.如果我希望生成的源在我的 sln 中可用,我是否应该更改输出路径?我不想在我的 sln 中使用它吗?

With the Antlr4 targets for C# I noticed that (at least by default) the output path of the generated Parser C# classes is in the intermediate directory, e.g. obj\Debug. This means I can't use the parser directly in the same project. Am I supposed to change the output path if I want the generated source usable in my sln? Don't I want it in my sln?

我尝试为解析器生成创建一个单独的项目,即一个包含语法文件的项目.使用 Antlr4 目标构建此项目时,可以从需要解析器类的项目中引用生成的程序集.但是,如果此项目包含在解决方案中,我仍然无法在 Visual Studio 中获得任何智能感知,因为它的智能感知基于加载项目的源文件,因此它仍然不太可用.我让它正常工作的唯一方法是构建然后卸载解析器项目,并让其他项目将其作为程序集文件而不是项目引用.

I tried making a separate project for the parser generation, that is, a project containing only the grammar file. When this project is built using the Antlr4 targets, the resulting assembly can be referenced from projects needing the parser classes. However, if this project is included in the solution I still don't get any intellisense in visual studio since it bases its intellisense on source files for loaded projects, so it is still not quite usable. The only way I could get it working properly was to build then unload the parser project, and have other projects reference it as an assembly file rather than a project.

在查看 antlr-interest 列表后,我发现这个线程表明智能感知的问题可能是 Resharpers 的错误.如果是这种情况,那么我的问题是如何在我的解决方案中继续使用 Antlr4 和 Resharper?https://groups.google/forum/#!topic/antlr-discussion/QSuJXphaBDg

After looking on the antlr-interest list I found this thread indicating that the problem with intellisense may be Resharpers fault. If this is the case, then my question is rather how to keep using both Antlr4 and Resharper in my solution? https://groups.google/forum/#!topic/antlr-discussion/QSuJXphaBDg

推荐答案

您遇到了 ReSharper 的已知错误.ANTLR 3 和 ANTLR 4 C# 构建集成是可靠的,并且使用 Microsoft 与其他语言和代码生成任务一起使用的长期建立的模式.您的选择是:

You are encountering a known bug with ReSharper. The ANTLR 3 and ANTLR 4 C# build integration is reliable, and uses long-established patterns that Microsoft uses with other languages and code generation tasks. Your options are:

停止使用 ReSharper让 ReSharper 作者解决此功能缺乏支持的问题,或者修改 ANTLR 4 目标以解决 ReSharper 中的限制,这会在构建中引入其他问题,您可能无法接受这些问题.

选项 1 当然是最便宜的,并且最有可能为您的项目提供可靠的长期支持.

Option 1 is certainly the least expensive, and most likely to provide reliable long-term support for your projects.

这篇关于Antlr4 C#目标和生成文件的输出路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-20 07:21:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/980011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   目标   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!