如何创建像Visual Studio这样的代码格式化实用程序? [英] How to create code formatting utility like Visual Studio?

查看:96
本文介绍了如何创建像Visual Studio这样的代码格式化实用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此先感谢,

我想创建一个文本格式实用程序,可以像Visual Studio一样工作.即当我按;"时字符,Visual Studio会根据键入的语言(C#,VB或XML)自动格式化我的代码.因此,我希望从我的实用程序中获得相同的功能,这是一个大学项目.有任何指导或帮助吗?

Thanks in advance,

I want to create a text formatting utility which can work like Visual Studio. i.e. when i press ";" character, visual studio automatically formats my code according to typed language (C#, VB or XML). So, i want the same functionality from my utility, it is a university project. Any guidance or help?

推荐答案

这不是一个小项目,您将不得不做很多事情.由于这是您的作业,因此我不会给您任何代码!
1)定义格式规则,并允许用户对其进行更改.有些使用K& R格式:
This is not a small project, you will have to do quite a lot. And since it is your homework, I will give you no code!
1) Define format rules, and allow the user to change them. Some use K&R format:
if (condition) {
   ...
   }

其他缩进代码:

Others indent code:

if (condition)
{
   ...
}

其他缩进大括号:

Others indent braces:

if (condition)
   {
   ...
   }

有时候,它希望没有缩进:

Sometimes, it is wanted without indents:

if (condition) ...

您将必须考虑所有这些规则和其他规则.
2)您将不得不扫描整个文件,并为有效的语言语法对其进行处理.只有有了这些,您才能开始纠正"缩进.这意味着您至少需要为要支持的每种语言创建一个解析器.
3)实际的输出很容易!

从Google开始:然后从那里开始!

You will have to allow for all of these, and other rules.
2) You will have to scan the entire file, and process it for valid language syntax. Only when you have that, can you start to "correct" indentation. This means you need to make at least a parser for each language you will support.
3) The actual output is the easy bit!

Start with Google: and go from there!


这篇关于如何创建像Visual Studio这样的代码格式化实用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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