Visual Studio样式字符串突出显示 [英] Visual Studio Style String Highlighting

查看:114
本文介绍了Visual Studio样式字符串突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个语法高亮显示器,它使用正则表达式来匹配文本。我正在使用字符串,我喜欢视觉工作室中的功能,它突出显示打开报价以关闭报价或打开报价到您输入的行尾,如下所示:

   hello world //这是其他一些代码 



   hello world  //  这是其他一些代码 





是否有一个正则表达式可以实现这一点?我已经尝试了很多东西,但它们都会在结束引号被突出显示之后导致代码,字符串不突出显示直到输入关闭引用之后。

解决方案

什么正则表达式?!正则表达式只能帮助查找匹配项并执行字符串替换。它们与图形无关或UI涉及突出显示。字符串也是纯粹的数据,与突出显示无关。您可以突出显示在某个可视实体(屏幕,打印)上呈现的文本,例如, System.Windows.Media.Visual 系统.Windows.Forms.Control System.Drawing.Graphics ,但不是字符串。



最全面的语法突出显示方法之一是在开源AvalonEdit组件中开发的。特别是,它被用在名为SharpDevelop的替代开源IDE中,它与Visual Studio非常相似:

http://en.wikipedia.org/wiki/SharpDevelop [ ^ ],

http://www.icsharpcode.net/ OpenSource / SD / Default.aspx [ ^ ]。



请参阅:

https://github.com/icsharpcode/SharpDevelop/wiki/AvalonEdit [ ^ ]。



另请参阅此CodeProject文章(从AvalonEdit网站引用):使用AvalonEdit(WPF文本编辑器) [ ^ ]。



-SA

I am writing a syntax highlighter that uses regular expressions to match text. I'm working on string and I like the feature in visual studio that highlights open-quote to close-quote or open-quote to end-of-line as you type, like so:

"hello world //and this is some other code


"hello world" //and this is some other code



Is there a regular expression that could accomplish this? I have tried a number of things, but they all result in the code after the end quote being highlighted as well, of the string isn't highlighted until after the close quote is input.

解决方案

What regular expressions?! Regular expressions only help to find matches and perform string replacements. They have nothing to do with graphics or UI involved in highlighting. Strings, also, is pure data which has nothing to do with "highlighting". You can highlight text rendered on some visual entity (screen, print), such as, just for example, System.Windows.Media.Visual or System.Windows.Forms.Control, System.Drawing.Graphics, but not string.

One of the most comprehensive approaches to syntax highlighting is developed in the open-source AvalonEdit component. In particular, it is used in the alternative open-source IDE called SharpDevelop, which is very similar to Visual Studio:
http://en.wikipedia.org/wiki/SharpDevelop[^],
http://www.icsharpcode.net/OpenSource/SD/Default.aspx[^].

Please see:
https://github.com/icsharpcode/SharpDevelop/wiki/AvalonEdit[^].

See also this CodeProject article (referenced from the AvalonEdit site): Using AvalonEdit (WPF Text Editor)[^].

—SA


这篇关于Visual Studio样式字符串突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