Commit Graph

22 Commits

Author SHA1 Message Date
Benedikt Peetz 25d03a3dd5
docs(parser/examples): Add various examples (also the trinitrix main api) 2024-03-24 20:07:53 +01:00
Benedikt Peetz 5b8d31e806
test(parser/checked/test): Update test case 2024-03-24 20:07:13 +01:00
Benedikt Peetz f24d6310fd
fix(parser/lexing/error): Improve the message of the `NoMatchesTaken` error
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.
2024-03-24 20:03:58 +01:00
Benedikt Peetz f14ef1cec2
fix(parser/error): Remove multiple errors from line number calc
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.
2024-03-24 19:59:21 +01:00
Benedikt Peetz 3c3ee23c2b
feat(parser): Associate a vector of nasps with every struct, enum, nasp
This feature makes it possible to generate these types actually in
namespaces and not only in one toplevel.
2024-03-24 19:57:32 +01:00
Benedikt Peetz 4a32f0d2f4
feat(parser): Add support for parsing function pointer types
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.
2024-03-24 19:35:09 +01:00
Benedikt Peetz e984cdc66f
feat(parser/bin): Allow `lex` as an alias to `tokenize` 2024-03-24 19:28:27 +01:00
Benedikt Peetz dad99d1a10
refactor(parser): Use predictable names for tokens 2024-03-24 19:27:25 +01:00
Benedikt Peetz 4da72b2655
fixup! feat(parser/lexing): Desugger doc comments by running a regex on the file 2024-03-24 19:18:23 +01:00
Benedikt Peetz 98c3b009df
feat(parser): Add support for parsing attributes 2024-03-24 19:16:52 +01:00
Benedikt Peetz bf3eb61110
feat(parser/lexing): Desugger doc comments by running a regex on the file
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.
2024-03-24 18:09:57 +01:00
Benedikt Peetz d904a19f48
style(treewide): Reformat with treefmt (`nix fmt`) 2024-02-19 20:53:11 +01:00
Benedikt Peetz 03f8eda241
style(treewide): Reformat 2024-02-19 16:15:18 +01:00
Benedikt Peetz 5a7bb00548
chore(treewide): Add the new license header 2024-02-19 16:13:55 +01:00
Benedikt Peetz 7ac6edb752
chore(treewide): Remove old license header
This was done with:
```bash
fd --type file . | xargs grep 'Copyright (C) 2023  The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>' | awk 'BEGIN{ FS=":"} {print $1}' | xargs sed -i '1,19d'
```
2024-02-19 16:13:48 +01:00
Benedikt Peetz e52f74b0c1
feat(treewide): Finalize basic c API
See the example under `./example/main/` for more details.
2024-02-19 15:50:30 +01:00
Benedikt Peetz 88aa3c3ad7
docs(trixy-parser): Update the railroad diagrams 2024-02-18 13:36:37 +01:00
Benedikt Peetz a077ef1466
fix(trixy-parser): Remove the `void` type 2024-02-18 13:27:31 +01:00
Benedikt Peetz dc8a7ecb33
test(trixy-parser): Restore test functionality after nasp -> mod rename 2024-02-18 13:17:34 +01:00
Benedikt Peetz b6799877bb
feat(trixy-parser): Adapt Trixy to be a complete subset of rust
This changes two important things:
- Firstly it renames the `nasp` keyword to `mod`:
        This change removes the not required deviation from rust.
- Secondly it removes the semicolon after an enumeration or structure
  declaration, which is pointless in these positions.
2024-02-17 19:54:43 +01:00
Benedikt Peetz b3c6a4c1a1
feat(treewide): Add broken Vec<E>, Result<T,E> and Option<T> types to c api
These are implemented right now by simply casting the generic arguments
to void pointers and providing a `type_id` field in every struct
denoting the original type.

This implementation, whilst being extremely unwieldy to work with on
the c side, also fails in a lot of fundamental ways:
   1. The `type_id` enum *can* never really support user defined
      types because we would already need it to provide the c to rust
      value conversion.

   2. Even without custom user types the type conversion is extremely
      hard to correctly implement in a somewhat performant way: A vector
      passed from c code to rust would need to completely reallocated
      *one element at a time*. And this only works if the c side has
      correctly cast the void pointer to the vectors data before accessing
      it, as any other way would have lead to possible unaligned data
      (which the rust side had to account for).

   3. The c api is just simply bad in this state:
      You have to always look at the Trixy file to even be able to deal
      with the data the api returns (that is: There is no mention of
      a results generics in the c header).  Additionally the question
      arises if these types should even be leaked into the c code because
      than c just becomes a worse version of rust, which undermines the
      whole reason of providing a c api in the first place.

One way to fix all these issues would be to change the way generics are
handled by using unions instead of the void pointer and trying to avoid
leaking these rust types in c as far as possible.
This approach would require a lot less binding code (both on the c and
rust side), but also would make the rust based c-header-gen-code harder,
as it would then be required to turn a `Vec<String>` to a `char **` (and
obviously a whole wrapper struct with size and string length), whilst
turning a `Vec<char>` to a `char*` differentiating it from a `string_t`.
2023-12-28 10:28:58 +01:00
Benedikt Peetz 21e1b75193
chore(treewide): Move the trixy subcrates under one trixy crate 2023-12-26 12:14:08 +01:00