Skip to content

Commit ca087d2

Browse files
committed
docs: add documentation on updating and publishing grammars
1 parent 8bb1448 commit ca087d2

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

docs/src/cli/test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Skip tests whose names match this regex.
1818

1919
### `-u/--update`
2020

21-
Update the expected output of tests.
21+
Update the expected output of tests.
2222

2323
```admonish info
2424
Tests containing `ERROR` nodes or `MISSING` nodes will not be updated.

docs/src/creating-parsers/5-writing-tests.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func x() int {
3131
* Then the **input source code** is written, followed by a line containing three or more `-` (dash) characters.
3232

3333
* Then, the **expected output syntax tree** is written as an [S-expression][s-exp]. The exact placement of whitespace in
34-
the S-expression doesn't matter, but ideally the syntax tree should be legible.
34+
the S-expression doesn't matter, but ideally the syntax tree should be legible.
3535

3636
```admonish tip
3737
The S-expression does not show syntax nodes like `func`, `(` and `;`, which are expressed as strings and regexes in the grammar.
@@ -163,6 +163,5 @@ file is changed.
163163

164164
[constants]: https://doc.rust-lang.org/std/env/consts/constant.OS.html
165165
[external-scanners]: ./4-external-scanners.md
166-
[named-vs-anonymous-nodes]: ../using-parsers/2-basic-parsing.md#named-vs-anonymous-nodes
167166
[node-field-names]: ../using-parsers/2-basic-parsing.md#node-field-names
168167
[s-exp]: https://en.wikipedia.org/wiki/S-expression
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Publishing your grammar
2+
3+
Once you feel that your parser is in a stable working state for consumers to use, you can publish it to various registries.
4+
It's strongly recommended to publish grammars to GitHub, [crates.io][crates.io] (Rust), [npm][npm] (JavaScript), and [PyPI][pypi]
5+
(Python) to make it easier for others to find and use your grammar.
6+
7+
If your grammar is hosted on GitHub, you can make use of our [reusable workflows][workflows] to handle the publishing process
8+
for you. This action will automatically handle regenerating and publishing your grammar in CI, so long as you have the required
9+
tokens setup for the various registries. For an example of this workflow in action, see the [Python grammar's GitHub][python-gh]
10+
11+
## From start to finish
12+
13+
To release a new grammar (or publish your first version), these are the steps you should follow:
14+
15+
1. Bump your version to the desired version with `tree-sitter version`. For example, if you're releasing version `1.0.0`
16+
of your grammar, you'd run `tree-sitter version 1.0.0`.
17+
2. Commit the changes with `git commit -am "Release 1.0.0" (or however you like)` (ensure that your working directory is
18+
clean).
19+
3. Tag the commit with `git tag -- v1.0.0`.
20+
4. Push the commit and tag with `git push --tags origin main` (assuming you're on the `main` branch, and `origin` is your
21+
remote).
22+
5. (optional) If you've set up the GitHub workflows for your grammar, the release will be automatically published to GitHub,
23+
crates.io, npm, and PyPI.
24+
25+
### Adhering to Semantic Versioning
26+
27+
When releasing new versions of your grammar, it's important to adhere to [Semantic Versioning][semver]. This ensures that
28+
consumers can predictably update their dependencies and that their existing tree-sitter integrations (queries, tree traversal
29+
code, node type checks) will continue to work as expected when upgrading.
30+
31+
1. Increment the major version when you make incompatible changes to the grammar's node types or structure
32+
2. Increment the minor version when you add new node types or patterns while maintaining backward compatibility
33+
3. Increment the patch version when you fix bugs without changing the grammar's structure
34+
35+
For grammars in version 0.y.z (zero version), the usual semantic versioning rules are technically relaxed. However, if your
36+
grammar already has users, it's recommended to treat version changes more conservatively:
37+
38+
- Treat patch version (`z`) changes as if they were minor version changes
39+
- Treat minor version (`y`) changes as if they were major version changes
40+
41+
This helps maintain stability for existing users during the pre-1.0 phase. By following these versioning guidelines, you
42+
ensure that downstream users can safely upgrade without their existing queries breaking.
43+
44+
[crates.io]: https://crates.io
45+
[npm]: https://www.npmjs.com
46+
[pypi]: https://pypi.org
47+
[python-gh]: https://github.com/tree-sitter/tree-sitter-python/blob/master/.github/workflows/publish.yml
48+
[semver]: https://semver.org/
49+
[workflows]: https://github.com/tree-sitter/workflows

0 commit comments

Comments
 (0)