如何创建一种新语言以在 Visual Studio 中使用 [英] How to create a new language for use in Visual Studio
问题描述
我想编写一种新的模板语言,并且希望 Visual Studio 能够支持"它.我需要知道的是:
I want to write a new templating language, and I want Visual Studio to "support" it. What I need to know is:
- 如何解析我的新语言?
给定我的新模板语言中的一些代码,我如何将其翻译成 HTML?现在我正在使用正则表达式来逐个解析它,但我认为这不会很好地扩展,因为语言变得更加复杂,并且没有错误检查.我听说过 ANTLR 但从未使用过它.这会是这项工作的正确工具,还是有更简单的方法?理想情况下,我想像其他语言一样将任何语法错误发送到错误窗口,并提供尽可能多的信息(行号、错误类型). - 如何为 Visual Studio 创建新的文件类型?
- 我如何获得语法高亮?
我可以使用我在第 1 步中创建的同一个解析器,还是完全不同的东西? - 我如何获得智能感知?
我更喜欢用 C# 编写解析器.
I'd prefer to write my parser in C#.
推荐答案
我想看看另一种语言,它已经完成了与 Visual Studio 的集成工作.一个很好的例子是 Boo.语言和 Visual Studio 集成是开源的.因此,您可以确切了解他们必须执行的操作.
I would take a look at another language that has already done the legwork of integrating with Visual Studio. A great example is Boo. The language and Visual Studio integration are open source. So you can take a look at exactly what they had to do.
- Boo 语言:https://github.com/boo/boo-lang
- VS2010 的 Boo 语法高亮(VSX 插件):http://vs2010boo.codeplex.com/一个>
- Boo Language Studio(VS2008 的语法高亮):http://boolangstudio.codeplex.com/
VS2010 的 Boo Syntax Highlighting 在其主页上包含一些推荐链接,我将复制这些链接以供参考:
The Boo Syntax Highlighting for VS2010 includes some recommended links on its homepage, which I'll copy for easy reference:
- 关于 VS 2010 中的分类"(语法高亮)的好文章:http://dotneteers.net/blogs/divedeeper/archive/2008/11/04/LearnVSXNowPart38.aspx
- VSX 插件示例:http://blogs.msdn.com/vsxteam/archive/2009/06/17/new-editor-samples-for-visual-studio-2010-beta-1.aspx
这篇关于如何创建一种新语言以在 Visual Studio 中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!