docs: replace mdbook-admonish with mdBook admonitions

This commit is contained in:
Amaan Qureshi 2026-08-30 15:42:41 -04:00 committed by Amaan Qureshi
parent aa1b924997
commit ea9ddbe190
20 changed files with 130 additions and 524 deletions

View file

@ -18,22 +18,16 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v7.0.1 uses: actions/checkout@v7.0.1
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install mdbook - name: Install mdbook
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
run: | run: |
jq_expr='.assets[] | select(.name | contains("x86_64-unknown-linux-gnu")) | .browser_download_url' jq_expr='.assets[] | select(.name | contains("x86_64-unknown-linux-gnu")) | .browser_download_url'
url=$(gh api repos/rust-lang/mdbook/releases/tags/v0.4.52 --jq "$jq_expr") url=$(gh api repos/rust-lang/mdbook/releases/tags/v0.5.4 --jq "$jq_expr")
mkdir mdbook mkdir mdbook
curl -sSL "$url" | tar -xz -C mdbook curl -sSL "$url" | tar -xz -C mdbook
printf '%s/mdbook\n' "$PWD" >> "$GITHUB_PATH" printf '%s/mdbook\n' "$PWD" >> "$GITHUB_PATH"
- name: Install mdbook-admonish
run: cargo install mdbook-admonish
- name: Build Book - name: Build Book
run: mdbook build docs run: mdbook build docs

View file

@ -5,10 +5,10 @@ src = "src"
title = "Tree-sitter" title = "Tree-sitter"
[output.html] [output.html]
additional-css = [ "src/assets/css/playground.css", "src/assets/css/mdbook-admonish.css" ] additional-css = [ "src/assets/css/playground.css" ]
additional-js = [ "src/assets/js/playground.js" ] additional-js = [ "src/assets/js/playground.js" ]
edit-url-template = "https://github.com/tree-sitter/tree-sitter/edit/master/docs/{path}" edit-url-template = "https://github.com/tree-sitter/tree-sitter/edit/master/docs/{path}"
git-repository-icon = "fa-github" git-repository-icon = "fab-github"
git-repository-url = "https://github.com/tree-sitter/tree-sitter" git-repository-url = "https://github.com/tree-sitter/tree-sitter"
[output.html.search] [output.html.search]
@ -18,9 +18,3 @@ boost-title = 2
expand = true expand = true
limit-results = 20 limit-results = 20
use-boolean-and = true use-boolean-and = true
[preprocessor]
[preprocessor.admonish]
assets_version = "3.0.2" # do not edit: managed by `mdbook-admonish install`
command = "mdbook-admonish"

View file

