Skip to content

Conversation

@Marcono1234
Copy link
Contributor

@Marcono1234 Marcono1234 commented Apr 18, 2025

The current implementation implicitly relies on the following:

  • That the C enum values in tree-sitter start at 0 and have consecutive values
  • That Java enum's ordinal() begins at 0
  • That the C and Java enum values are in the same order

Currently all of this is the case, but it feels a bit brittle.

Because the C enum constant values are part of the jextract generated code, it seems more reliable to use them instead.

Is more robust than implicitly relying on Java and C enum having same values.
@ObserverOfTime
Copy link
Member

If something changes we can revisit this. But for now let's not complicate something that works just fine.

@Marcono1234
Copy link
Contributor Author

Hmm, ok. Personally I don't think this really complicates it; it is rather the opposite: The current code with its ordinal() usage and implicit assumptions (which are also not commented) makes it difficult to understand and maintain. And if this breaks in the future, it will fail in confusing ways.

The proposed changes here with its TSInputEncoding... usage make the behavior very clear1. If you don't like the way I implemented it, feel free to change it in whatever way you prefer. But I really think it would be better to use TSInputEncoding... here.

But it is your choice of course.

Footnotes

  1. Note also that this is an internal change only; the newly added tsInputEncoding() is package-private and not visible or accessible to users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants