dragons-and-bytecode / comfy

Comfy - the comfortable C dialect
Mozilla Public License 2.0
1 stars 0 forks source link

Generated Header Files #4

Closed RavenNevermore closed 9 years ago

RavenNevermore commented 9 years ago

Admit it, you hate them.

More than that, Header files in C basically force you, to repeat yourself with anything, you want to be accessable from somewhere else. Thatway preventing you from writing beautiful and dry code.

With Comfy you don't need to worry about them anymore. In any .comfy file, you can simply declare members as public like so.

    /**
     * Some documentation, that will get moved to the header
     * as well.
     */
    public void i_am_visible(){
        //Put on some clothes
    }

Comfy will parse your file for any public identifiers and if it finds at least one, it will automatically generate a header file, copying the directive as a definition and also taking any documentation comments attached to the identifier.

It will also gate your definitions within a namespace.

So, assuming the above example is in a file called foobar.comfy, it would be generated as:

    /**
     * Some documentation, that will get moved to the header
     * as well.
     */
    void foobar_i_am_visible();
RavenNevermore commented 9 years ago

Maybe we don't even need public? What about simply exporting everything?

RavenNevermore commented 9 years ago

More formally:

Generally, the comfy source file will be copied to both, the header and the c source file, before it is processed through different modifiers.

These do in the c file:

  1. add an include to the header file in the first line.
  2. delete any pre processor lines, that start with two hashes. ##

And in the header file:

  1. delete any preprocessor lines, that start with only a single hash. #
  2. convert any double hashes to single hashes.

Preprocessor diectives:

Any preprocessor directive is by default kept in the source file and not exported to the header, in order to prevent cluttering the namespace.

If a preprocessor directive should be exported to the header, one should prepend it with another #.

#include "will_not_be_in_header.h"
##include "wil_be_in_header.h"
RavenNevermore commented 9 years ago

Implemented, via Line masking.

But there need to be a bit more features, to make that actually dry and usable.

Basically, the header generation works of of the notion, that any header line is starting with §, while a c-source line doesn't.

Now we can write features, that modify the .comfy source and add or remove masks to lines, to make this even more usefull.