Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metadata inner class for Language versioning #119

Merged
merged 16 commits into from
Feb 2, 2024
Merged

Conversation

dabico
Copy link
Member

@dabico dabico commented Feb 2, 2024

This PR introduces a new data class intended to give users a more accurate representation of the current grammar version at runtime. This is achieved through bundling the Git submodule information into a dedicated .properties file, which is then read at runtime.

From `CSHARP` to `C_SHARP`
This script is intended to trigger at build time, generating a file
called `language.properties`. Each file consists of a repetition of
three-line sections in the format:

```
tree-sitter.language.{language-name}.url={language-url}
tree-sitter.language.{language-name}.sha={language-sha}
tree-sitter.language.{language-name}.tag={language-tag}
```

Where `language-url` and `language-sha` are the remote URL and full last
commit SHA of the specified language submodule. The `language-tag` is
the current Git tag at which the submodule is situated, and it may or
may not be present. This information will be used at runtime to inject
additional information into `Language` enum values.
We want to ignore the generated language metadata properties file.
I've recently come to the realization that generated files should never
see a VCS, and this one is no exception. We only have to take care to
bind the generation to the correct build step, in order to ensure the
file is always picked up for packaging.
Rather than adhering to the format described in 971dc00,
I have decided to switch to a more compact format:

```
url.{language-name}={language-url}
sha.{language-name}={language-sha}
tag.{language-name}={language-tag}
```

This has the added benefit of easier mapping at runtime, as well as
more concise filtering by prefix. For instance, if we only need URLs,
we need only filter the keys that start with `url`.
Not useful to the average end-user, but will be of great use to us.
For this reason, it will remain `private`.
Said instance method fetches the information loaded from the properties
file, and compiles it in the `Language#Metadata` wrapper.
@dabico dabico merged commit 98d39e0 into master Feb 2, 2024
2 checks passed
@dabico dabico deleted the language/version branch February 2, 2024 16:13
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.

1 participant