I'm writing some C at the moment and because I like whitespace sensitive syntax, I'd like to write it like this:
#include <stdio.h>
int main(void)
printf("Hello, world!")
return 0
Instead of this:
#include <stdio.h>
int main(void) {
printf("Hello, world!");
return 0;
}
Does anybody know of a tool that will convert the former into the latter?
Edit: I've really no interest in arguing with those that think this is a bad idea. By all means continue to think that, you have your reasons. But at least know this: I'm aware Python is a whitespace sensitive language but I have not used it. Why would I? I know Ruby already. Also know: I am not just learning C for the first time and I have used PHP and JavaScript for more than four years, so I am not requesting this out of some personal difficulty, lack of familiarity with block syntax, or dogmatic affiliation. I am also aware of what would be involved in writing one of these and that's not beyond my ability but I don't want this enough to justify spending the time writing one.
Even if there was such a tool, I would strongly encourage you to reconsider this idea. Here are just a few problems I think you'll find with doing this:
This really seems to be a case where fitting your habits to everybody else is the smarter approach.
Hope this causes you to reconsider.
http://www.cython.org/
But that's a different language... it's basically a Python dialect with C performance properties.
Don't roll your own language, use something standard.
If you really want to do this, it is not going to be possible without implementing a language parser, and even then, I am not sure how the coding convention will be for some of the cases in your "new language that looks like C but has no braces". For example, take the following C code:
You can write it as
But it has to be converted to the original code, not:
Also, given the snippets below:
How are you going to specify these in your language?
You seem to not want to use semicolons in your language either. This restricts your code quite a bit, and makes the conversion tool complicated as well, because you can't have continuation lines without extra effort:
is legal C, but
is not.
So first, you need to define the grammar of your "braceless C" more precisely. As others have said, this sort of thing is fraught with peril.
Python-style indentation for C.
Looks like it is what you are looking for.
Yea, there's one I really like. They call it Python.
I don't believe such a tool exists. Tools exist to clean formatting, but the code must already be C formatted.
I really think you should use the language as designed and learn to use braces.