udoprog / genco

A whitespace-aware quasiquoter for beautiful code generation.
Apache License 2.0
181 stars 11 forks source link

Add C support #38

Closed believeinlain closed 1 year ago

believeinlain commented 1 year ago

PR that adds rudimentary support for C includes. Since C doesn't have a concept of "modules" we simply import items (which could be a function or variable) from files specified by path, with a boolean to distinguish system headers (such as #include <stdio.h>) from local headers (such as #include "foo/bar.h").

Note that it considers <stdio.h> and "stdio.h" to be different include files. We can let the C compiler sort out correctness - naming local headers with the same names as system headers that one is also using is incredibly bad practice.

Added working example and doc test.

Addresses Issue #22

udoprog commented 1 year ago

Looks great!

One thing I'm considering is whether the system header parameter might instead be better served by splitting it up into multiple function calls. But I'll have you decide since I don't use C codegen :).

believeinlain commented 1 year ago

Ah, I didn't think of that! I think it would improve readability to have include_header and include_system_header rather than passing a boolean. I'll rework it.

udoprog commented 1 year ago

Are things going OK? Would you like me to merge as-is?

believeinlain commented 1 year ago

Sorry, I kinda got caught up in other stuff. I split include into include and include_header and updated the related docs and tests. It should be good to merge now.

believeinlain commented 1 year ago

Ah, good catch. I've removed the with-package config option as it's not relevant to C.

udoprog commented 1 year ago

Thank you!