@ -3,7 +3,6 @@
lib, lib,
version, version,
mdbook, mdbook,
mdbook-admonish,
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {
inherit version; inherit version;
@ -11,10 +10,7 @@ stdenv.mkDerivation {
src = ./.; src = ./.;
pname = "tree-sitter-docs"; pname = "tree-sitter-docs";
nativeBuildInputs = [ nativeBuildInputs = [ mdbook ];
mdbook
mdbook-admonish
];
buildPhase = '' buildPhase = ''
mdbook build mdbook build

View file

@ -154,13 +154,14 @@ Then, in our config file, we could map each of these highlight names to a color:
Running `tree-sitter highlight` on this Go file would produce output like this: Running `tree-sitter highlight` on this Go file would produce output like this:
```admonish example collapsible=true, title='Output' <details>
<summary>Output</summary>
<pre class='highlight'> <pre class='highlight'>
<span style='color: purple;'>func</span> <span style='color: #005fd7;'>increment</span>(<span>a</span> <span style='color: green;'>int</span>) <span style='color: green;'>int</span> { <span style='color: purple;'>func</span> <span style='color: #005fd7;'>increment</span>(<span>a</span> <span style='color: green;'>int</span>) <span style='color: green;'>int</span> {
<span style='color: purple;'>return</span> <span>a</span> <span style='font-weight: bold;color: #4e4e4e;'>+</span> <span style='font-weight: bold;color: #875f00;'>1</span> <span style='color: purple;'>return</span> <span>a</span> <span style='font-weight: bold;color: #4e4e4e;'>+</span> <span style='font-weight: bold;color: #875f00;'>1</span>
} }
</pre> </pre>
``` </details>
### Local Variables ### Local Variables
@ -297,7 +298,8 @@ and blocks create local *scopes*, parameters and assignments create *definitions
Running `tree-sitter highlight` on this ruby file would produce output like this: Running `tree-sitter highlight` on this ruby file would produce output like this:
```admonish example collapsible=true, title='Output' <details>
<summary>Output</summary>
<pre class='highlight'> <pre class='highlight'>
<span style='color: purple;'>def</span> <span style='color: #005fd7;'>process_list</span><span style='color: #4e4e4e;'>(</span><span style='text-decoration: underline;'>list</span><span style='color: #4e4e4e;'>)</span> <span style='color: purple;'>def</span> <span style='color: #005fd7;'>process_list</span><span style='color: #4e4e4e;'>(</span><span style='text-decoration: underline;'>list</span><span style='color: #4e4e4e;'>)</span>
<span>context</span> <span style='font-weight: bold;color: #4e4e4e;'>=</span> <span style='color: #005fd7;'>current_context</span> <span>context</span> <span style='font-weight: bold;color: #4e4e4e;'>=</span> <span style='color: #005fd7;'>current_context</span>
@ -305,11 +307,11 @@ Running `tree-sitter highlight` on this ruby file would produce output like this
<span style='color: #005fd7;'>process_item</span>(<span style='text-decoration: underline;'>item</span><span style='color: #4e4e4e;'>,</span> <span>context</span><span style='color: #4e4e4e;'>)</span> <span style='color: #005fd7;'>process_item</span>(<span style='text-decoration: underline;'>item</span><span style='color: #4e4e4e;'>,</span> <span>context</span><span style='color: #4e4e4e;'>)</span>
<span style='color: purple;'>end</span> <span style='color: purple;'>end</span>
<span style='color: purple;'>end</span> <span style='color: purple;'>end</span>
<span></span>
<span>item</span> <span style='font-weight: bold;color: #4e4e4e;'>=</span> <span style='font-weight: bold;color: #875f00;'>5</span> <span>item</span> <span style='font-weight: bold;color: #4e4e4e;'>=</span> <span style='font-weight: bold;color: #875f00;'>5</span>
<span>list</span> <span style='font-weight: bold;color: #4e4e4e;'>=</span> [<span>item</span><span style='color: #4e4e4e;'>]</span> <span>list</span> <span style='font-weight: bold;color: #4e4e4e;'>=</span> [<span>item</span><span style='color: #4e4e4e;'>]</span>
</pre> </pre>
``` </details>
### Language Injection ### Language Injection
@ -417,19 +419,19 @@ var abc = function(d) {
}; };
``` ```
```admonish cite title='From the Sublime text docs' > **From the Sublime Text docs**
The two types of tests are: >
> The two types of tests are:
>
> **Caret**: ^ this will test the following selector against the scope on the most recent non-test line. It will test it
> at the same column the ^ is in. Consecutive ^s will test each column against the selector.
>
> **Arrow**: <- this will test the following selector against the scope on the most recent non-test line. It will test it
> at the same column as the comment character is in.
**Caret**: ^ this will test the following selector against the scope on the most recent non-test line. It will test it > [!NOTE]
at the same column the ^ is in. Consecutive ^s will test each column against the selector. > An exclamation mark (`!`) can be used to negate a selector. For example, `!keyword` will match any scope that is
> not the `keyword` class.
**Arrow**: <- this will test the following selector against the scope on the most recent non-test line. It will test it
at the same column as the comment character is in.
```
```admonish note
An exclamation mark (`!`) can be used to negate a selector. For example, `!keyword` will match any scope that is
not the `keyword` class.
```
[erb]: https://en.wikipedia.org/wiki/ERuby [erb]: https://en.wikipedia.org/wiki/ERuby
[highlight crate]: https://github.com/tree-sitter/tree-sitter/tree/master/crates/highlight [highlight crate]: https://github.com/tree-sitter/tree-sitter/tree/master/crates/highlight

View file

@ -89,9 +89,8 @@ npm install # or your JS package manager of choice
npm run build npm run build
``` ```
```admonish note > [!NOTE]
If using a local Emscripten installation, the version must match the one [pinned by this repository][emscripten-version]. > If using a local Emscripten installation, the version must match the one [pinned by this repository][emscripten-version].
```
Build the Rust libraries and the CLI: Build the Rust libraries and the CLI:
@ -301,9 +300,8 @@ edit and hit the edit icon at the top right of the page.
### Prerequisites for Local Development ### Prerequisites for Local Development
```admonish note > [!NOTE]
We're assuming you have `cargo` installed, the Rust package manager. > We're assuming you have `cargo` installed, the Rust package manager.
```
To run and iterate on the docs locally, the To run and iterate on the docs locally, the
[`mdbook`][mdbook cli] CLI tool is required, which can be installed with [`mdbook`][mdbook cli] CLI tool is required, which can be installed with
@ -313,16 +311,14 @@ cargo install mdbook
``` ```
You might have noticed we have some fancy admonitions sprinkled throughout the documentation, like the note above. You might have noticed we have some fancy admonitions sprinkled throughout the documentation, like the note above.
These are created using [`mdbook-admonish`][admonish], a [preprocessor][preprocessor] for `mdBook`. As such, this is also These are built into `mdBook`, and are written as a blockquote whose first line names the kind, one of `NOTE`, `TIP`,
a requirement for developing the documentation locally. To install it, run: `IMPORTANT`, `WARNING`, or `CAUTION`. See the [reference][admonitions] for more information.
```sh ```md
cargo install mdbook-admonish > [!NOTE]
> Something worth pointing out.
``` ```
Once you've installed it, you can begin using admonitions in your markdown files. See the [reference][admonish reference]
for more information.
### Spinning it up ### Spinning it up
Now that you've installed the prerequisites, you can run the following command to start a local server: Now that you've installed the prerequisites, you can run the following command to start a local server:
@ -343,8 +339,7 @@ at [`docs/src/assets/css/playground.css`][playground css]. The editor of choice
and the tree-sitter module is fetched from [here][js url]. This, along with the Wasm module and Wasm parsers, live in the and the tree-sitter module is fetched from [here][js url]. This, along with the Wasm module and Wasm parsers, live in the
[.github.io repo][gh.io repo]. [.github.io repo][gh.io repo].
[admonish]: https://github.com/tommilligan/mdbook-admonish [admonitions]: https://rust-lang.github.io/mdBook/format/markdown.html#admonitions
[admonish reference]: https://tommilligan.github.io/mdbook-admonish/reference.html
[binaryen]: https://github.com/WebAssembly/binaryen [binaryen]: https://github.com/WebAssembly/binaryen
[binaryen-releases]: https://github.com/WebAssembly/binaryen/releases [binaryen-releases]: https://github.com/WebAssembly/binaryen/releases
[config crate]: https://crates.io/crates/tree-sitter-config [config crate]: https://crates.io/crates/tree-sitter-config
@ -375,7 +370,6 @@ and the tree-sitter module is fetched from [here][js url]. This, along with the
[playground]: https://github.com/tree-sitter/tree-sitter/blob/master/docs/src/assets/js/playground.js [playground]: https://github.com/tree-sitter/tree-sitter/blob/master/docs/src/assets/js/playground.js
[playground css]: https://github.com/tree-sitter/tree-sitter/blob/master/docs/src/assets/css/playground.css [playground css]: https://github.com/tree-sitter/tree-sitter/blob/master/docs/src/assets/css/playground.css
[podman]: https://podman.io [podman]: https://podman.io
[preprocessor]: https://rust-lang.github.io/mdBook/for_developers/preprocessors.html
[py package]: https://pypi.org/project/tree-sitter [py package]: https://pypi.org/project/tree-sitter
[py ts]: https://github.com/tree-sitter/py-tree-sitter [py ts]: https://github.com/tree-sitter/py-tree-sitter
[pypi]: https://pypi.org [pypi]: https://pypi.org

View file

@ -96,9 +96,8 @@ You can also run playground locally (with your own grammar) using the
<a href="/tree-sitter/cli/playground.html">CLI</a>'s <code>tree-sitter playground</code> subcommand. <a href="/tree-sitter/cli/playground.html">CLI</a>'s <code>tree-sitter playground</code> subcommand.
</p> </p>
```admonish info > [!NOTE]
Logging (if enabled) can be viewed in the browser's console. > Logging (if enabled) can be viewed in the browser's console.
```
<p>The syntax tree should update as you type in the code. As you move around the <p>The syntax tree should update as you type in the code. As you move around the
code, the current node should be highlighted in the tree; you can also click any code, the current node should be highlighted in the tree; you can also click any

View file

@ -1,348 +0,0 @@
@charset "UTF-8";
:is(.admonition) {
display: flow-root;
margin: 1.5625em 0;
padding: 0 1.2rem;
color: var(--fg);
page-break-inside: avoid;
background-color: var(--bg);
border: 0 solid black;
border-inline-start-width: 0.4rem;
border-radius: 0.2rem;
box-shadow: 0 0.2rem 1rem rgba(0, 0, 0, 0.05), 0 0 0.1rem rgba(0, 0, 0, 0.1);
}
@media print {
:is(.admonition) {
box-shadow: none;
}
}
:is(.admonition) > * {
box-sizing: border-box;
}
:is(.admonition) :is(.admonition) {
margin-top: 1em;
margin-bottom: 1em;
}
:is(.admonition) > .tabbed-set:only-child {
margin-top: 0;
}
html :is(.admonition) > :last-child {
margin-bottom: 1.2rem;
}
a.admonition-anchor-link {
display: none;
position: absolute;
left: -1.2rem;
padding-right: 1rem;
}
a.admonition-anchor-link:link, a.admonition-anchor-link:visited {
color: var(--fg);
}
a.admonition-anchor-link:link:hover, a.admonition-anchor-link:visited:hover {
text-decoration: none;
}
a.admonition-anchor-link::before {
content: "§";
}
:is(.admonition-title, summary.admonition-title) {
position: relative;
min-height: 4rem;
margin-block: 0;
margin-inline: -1.6rem -1.2rem;
padding-block: 0.8rem;
padding-inline: 4.4rem 1.2rem;
font-weight: 700;
background-color: rgba(68, 138, 255, 0.1);
print-color-adjust: exact;
-webkit-print-color-adjust: exact;
display: flex;
}
:is(.admonition-title, summary.admonition-title) p {
margin: 0;
}
html :is(.admonition-title, summary.admonition-title):last-child {
margin-bottom: 0;
}
:is(.admonition-title, summary.admonition-title)::before {
position: absolute;
top: 0.625em;
inset-inline-start: 1.6rem;
width: 2rem;
height: 2rem;
background-color: #448aff;
print-color-adjust: exact;
-webkit-print-color-adjust: exact;
mask-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"></svg>');
-webkit-mask-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"></svg>');
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-size: contain;
content: "";
}
:is(.admonition-title, summary.admonition-title):hover a.admonition-anchor-link {
display: initial;
}
details.admonition > summary.admonition-title::after {
position: absolute;
top: 0.625em;
inset-inline-end: 1.6rem;
height: 2rem;
width: 2rem;
background-color: currentcolor;
mask-image: var(--md-details-icon);
-webkit-mask-image: var(--md-details-icon);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-size: contain;
content: "";
transform: rotate(0deg);
transition: transform 0.25s;
}
details[open].admonition > summary.admonition-title::after {
transform: rotate(90deg);
}
:root {
--md-details-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42Z'/></svg>");
}
:root {
--md-admonition-icon--admonish-note: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25z'/></svg>");
--md-admonition-icon--admonish-abstract: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17 9H7V7h10m0 6H7v-2h10m-3 6H7v-2h7M12 3a1 1 0 0 1 1 1 1 1 0 0 1-1 1 1 1 0 0 1-1-1 1 1 0 0 1 1-1m7 0h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2z'/></svg>");
--md-admonition-icon--admonish-info: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M13 9h-2V7h2m0 10h-2v-6h2m-1-9A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2z'/></svg>");
--md-admonition-icon--admonish-tip: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17.66 11.2c-.23-.3-.51-.56-.77-.82-.67-.6-1.43-1.03-2.07-1.66C13.33 7.26 13 4.85 13.95 3c-.95.23-1.78.75-2.49 1.32-2.59 2.08-3.61 5.75-2.39 8.9.04.1.08.2.08.33 0 .22-.15.42-.35.5-.23.1-.47.04-.66-.12a.58.58 0 0 1-.14-.17c-1.13-1.43-1.31-3.48-.55-5.12C5.78 10 4.87 12.3 5 14.47c.06.5.12 1 .29 1.5.14.6.41 1.2.71 1.73 1.08 1.73 2.95 2.97 4.96 3.22 2.14.27 4.43-.12 6.07-1.6 1.83-1.66 2.47-4.32 1.53-6.6l-.13-.26c-.21-.46-.77-1.26-.77-1.26m-3.16 6.3c-.28.24-.74.5-1.1.6-1.12.4-2.24-.16-2.9-.82 1.19-.28 1.9-1.16 2.11-2.05.17-.8-.15-1.46-.28-2.23-.12-.74-.1-1.37.17-2.06.19.38.39.76.63 1.06.77 1 1.98 1.44 2.24 2.8.04.14.06.28.06.43.03.82-.33 1.72-.93 2.27z'/></svg>");
--md-admonition-icon--admonish-success: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m9 20.42-6.21-6.21 2.83-2.83L9 14.77l9.88-9.89 2.83 2.83L9 20.42z'/></svg>");
--md-admonition-icon--admonish-question: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m15.07 11.25-.9.92C13.45 12.89 13 13.5 13 15h-2v-.5c0-1.11.45-2.11 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41a2 2 0 0 0-2-2 2 2 0 0 0-2 2H8a4 4 0 0 1 4-4 4 4 0 0 1 4 4 3.2 3.2 0 0 1-.93 2.25M13 19h-2v-2h2M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10c0-5.53-4.5-10-10-10z'/></svg>");
--md-admonition-icon--admonish-warning: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M13 14h-2V9h2m0 9h-2v-2h2M1 21h22L12 2 1 21z'/></svg>");
--md-admonition-icon--admonish-failure: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20 6.91 17.09 4 12 9.09 6.91 4 4 6.91 9.09 12 4 17.09 6.91 20 12 14.91 17.09 20 20 17.09 14.91 12 20 6.91z'/></svg>");
--md-admonition-icon--admonish-danger: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M11 15H6l7-14v8h5l-7 14v-8z'/></svg>");
--md-admonition-icon--admonish-bug: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M14 12h-4v-2h4m0 6h-4v-2h4m6-6h-2.81a5.985 5.985 0 0 0-1.82-1.96L17 4.41 15.59 3l-2.17 2.17a6.002 6.002 0 0 0-2.83 0L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8z'/></svg>");
--md-admonition-icon--admonish-example: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M7 13v-2h14v2H7m0 6v-2h14v2H7M7 7V5h14v2H7M3 8V5H2V4h2v4H3m-1 9v-1h3v4H2v-1h2v-.5H3v-1h1V17H2m2.25-7a.75.75 0 0 1 .75.75c0 .2-.08.39-.21.52L3.12 13H5v1H2v-.92L4 11H2v-1h2.25z'/></svg>");
--md-admonition-icon--admonish-quote: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M14 17h3l2-4V7h-6v6h3M6 17h3l2-4V7H5v6h3l-2 4z'/></svg>");
}
:is(.admonition):is(.admonish-note) {
border-color: #448aff;
}
:is(.admonish-note) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(68, 138, 255, 0.1);
}
:is(.admonish-note) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #448aff;
mask-image: var(--md-admonition-icon--admonish-note);
-webkit-mask-image: var(--md-admonition-icon--admonish-note);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-abstract, .admonish-summary, .admonish-tldr) {
border-color: #00b0ff;
}
:is(.admonish-abstract, .admonish-summary, .admonish-tldr) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 176, 255, 0.1);
}
:is(.admonish-abstract, .admonish-summary, .admonish-tldr) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00b0ff;
mask-image: var(--md-admonition-icon--admonish-abstract);
-webkit-mask-image: var(--md-admonition-icon--admonish-abstract);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-info, .admonish-todo) {
border-color: #00b8d4;
}
:is(.admonish-info, .admonish-todo) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 184, 212, 0.1);
}
:is(.admonish-info, .admonish-todo) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00b8d4;
mask-image: var(--md-admonition-icon--admonish-info);
-webkit-mask-image: var(--md-admonition-icon--admonish-info);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-tip, .admonish-hint, .admonish-important) {
border-color: #00bfa5;
}
:is(.admonish-tip, .admonish-hint, .admonish-important) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 191, 165, 0.1);
}
:is(.admonish-tip, .admonish-hint, .admonish-important) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00bfa5;
mask-image: var(--md-admonition-icon--admonish-tip);
-webkit-mask-image: var(--md-admonition-icon--admonish-tip);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-success, .admonish-check, .admonish-done) {
border-color: #00c853;
}
:is(.admonish-success, .admonish-check, .admonish-done) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 200, 83, 0.1);
}
:is(.admonish-success, .admonish-check, .admonish-done) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00c853;
mask-image: var(--md-admonition-icon--admonish-success);
-webkit-mask-image: var(--md-admonition-icon--admonish-success);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-question, .admonish-help, .admonish-faq) {
border-color: #64dd17;
}
:is(.admonish-question, .admonish-help, .admonish-faq) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(100, 221, 23, 0.1);
}
:is(.admonish-question, .admonish-help, .admonish-faq) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #64dd17;
mask-image: var(--md-admonition-icon--admonish-question);
-webkit-mask-image: var(--md-admonition-icon--admonish-question);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-warning, .admonish-caution, .admonish-attention) {
border-color: #ff9100;
}
:is(.admonish-warning, .admonish-caution, .admonish-attention) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(255, 145, 0, 0.1);
}
:is(.admonish-warning, .admonish-caution, .admonish-attention) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #ff9100;
mask-image: var(--md-admonition-icon--admonish-warning);
-webkit-mask-image: var(--md-admonition-icon--admonish-warning);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-failure, .admonish-fail, .admonish-missing) {
border-color: #ff5252;
}
:is(.admonish-failure, .admonish-fail, .admonish-missing) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(255, 82, 82, 0.1);
}
:is(.admonish-failure, .admonish-fail, .admonish-missing) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #ff5252;
mask-image: var(--md-admonition-icon--admonish-failure);
-webkit-mask-image: var(--md-admonition-icon--admonish-failure);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-danger, .admonish-error) {
border-color: #ff1744;
}
:is(.admonish-danger, .admonish-error) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(255, 23, 68, 0.1);
}
:is(.admonish-danger, .admonish-error) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #ff1744;
mask-image: var(--md-admonition-icon--admonish-danger);
-webkit-mask-image: var(--md-admonition-icon--admonish-danger);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-bug) {
border-color: #f50057;
}
:is(.admonish-bug) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(245, 0, 87, 0.1);
}
:is(.admonish-bug) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #f50057;
mask-image: var(--md-admonition-icon--admonish-bug);
-webkit-mask-image: var(--md-admonition-icon--admonish-bug);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-example) {
border-color: #7c4dff;
}
:is(.admonish-example) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(124, 77, 255, 0.1);
}
:is(.admonish-example) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #7c4dff;
mask-image: var(--md-admonition-icon--admonish-example);
-webkit-mask-image: var(--md-admonition-icon--admonish-example);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.admonish-quote, .admonish-cite) {
border-color: #9e9e9e;
}
:is(.admonish-quote, .admonish-cite) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(158, 158, 158, 0.1);
}
:is(.admonish-quote, .admonish-cite) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #9e9e9e;
mask-image: var(--md-admonition-icon--admonish-quote);
-webkit-mask-image: var(--md-admonition-icon--admonish-quote);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
.navy :is(.admonition) {
background-color: var(--sidebar-bg);
}
.ayu :is(.admonition),
.coal :is(.admonition) {
background-color: var(--theme-hover);
}
.rust :is(.admonition) {
background-color: var(--sidebar-bg);
color: var(--sidebar-fg);
}
.rust .admonition-anchor-link:link, .rust .admonition-anchor-link:visited {
color: var(--sidebar-fg);
}

