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.
发布评论
评论(2)
Python 有一个有趣的特性——它向脚本公开自己的解析器。有示例使用 AST - 抽象语法树 - 并执行漂亮的印刷。
我不知道 Ruby 以这种方式向其脚本公开自己的解析器,但是有一些用 Ruby 编写的 Ruby 解析器 此处。
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.
嗯...我认为初始步骤是您为任何项目所做的事情。
写下要求清单。
描述您的程序的用户界面,您喜欢它并且不会妨碍您满足这些要求。
现在,您可以写下更多“代码”设计,并选择最容易满足该设计的语言。
以下是我脑海中浮现的一些要求:
想要多少就制作多少,这是您的程序。 ;p 我是在拿 Perl 开玩笑,但我认为你支持的每一种语言都会增加更多的工作。
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:
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.