简体   繁体   English

ANTLR语法在Visual Studio中突出显示DSL

[英]ANTLR Syntax Highlighting DSL in Visual Studio

I have an ANTLR grammar that defines a DSL (domain specific language). 我有一个定义DSL(特定于域的语言)的ANTLR语法。 This grammar is relatively simple. 这个语法相对简单。 It is parsing the language and outputting C code to create a very basic translator. 它正在解析语言并输出C代码以创建一个非常基本的翻译器。

This language is meant to be used in C# application (typed into some sort of control, whether it be RichTextBox or a custom control) and one requirement is to have syntax highlighting for this language. 这种语言用于C#应用程序(键入某种控件,无论是RichTextBox还是自定义控件),一种要求是为此语言提供语法高亮显示。 I have scoured the Internet in hopes of finding some sort of information on how to accomplish this, or find a tool to make this a little easier on myself. 我已经浏览了互联网,希望能找到关于如何实现这一目标的某种信息,或者找到一种工具来让自己变得更容易。

After not finding too much information, my best assumption would be that I need to use the ANTLR generated lexer to look at the tokens and color them accordingly. 在没有找到太多信息之后,我最好的假设是我需要使用ANTLR生成的词法分析器来查看标记并相应地对它们进行着色。 Is this the correct path of action, or is there some other method/tool to provide syntax highlighting for custom domain specific languages? 这是正确的操作路径,还是有其他方法/工具为自定义域特定语言提供语法突出显示? If this is the correct method, how do I go about recognizing specific tokens? 如果这是正确的方法,我该如何识别特定的令牌?

If I left out any important information, please ask! 如果我遗漏了任何重要信息,请询问! Thanks! 谢谢!

I successfully used AvalonEdit for a similar project of mine. 我成功地将AvalonEdit用于我的类似项目。 I just created a small editor with the correct syntax highlighting. 我刚刚用正确的语法高亮创建了一个小编辑器。

It is very easy and quick to get it up and running in your project. 在项目中启动和运行它非常简单快捷。 You just have to provide it with a simple XML file to document the syntax of your DSL and you will have a colored output out-of-the-box as a WPF control. 您只需提供一个简单的XML文件来记录您的DSL的语法,您将获得一个开箱即用的彩色输出作为WPF控件。

It looks like they added completion facilities since I used it, I don't have experience on that part though, but I suspect it is also very well done if the quality is the same as the colouring. 看起来他们添加完成设施,因为我使用它,虽然我没有经验,但我怀疑如果质量与着色相同也做得很好。

This language is meant to be used in C# application (typed into some sort of control, whether it be RichTextBox or a custom control) and one requirement is to have syntax highlighting for this language. 这种语言用于C#应用程序(键入某种控件,无论是RichTextBox还是自定义控件),一种要求是为此语言提供语法高亮显示。

Consider using Scintilla for your control. 考虑使用Scintilla进行控制。 It's a text control for IDE-style text editing. 它是IDE样式文本编辑的文本控件。 Notepad++ uses it for its text control, as does the SciTE IDE from which it originates. Notepad ++将其用于文本控制,其源自SciTE IDE。 I've used it in a small, custom IDE project written in C# using an unofficial .NET-specific version -- I think it was ScintillaNET . 我在一个用C#编写的小型自定义IDE项目中使用了非正式的.NET特定版本 - 我认为它是ScintillaNET

Scintilla supports custom keyword highlighting and also a variety of programmable features like squiggly-line underlining and things like that. Scintilla支持自定义关键字突出显示以及各种可编程功能,如波浪线下划线等。


If you have a control that you'd rather use, I think it's reasonable to use a small ANTLR lexer to produce tokens for you. 如果你有一个你宁愿使用的控件,我认为使用一个小的ANTLR词法分析器来为你生成令牌是合理的。 Each token contains the line number, starting character position, source text, and token type -- everything you'd need to know what to highlight and how. 每个令牌都包含行号,起始字符位置,源文本和令牌类型 - 您需要知道要突出显示的内容以及如何突出显示的内容。 The only hassle would be running the text through the lexer each time the text is changed. 每次更改文本时,唯一的麻烦就是通过词法分析器运行文本。 There are efficient ways to do that without re-lexing the entire document, but it's still something to keep in mind. 有一些有效的方法可以在不重新整理整个文档的情况下实现这一点,但仍需记住这一点。

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

相关问题 语法突出显示在 Visual Studio 中不起作用 - Syntax highlighting not working in Visual Studio 在Visual Studio 2015中突出显示奇怪的语法 - Strange syntax highlighting in Visual Studio 2015 Visual Studio 2012中嵌入式语言的语法突出显示 - Syntax Highlighting of an Embedded Language in Visual Studio 2012 Visual Studio 2019 Razor 语法在使用本地函数时突出显示 - Visual Studio 2019 Razor Syntax Highlighting When Using Local Functions Visual Studio 2015 不是语法高亮剃刀,也不是 Intellisense - Visual Studio 2015 not syntax highlighting razor nor Intellisense Visual Studio 2017 XAML设计器没有语法突出显示 - Visual Studio 2017 XAML Designer Has No Syntax Highlighting 如何在Visual Studio 11 Beta中为接口和委托设置语法突出显示? - How to setup syntax highlighting for interfaces and delegates in Visual Studio 11 Beta? 在Visual Studio中非项目文件的语法突出显示 - Syntax highlighting for non-project files in Visual Studio 如何在Visual Studio Code中为大型C#文件启用语法突出显示? - How do I enable syntax highlighting for a large C# file in Visual Studio Code? 如何在Visual Studio 2008中使VB.NET和C#的语法突出显示和键盘行为相同? - How to make make syntax highlighting and keyboard behavior identical for VB.NET and C# in Visual Studio 2008?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM