开发者

Writing a code beautifier [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Improve this question

I'd like to write a code beautifier and i thought of using Ruby to do it. Could someone show me a place to get started? I've seen a lot of code bea开发者_如何学运维utifiers online but I've never come across any tutorials on how to write one. Is this a very challenging task for someone who's never undertaken any projects such as writing a compiler, parser, etc. before?

(Is there another langauge which would be more well suited for this kind of task, excluding C/C++?)


Python has an interesting feature - it exposes its own parser to scripts. There are examples that use the AST - abstract syntax tree - and do the pretty printing.

I'm not aware that Ruby exposes its own parser to its scripts in such a way, but there are parsers for Ruby written in Ruby here.


Well... I think the initial steps are what you'd do for any project.

Write a list of requirements. Describe a user interface to your program, that you like and won't prevent you meeting those requirements. Now you can write down more of a "code" design, and pick the language that would be easiest for you to meet that design.

Here's some requirements off the top of my head:

  • Supports code beautifying of these languages: Ruby, Python, Perl
  • Output code behaves identically to input
  • Output has consistent use of tabs/spaces
  • Output has consistent function naming convention
  • Output has consistent variable naming convention
  • Output has matching braces and indentation

Make as many as you want, it's your program. ;p I was kidding about the Perl, but I think every language you support is going to add a more work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