View file

@ -11,9 +11,8 @@ These directories are created in the "default" location for your platform:
* On Unix, `$XDG_CONFIG_HOME/tree-sitter` or `$HOME/.config/tree-sitter` * On Unix, `$XDG_CONFIG_HOME/tree-sitter` or `$HOME/.config/tree-sitter`
* On Windows, `%APPDATA%\tree-sitter` or `$HOME\AppData\Roaming\tree-sitter` * On Windows, `%APPDATA%\tree-sitter` or `$HOME\AppData\Roaming\tree-sitter`
```admonish info > [!NOTE]
The CLI will work if there's no config file present, falling back on default values for each configuration option. > The CLI will work if there's no config file present, falling back on default values for each configuration option.
```
When you run the `init-config` command, it will print out the location of the file that it creates so that you can easily When you run the `init-config` command, it will print out the location of the file that it creates so that you can easily
find and modify it. find and modify it.
@ -117,9 +116,8 @@ An example theme can be seen below:
The [`tree-sitter parse`](./parse.md) command will output a pretty-printed CST when the `-c/--cst` option is used. You can The [`tree-sitter parse`](./parse.md) command will output a pretty-printed CST when the `-c/--cst` option is used. You can
control what colors are used for various parts of the tree in your configuration file. control what colors are used for various parts of the tree in your configuration file.
```admonish note > [!NOTE]
Omitting a field will cause the relevant text to be rendered with its default color. > Omitting a field will cause the relevant text to be rendered with its default color.
```
An example parse theme can be seen below: An example parse theme can be seen below:

