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 beautifiers 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++?)
A program that improves the presentation of programming source code. Based on an analysis of the syntax, it indents lines appropriately and squashes extraneous blank spaces and lines in order to produce more readable code.
Code formatting provides you with many opportunities to subtly communicate your intent to a reader. Far from being a backwater best left to draconian "style guides", code formatting is often your reader's first encounter with your system. It deserves attention and care.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With