nobraces

Python-style indentation for C

No target
$100 pledged, USD
$
Pledge now, pay later.

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.

Get paid to develop this project.

re-opened for quotes
previous development
6%
Downloads

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 style
comments

Project 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.
add your own

16 comments (oldest first)

Ben 14 years ago link

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.

wlievens 14 years ago link

I’d love doing this; but not for $100 :-)

Ben 14 years ago link

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. :-)

wlievens 14 years ago link

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.

mattihas.goergens 14 years ago link

I am not doing it for the $$$. ;) Just don’t tell anyone that I would probably have done a version for free.

Ben 13 years ago link

Just wondering how you’re going on this, Matthias?

mattihas.goergens 13 years ago link

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.

Ben 13 years ago link

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. :-)

harold 13 years ago link

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

mattihas.goergens 13 years ago * link

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

Ben 13 years ago link

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.

mattihas.goergens 13 years ago link

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.

Ben 13 years ago * link

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.

grumdrig 13 years ago link

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.

mattihas.goergens 13 years ago link

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.

Ben 13 years ago * link

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.

Markdown formatting help:

Type thisTo get
*italics*italics
**bold**bold
[Brush](http://brush.co.nz/)Brush
* item A
* item B
* item C
  • item A
  • item B
  • item C