View file

@ -6,10 +6,9 @@ The `playground` command allows you to start a local playground to test your par
tree-sitter playground [OPTIONS] # Aliases: play, pg, web-ui tree-sitter playground [OPTIONS] # Aliases: play, pg, web-ui
``` ```
```admonish note > [!NOTE]
For this to work, you must have already built the parser as a Wasm module. This can be done with the [`build`](./build.md) > For this to work, you must have already built the parser as a Wasm module. This can be done with the [`build`](./build.md)
subcommand (`tree-sitter build --wasm`). > subcommand (`tree-sitter build --wasm`).
```
## Options ## Options

View file

@ -36,9 +36,8 @@ If `--lib-path` is used, the name of the language used to extract the library's
Update the expected output of tests. Update the expected output of tests.
```admonish info > [!NOTE]
Tests containing `ERROR` nodes or `MISSING` nodes will not be updated. > Tests containing `ERROR` nodes or `MISSING` nodes will not be updated.
```
### `-d/--debug` ### `-d/--debug`

View file

@ -37,13 +37,11 @@ mkdir tree-sitter-${LOWER_PARSER_NAME}
cd tree-sitter-${LOWER_PARSER_NAME} cd tree-sitter-${LOWER_PARSER_NAME}
``` ```
```admonish note > [!NOTE]
The `LOWER_` prefix here means the "lowercase" name of the language. > The `LOWER_` prefix here means the "lowercase" name of the language.
```
```admonish warning > [!WARNING]
Dashes are not permitted via the CLI's `init` command and should not be used in parser names. > Dashes are not permitted via the CLI's `init` command and should not be used in parser names.
```
### Init ### Init
@ -78,10 +76,9 @@ export default grammar({
}); });
``` ```
```admonish info > [!NOTE]
The placeholders shown above would be replaced with the corresponding data you provided in the `init` sub-command's > The placeholders shown above would be replaced with the corresponding data you provided in the `init` sub-command's
prompts. > prompts.
```
To learn more about this command, check the [reference page](../cli/init.md). To learn more about this command, check the [reference page](../cli/init.md).

