This might be a big diff, but I _hope_ that it does not change much
functionally (hopefully it changes nothing generation specific).
What has changed?
-----------------
- I had to merge the three crates into one, to allow `macros` to impl
functions on Types defined in `parser`.
- As mentioned in the point above, the conversion function are now
inherent to the type they convert (i. e. `r#type.to_rust()` instead of
`type_to_rust(r#type)`).
- The conversion function have been sorted, by what they convert to:
- `to_rust()` converts a type to be used in rust *host* code.
- `to_c()` converts a type to be used in c *host* code.
- `to_auxiliary_c()` converts a type to be used in c *auxiliary*
code.
- The top-most `generate` method of `TrixyConfig` now returns a
`FileTree` instead of writing the files directly. The `FileTree` can
still be materialize with the `materialize` method. But this change
facilitates moving non-generation focused code out of the `generate`
method.
What is the difference between _host_ and _auxiliary_ code?
-----------------------------------------------------------
Auxiliary code is always written in the language it is generated for. So
auxiliary code for c would be written in c (or at least in a subset of c),
as it represents c header files.
Host code is always written in rust. This is the code that is
responsible for implementing the actual ffi stuff. In our case these are
the `extern "C"` functions and the types, defined in trixy.
The rust host code is generating the native rust representations of
these types.
This error should only ever be raised, when we encountered a bug.
This change notifies the user, that the situation is rather likely to be
a bug and that this should be reported.
Errors were contextualized by finding their index in the source file.
This method is extremely flaky, as it _hopes_ that the line is not
spread over multiple lines.
The new method actually uses the span to calculate a matched line and
thus avoids any issues related to the actual position of the line in the
source file.
Notably these diverge from rust, by requiring argument names. This is a
deliberate design decision, as it help users to guess what's going to be
passed into their callback.
Previously we actually supported parsing doc comments (`///`), but
replacing them before parsing allows for simplifications in the lexer.
Precisely, that means that we can add support for attributes without
having to maintain the doc comment parser.
This only adds this as nix module. So running `nix fmt` will now format
all files under the repo root.
If you want to run this as non-nix user feel free to take a look at the
generated `treefmt.toml`.
The old implementation tried to provide rust types in c—like the
result or option types. This implementation now removes this source of
complexity by ensuring, that these types are unwrapped on the rust->c
boundary.
This first commit changes the header files to conform to the new api.