编写代码美化器

发布于 2024-09-26 18:24:59 字数 1431 浏览 0 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疏忽 2024-10-03 18:25:00

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.

习ぎ惯性依靠 2024-10-03 18:25:00

嗯...我认为初始步骤是您为任何项目所做的事情。

写下要求清单。
描述您的程序的用户界面,您喜欢它并且不会妨碍您满足这些要求。
现在,您可以写下更多“代码”设计,并选择最容易满足该设计的语言。

以下是我脑海中浮现的一些要求:

  • 支持这些语言的代码美化:Ruby、Python、Perl
  • 输出代码的行为与输入相同
  • 输出具有一致的制表符/空格使用
  • 输出具有一致的函数命名约定
  • 一致的变量命名约定
  • 输出具有一致的变量命名约定 输出具有 匹配大括号和缩进

想要多少就制作多少,这是您的程序。 ;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:

  • 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文