View file

@ -20,20 +20,19 @@ DSL through the `RustRegex` class. Simply pass your regex pattern as a string:
accepts a single pattern string. While it doesn't support separate flags, you can use inline flags within the pattern accepts a single pattern string. While it doesn't support separate flags, you can use inline flags within the pattern
itself. For more details about Rust's regex syntax and capabilities, check out the [Rust regex documentation][rust regex]. itself. For more details about Rust's regex syntax and capabilities, check out the [Rust regex documentation][rust regex].
```admonish note > [!NOTE]
Only a subset of the Regex engine is actually supported. This is due to certain features like lookahead and lookaround > Only a subset of the Regex engine is actually supported. This is due to certain features like lookahead and lookaround
assertions not being feasible to use in an LR(1) grammar, as well as certain flags being unnecessary for tree-sitter. However, > assertions not being feasible to use in an LR(1) grammar, as well as certain flags being unnecessary for tree-sitter. However,
plenty of features are supported by default: > plenty of features are supported by default:
>
- Character classes > - Character classes
- Character ranges > - Character ranges
- Character sets > - Character sets
- Quantifiers > - Quantifiers
- Alternation > - Alternation
- Grouping > - Grouping
- Unicode character escapes > - Unicode character escapes
- Unicode property escapes > - Unicode property escapes
```
- **Sequences : `seq(rule1, rule2, ...)`** — This function creates a rule that matches any number of other rules, one after - **Sequences : `seq(rule1, rule2, ...)`** — This function creates a rule that matches any number of other rules, one after
another. It is analogous to simply writing multiple symbols next to each other in [EBNF notation][ebnf]. another. It is analogous to simply writing multiple symbols next to each other in [EBNF notation][ebnf].

