nobraces
idea by Ben
Python-style indentation for C
Project progress
The project has already been 6% completed, but the original developer is no longer involved.
There no new developers quoting to develop this project.
Current Quotes
Get paid to develop this project
The previous developer of this project was mattihas.goergens.
Project Info
License is open-source.
5 people are pledging, and $6 of the pledges have been paid.
Project Tags
braces c indent indentation python styleProject details
Tim Hatch wrote a neat (and humorous) filter for Python, pybraces, that allows you to write Python like a C programmer: with icky-looking braces and semicolons.
This project is the opposite: it will allow you write C like a Python programmer. Scrap your braces and semicolons and just indent your code as you would anyway. Read Ben’s blog entry for a bit more background.
What the developer needs to do is look at the source code for the minimal version Ben wrote and then extend it to robustly handle things like:
- Continuation lines. Ideally using Python-like implicit line joining for common situations, and backslash for explicit line joining.
- Preprocessor macros. C macros already use backslash as a line continuation character. You’ll have to make sure this still works.
- Comments. Ben’s version doesn’t handle comments after the colons at the end of control flow statements. To do so requires at least parsing and detecting strings, possibly something more clever.
It should also:
- Operate as a stdin/stdout filter, so you can use it by simply adding a pre-processing stage to your makefile.
- Work with C++/Java/etc. Shouldn’t be too hard. Well, maybe. :-)
- Have a reverse option. In other words, allow you to convert existing, braced C source into “nobraces” code.
16 comments (oldest first)
Oh yes, I forgot to mention: it should probably be written in C, so that people who only have C installed (and not Python) can easily use it.
I’d love doing this; but not for $100 :-)
Hi wlievens, fair call, but there are two possibilities: get your mates to pledge $20 each till the pledges reach say $300, or write it “for love” like a true open sourcer and come away with honour, glory, and at least $65 as a bonus. :-)
A hint for implementors: if you do this as a source-to-source translator (which is the objective, as I see it) you can use the #line and #file directives to maintain correct source references in the compiler transcripts.
I am not doing it for the $$$. ;) Just don’t tell anyone that I would probably have done a version for free.
Just wondering how you’re going on this, Matthias?
Ben, I have already started. At first I was going to code the program in python until I read your first comment.
Now I have aquainted myself with lex and yacc. You wrote that you did not want to actually parse C - so I thought parsing might actually be a good idea.
Sounds good. Coding it in Python would certainly be a good start – shouldn’t be too hard to convert it to C from there. Heading the lex/yacc direction sounds a bit complicated, but then again, I’ve never used ‘em, so that may just be me. :-)
Lex/Yacc are probably the way to go. You’re defining a new language here (C with Python blocks) and having a formal yacc/bison grammar for it would provide a solid definition of that language.
Sinc you want to go both ways, you’d also want to try to find an open-source C grammar that you can use to generate the C-with-Python-blocks code.
The C code generated by lexx/flex and yacc/bison could be part of the distribution if you want people with only a C compiler to be able to use it, though many/most Unix systems include them (including Mac OS X).
I agree, Harold.
Too all: I’ve been busy with my math studies lately. I will go back to nobraces, as soon as possible.
Edit: Would just distributing the source code generated by lex/yacc work? As far as I know you need special libraries for the linking..
harold, you’re right that it’s a “new language”, but I’m still in two minds about lex/yacc, and suspect they might actually make things more complicated, but I’m willing to leave that up to developer (mattihas). A working solution is a pretty good solution. :-)
The reason I think it might make it more complicated: wouldn’t you need to have the entire language grammar, which, especially for C++, might be quite large/icky? Probably grammars for C and C++ are readily available, and you could just hack one of those, but it might well be harder than just have a couple of simple rules to parse comments and strings (I suspect those are the only hard things). The other reason, as mattihas hinted at, is that you’ll need more tools/dependencies to make it.
mattihas, you could certainly distribute the generated source code in the package (good idea, in fact), but you’ll need to distribute the original source as well.
Ben, perhaps you are right about the complexities of C++ (and even C may prove to complex).
P.S. The above sentence only serves as a justification for this comment as I wanted to say that my name is Matthias and I just introduced a typo into my user. But I could not figure out, yet, how to change it.
About your username, Matthias: heh, I wondered whether that was the case. I’d never heard of a Mattihas before. :-) We haven’t allowed users to change their user names, mainly because it’s used for their user page and if it changed you’d get link rot. It’s also used for sign-in, so it might be confusing if it changed. But I’ve emailed you more detail about this issue.
I would suggest Antlr v3 over lex/yacc. It’s much more modern, in a good way, and has more attractive input and output. Anyway, that’s my $20 worth.
Sorry for being overdue. I have some things to do and did not prioritize nobraces high enough.
Expect gradual progress in the next few weeks.
Good stuff, Matthias. Looking forward to it. :-)
Add a comment
Before you add a comment you must be signed up – it takes about 30 seconds. Sign up now.