View file

@ -244,11 +244,10 @@ Possible resolutions:
4: Add a conflict for these rules: `binary_expression` `unary_expression` 4: Add a conflict for these rules: `binary_expression` `unary_expression`
``` ```
```admonish hint > [!TIP]
The • character in the error message indicates where exactly during > The • character in the error message indicates where exactly during
parsing the conflict occurs, or in other words, where the parser is encountering > parsing the conflict occurs, or in other words, where the parser is encountering
ambiguity. > ambiguity.
```
For an expression like `-a * b`, it's not clear whether the `-` operator applies to the `a * b` or just to the `a`. This For an expression like `-a * b`, it's not clear whether the `-` operator applies to the `a * b` or just to the `a`. This
is where the `prec` function [described in the previous page][grammar dsl] comes into play. By wrapping a rule with `prec`, is where the `prec` function [described in the previous page][grammar dsl] comes into play. By wrapping a rule with `prec`,
@ -364,11 +363,10 @@ In such cases, we want the parser to explore both possibilities by explicitly de
} }
``` ```
```admonish note > [!NOTE]
The example is a bit contrived for the purpose of illustrating the usage of conflicts. The actual JavaScript grammar isn't > The example is a bit contrived for the purpose of illustrating the usage of conflicts. The actual JavaScript grammar isn't
structured like that, but this conflict is actually present in the > structured like that, but this conflict is actually present in the
[Tree-sitter JavaScript grammar](https://github.com/tree-sitter/tree-sitter-javascript/blob/108b2d4d17a04356a340aea809e4dd5b801eb40d/grammar.js#L100). > [Tree-sitter JavaScript grammar](https://github.com/tree-sitter/tree-sitter-javascript/blob/108b2d4d17a04356a340aea809e4dd5b801eb40d/grammar.js#L100).
```
## Hiding Rules ## Hiding Rules
@ -420,11 +418,10 @@ module.exports = grammar({
}); });
``` ```
```admonish warning > [!WARNING]
When adding more complicated tokens to `extras`, it's preferable to associate the pattern > When adding more complicated tokens to `extras`, it's preferable to associate the pattern
with a rule. This way, you avoid the lexer inlining this pattern in a bunch of spots, > with a rule. This way, you avoid the lexer inlining this pattern in a bunch of spots,
which can dramatically reduce the parser size. > which can dramatically reduce the parser size.
```
For example, instead of defining the `comment` token inline in `extras`: For example, instead of defining the `comment` token inline in `extras`:
@ -471,10 +468,9 @@ module.exports = grammar({
}); });
``` ```
```admonish note > [!NOTE]
Tree-sitter intentionally simplifies the whitespace character class, `\s`, to `[ \t\n\r]` as a performance > Tree-sitter intentionally simplifies the whitespace character class, `\s`, to `[ \t\n\r]` as a performance
optimization. This is because typically users do not require the full Unicode definition of whitespace. > optimization. This is because typically users do not require the full Unicode definition of whitespace.
```
## Using Supertypes ## Using Supertypes
@ -520,12 +516,11 @@ module.exports = grammar({
Although supertype rules are hidden from the syntax tree, they can still be used in queries. See the chapter on Although supertype rules are hidden from the syntax tree, they can still be used in queries. See the chapter on
[Query Syntax][query syntax] for more information. [Query Syntax][query syntax] for more information.
```admonish warning > [!WARNING]
Aliasing a supertype rule makes the node in the alias match the supertype in > Aliasing a supertype rule makes the node in the alias match the supertype in
name only and will not be treated as a supertype. For `alias($.foo, $.bar)` a > name only and will not be treated as a supertype. For `alias($.foo, $.bar)` a
query targeting `bar` will not transparently match the supertype's subtypes the > query targeting `bar` will not transparently match the supertype's subtypes the
way a query targeting `foo` would. > way a query targeting `foo` would.
```
# Lexical Analysis # Lexical Analysis
@ -637,11 +632,10 @@ It would then correctly recognize the code as invalid.
Aside from improving error detection, keyword extraction also has performance benefits. It allows Tree-sitter to generate Aside from improving error detection, keyword extraction also has performance benefits. It allows Tree-sitter to generate
a smaller, simpler lexing function, which means that **the parser will compile much more quickly**. a smaller, simpler lexing function, which means that **the parser will compile much more quickly**.
```admonish note > [!NOTE]
The word token must be a unique token that is not reused by another rule. If you want to have a word token used in a > The word token must be a unique token that is not reused by another rule. If you want to have a word token used in a
rule that's called something else, you should just alias the word token instead, like how the Rust grammar does it > rule that's called something else, you should just alias the word token instead, like how the Rust grammar does it
<a href="https://github.com/tree-sitter/tree-sitter-rust/blob/1f63b33efee17e833e0ea29266dd3d713e27e321/grammar.js#L1605">here</a> > <a href="https://github.com/tree-sitter/tree-sitter-rust/blob/1f63b33efee17e833e0ea29266dd3d713e27e321/grammar.js#L1605">here</a>
```
[ambiguous-grammar]: https://en.wikipedia.org/wiki/Ambiguous_grammar [ambiguous-grammar]: https://en.wikipedia.org/wiki/Ambiguous_grammar
[antlr]: https://www.antlr.org [antlr]: https://www.antlr.org

View file

@ -224,11 +224,10 @@ array macros from `tree_sitter/array.h`.
There are quite a few of them provided for you, but here's how you could get started tracking some state. Check out the header There are quite a few of them provided for you, but here's how you could get started tracking some state. Check out the header
itself for more detailed documentation. itself for more detailed documentation.
```admonish attention > [!WARNING]
Do not use any of the array functions or macros that are prefixed with an underscore and have comments saying > Do not use any of the array functions or macros that are prefixed with an underscore and have comments saying
that it is not what you are looking for. These are internal functions used as helpers by other macros that are public. > that it is not what you are looking for. These are internal functions used as helpers by other macros that are public.
They are not meant to be used directly, nor are they what you want. > They are not meant to be used directly, nor are they what you want.
```
```c ```c
#include "tree_sitter/parser.h" #include "tree_sitter/parser.h"
@ -370,13 +369,12 @@ However, when you use rule references (like `$.if_keyword`) in the externals arr
in the grammar, Tree-sitter cannot fall back to its internal lexer. In this case, the external scanner is solely responsible in the grammar, Tree-sitter cannot fall back to its internal lexer. In this case, the external scanner is solely responsible
for recognizing these tokens. for recognizing these tokens.
```admonish danger > [!CAUTION]
- External scanners can easily create infinite loops > - External scanners can easily create infinite loops
>
- Be extremely careful when emitting zero-width tokens > - Be extremely careful when emitting zero-width tokens
>
- Always use the `eof` function when looping through characters > - Always use the `eof` function when looping through characters
```
[ejs]: https://ejs.co [ejs]: https://ejs.co
[enum]: https://en.wikipedia.org/wiki/Enumerated_type#C [enum]: https://en.wikipedia.org/wiki/Enumerated_type#C

View file

@ -33,10 +33,9 @@ func x() int {
* Then, the **expected output syntax tree** is written as an [S-expression][s-exp]. The exact placement of whitespace in * Then, the **expected output syntax tree** is written as an [S-expression][s-exp]. The exact placement of whitespace in
the S-expression doesn't matter, but ideally the syntax tree should be legible. the S-expression doesn't matter, but ideally the syntax tree should be legible.
```admonish tip > [!TIP]
The S-expression does not show syntax nodes like `func`, `(` and `;`, which are expressed as strings and regexes in the grammar. > The S-expression does not show syntax nodes like `func`, `(` and `;`, which are expressed as strings and regexes in the grammar.
It only shows the *named* nodes, as described in [this section][named-vs-anonymous-nodes] of the page on parser usage. > It only shows the *named* nodes, as described in [this section][named-vs-anonymous-nodes] of the page on parser usage.
```
The expected output section can also *optionally* show the [*field names*][node-field-names] associated with each child The expected output section can also *optionally* show the [*field names*][node-field-names] associated with each child
node. To include field names in your tests, you write a node's field name followed by a colon, before the node itself node. To include field names in your tests, you write a node's field name followed by a colon, before the node itself
@ -109,20 +108,18 @@ The recommendation is to be comprehensive in adding tests. If it's a visible nod
directory. It's typically a good idea to test all the permutations of each language construct. This increases test coverage, directory. It's typically a good idea to test all the permutations of each language construct. This increases test coverage,
but doubly acquaints readers with a way to examine expected outputs and understand the "edges" of a language. but doubly acquaints readers with a way to examine expected outputs and understand the "edges" of a language.
```admonish tip > [!TIP]
After modifying the grammar, you can run `tree-sitter test -u` > After modifying the grammar, you can run `tree-sitter test -u`
to update all syntax trees in corpus files with current parser output. > to update all syntax trees in corpus files with current parser output.
```
## Attributes ## Attributes
Tests can be annotated with a few `attributes`. Attributes must be put in the header, below the test name, and start with Tests can be annotated with a few `attributes`. Attributes must be put in the header, below the test name, and start with
a `:`. A couple of attributes also take in a parameter, which require the use of parenthesis. a `:`. A couple of attributes also take in a parameter, which require the use of parenthesis.
```admonish tip > [!TIP]
If you'd like to supply in multiple parameters, e.g. to run tests on multiple platforms or to test multiple languages, > If you'd like to supply in multiple parameters, e.g. to run tests on multiple platforms or to test multiple languages,
you can repeat the attribute on a new line. > you can repeat the attribute on a new line.
```
The following attributes are available: The following attributes are available:

View file

@ -54,9 +54,8 @@ typedef uint32_t (*TSDecodeFunction)(
); );
``` ```
```admonish attention > [!WARNING]
The `TSInputEncoding` must be set to `TSInputEncodingCustom` for the `decode` function to be called. > The `TSInputEncoding` must be set to `TSInputEncodingCustom` for the `decode` function to be called.
```
The `string` argument is a pointer to the text to decode, which comes from the `read` function, and the `length` argument The `string` argument is a pointer to the text to decode, which comes from the `read` function, and the `length` argument
is the length of the `string`. The `code_point` argument is a pointer to an integer that represents the decoded code point, is the length of the `string`. The `code_point` argument is a pointer to an integer that represents the decoded code point,
@ -87,9 +86,8 @@ TSPoint ts_node_start_point(TSNode);
TSPoint ts_node_end_point(TSNode); TSPoint ts_node_end_point(TSNode);
``` ```
```admonish note > [!NOTE]
A *newline* is considered to be a single line feed (`\n`) character. > A *newline* is considered to be a single line feed (`\n`) character.
```
## Retrieving Nodes ## Retrieving Nodes

View file

@ -156,9 +156,8 @@ Internally, copying a syntax tree just entails incrementing an atomic reference
tree which you can freely query, edit, reparse, or delete on a new thread while continuing to use the original tree on a tree which you can freely query, edit, reparse, or delete on a new thread while continuing to use the original tree on a
different thread. different thread.
```admonish danger > [!CAUTION]
Individual `TSTree` instances are _not_ thread safe; you must copy a tree if you want to use it on multiple threads simultaneously. > Individual `TSTree` instances are _not_ thread safe; you must copy a tree if you want to use it on multiple threads simultaneously.
```
[ejs]: https://ejs.co [ejs]: https://ejs.co
[erb]: https://ruby-doc.org/stdlib-2.5.1/libdoc/erb/rdoc/ERB.html [erb]: https://ruby-doc.org/stdlib-2.5.1/libdoc/erb/rdoc/ERB.html

View file

@ -4,13 +4,12 @@ You can access every node in a syntax tree using the `TSNode` APIs [described ea
to access a large number of nodes, the fastest way to do so is with a _tree cursor_. A cursor is a stateful object that to access a large number of nodes, the fastest way to do so is with a _tree cursor_. A cursor is a stateful object that
allows you to walk a syntax tree with maximum efficiency. allows you to walk a syntax tree with maximum efficiency.
```admonish note > [!NOTE]
The given input node is considered the root of the cursor, and the cursor cannot walk outside this node. > The given input node is considered the root of the cursor, and the cursor cannot walk outside this node.
Going to the parent or any sibling of the root node will always return `false`. > Going to the parent or any sibling of the root node will always return `false`.
>
This has no unexpected effects if the given input node is the actual `root` node of the tree, but is something to keep in > This has no unexpected effects if the given input node is the actual `root` node of the tree, but is something to keep in
mind when using cursors constructed with a node that is not the `root` node. > mind when using cursors constructed with a node that is not the `root` node.
```
You can initialize a cursor from any node: You can initialize a cursor from any node:

View file

@ -186,15 +186,14 @@ To recap about the predicates and directives Tree-sitter's bindings support:
- `#strip!` removes text from a capture - `#strip!` removes text from a capture
```admonish info > [!NOTE]
Predicates and directives are not handled directly by the Tree-sitter C library. > Predicates and directives are not handled directly by the Tree-sitter C library.
They are just exposed in a structured form so that higher-level code can perform > They are just exposed in a structured form so that higher-level code can perform
the filtering. However, higher-level bindings to Tree-sitter like > the filtering. However, higher-level bindings to Tree-sitter like
[the Rust Crate][rust crate] > [the Rust Crate][rust crate]
or the [WebAssembly binding][wasm binding] > or the [WebAssembly binding][wasm binding]
do implement a few common predicates like those explained above. In the future, more "standard" predicates and directives > do implement a few common predicates like those explained above. In the future, more "standard" predicates and directives
may be added. > may be added.
```
[cgo]: https://pkg.go.dev/cmd/cgo [cgo]: https://pkg.go.dev/cmd/cgo
[rust crate]: https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_rust [rust crate]: https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_rust

View file

@ -79,7 +79,6 @@ bool ts_query_cursor_set_containing_byte_range(TSQueryCursor *self, uint32_t sta
bool ts_query_cursor_set_containing_point_range(TSQueryCursor *self, TSPoint start_point, TSPoint end_point); bool ts_query_cursor_set_containing_point_range(TSQueryCursor *self, TSPoint start_point, TSPoint end_point);
``` ```
```admonish note > [!NOTE]
For all of these functions, an end value of zero is treated as unbounded (the maximum possible value). > For all of these functions, an end value of zero is treated as unbounded (the maximum possible value).
This means passing a byte range of `(0, 0)` (or a point range of `{0, 0}, {0, 0}`) will match the entire tree, not an empty range. > This means passing a byte range of `(0, 0)` (or a point range of `{0, 0}, {0, 0}`) will match the entire tree, not an empty range.
```