Commit graph

6516 commits

Author SHA1 Message Date
Will Lillis 5ddf71b9f4 fix(rust)!: expose QueryMatch::captures as a method
The field handed out a slice whose lifetime outlived the streaming-iterator
loan it came from. An accessor reborrowing through `&self` bounds it correctly.

BREAKING CHANGE: In the rust bindings, replace `m.captures` with `m.captures()`.
2026-08-30 02:58:20 -04:00
cuishuang efa0dd9a36 fix(cli): correct zero-based positions for --edits
Some checks failed
CI / checks (push) Waiting to run
CI / sanitize (push) Failing after 15s
CI / build (push) Failing after 16s
CI / check-wasm-stdlib (push) Failing after 15s
Signed-off-by: cuishuang <imcusg@gmail.com>
2026-08-29 21:06:30 -04:00
Christian Clason 16d5e9d227 ci(checks): add lint-toml step using taplo
Some checks failed
CI / checks (push) Waiting to run
CI / sanitize (push) Failing after 14s
CI / build (push) Failing after 15s
CI / check-wasm-stdlib (push) Failing after 14s
Deploy Docs / deploy-docs (push) Has been cancelled
2026-08-29 11:10:37 +02:00
Will Lillis 3ac04a64f7 docs: add taplo instructions 2026-08-29 11:10:37 +02:00
Will Lillis d9cb739430 fix(toml): drop align_entries = true from .taplo.toml
This key was being applied inconsistently depending on nesting level.
2026-08-29 11:10:37 +02:00
Will Lillis 7a2dd61a7c fix(xtask): preserve format padding when updating Cargo.toml files 2026-08-29 11:10:37 +02:00
Christian Clason a520ad0fc3 chore: remove .dockerignore
Fixup for #5872, which missed the hidden file.
2026-08-29 10:30:35 +02:00
Christian Clason da219f40f8 chore: remove Zed editor config
Problem: Editor-specific settings should not be part of the global
repository. (Only config files that control standard tooling in order to
enforce, e.g., formatting policies are appropriate to commit -- and only
if covered by CI.)

Solution: Drop the Zed config files from the repo.
2026-08-29 10:30:35 +02:00
Christian Clason 664e9a6786 build(deps)!: bump wasi-sdk to v34
Some checks failed
CI / checks (push) Waiting to run
Deploy Docs / deploy-docs (push) Waiting to run
CI / sanitize (push) Failing after 15s
CI / build (push) Failing after 15s
CI / check-wasm-stdlib (push) Failing after 14s
Check Bindgen Output / check-bindgen (push) Has been cancelled
Check Wasm Exports / check-wasm-exports (push) Has been cancelled
Breaking change: LLVM 23 replaces `wasm32-wasi` target with
`wasm32-wasip1`, requiring updating the flags used by
`tree-sitter build --wasm`.
2026-08-27 10:35:19 +02:00
Christian Clason fcef970e81 build(deps): bump wasmtime-c-api to v48.0.1 2026-08-27 09:37:57 +02:00
Kyuhwan Lee 8933cb7b40 docs(web): add WASM version compatibility section
Add documentation about version compatibility requirements between
web-tree-sitter parser ABIs for WASM file generation.

This helps users understand why Language.load() might fail when using
pre-built WASM files from third-party packages that were built with
incompatible tree-sitter-cli versions.

Co-authored-by: Will Lillis <will.lillis24@gmail.com>
2026-08-25 17:34:56 -04:00
Will Lillis 82639170a7 docs: specify Emscripten version constraints for web binding builds 2026-08-25 17:34:37 -04:00
dependabot[bot] 129d8cd141 build(deps): bump eslint
Bumps the npm group with 1 update in the /lib/binding_web directory: [eslint](https://github.com/eslint/eslint).


Updates `eslint` from 10.8.1 to 10.9.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Commits](https://github.com/eslint/eslint/compare/v10.8.1...v10.9.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-version: 10.9.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-25 09:59:01 +02:00
dependabot[bot] f3a9521894 build(deps): bump cc from 1.4.3 to 1.4.4 in the cargo group
Bumps the cargo group with 1 update: [cc](https://github.com/rust-lang/cc-rs).


Updates `cc` from 1.4.3 to 1.4.4
- [Release notes](https://github.com/rust-lang/cc-rs/releases)
- [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.4.3...cc-v1.4.4)

---
updated-dependencies:
- dependency-name: cc
  dependency-version: 1.4.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-25 09:58:43 +02:00
Peter Stenger 0be5f898ad fix(web): map Node-only specifiers to false via browser field
Browser bundlers (esbuild, webpack, vite, rollup) statically discover the
`await import("fs/promises")` and `await import("module")` calls in the
shipped ESM bundle and try to resolve them, even though both sit in
Node-only branches that never execute in a browser.

Adding a top-level `browser` field tells bundlers to substitute empty
stubs for these specifiers when targeting the browser. The runtime gates
(`globalThis.process?.versions.node` and `ENVIRONMENT_IS_NODE`) already
prevent the stubs from ever being invoked.

Fixes #5545.
2026-08-25 00:27:50 -04:00
katrinafyi ac17c8d003 playground: set default LANGUAGE_BASE_URL to "." to fix subfolder hosting
Previously with the empty string base URL, the playground would not work when hosted at a subfolder of the domain. This is because playground.js has this code:

      const url = `${LANGUAGE_BASE_URL}/tree-sitter-${newLanguageName}.wasm`;

With an empty string, it would look for wasm at the root of the website and 404.

Github code search shows that this is an issue which lots of people have run into, and everyone has to work around it: https://github.com/search?q=%2FLANGUAGE_BASE_URL+%3D+%22%22%2F+-language%3AHTML&type=code

Related to https://www.github.com/tree-sitter/tree-sitter/issues/5230
2026-08-24 19:41:26 -04:00
Will Lillis c6c137a329 fix(generate): avoid mutating inherited reserved sets
Copy the base grammar's reserved set map before adding or replacing sets
in a derived grammar.
2026-08-23 17:08:31 -04:00
Will Lillis 1cb91662a5 fix(generate): validate symbol-only grammar fields
Require `word`, `conflicts`, `inline`, and `supertypes` callbacks
to return named grammar symbols instead of silently accepting values
that produce undefined names.

Restrict `precedences` lists to named rules and precedence names, and
preserve the existing handling of undefined and duplicate `inline`
rules.
2026-08-23 17:08:31 -04:00
Mike Arndt 7ca101cb7e fix(cli): align grammar DSL declarations with runtime
Model grammar() as returning the evaluated grammar beneath a `grammar`
property, with callbacks replaced by their normalized values and
runtime-initialized fields represented as required properties.

Correct the evaluated rule types for named precedences and regular
expression flags. Narrow symbol-only callbacks such as `conflicts`,
`inline`, `supertypes`, and `word`, and expose the inherited values
passed to `extras` and `reserved` callbacks.

Co-authored-by: Will Lillis <will.lillis24@gmail.com>
2026-08-23 17:08:31 -04:00
Will Lillis dad7d0bd88 generate: use a single buffer for the string pool's backing store
This representation slightly lowers walltime and allocations, but also
makes `StrPool` `Send`.
2026-08-23 14:15:16 -04:00
Will Lillis f9dcb005cd fix(generate)!: use node identities in node-types bookkeeping
Some node-types bookkeeping still used the type name without its named
status. This caused anonymous nodes to inherit extra metadata from named
nodes with the same text, and could create false supertype cycles when a
named supertype and anonymous alias shared a name.

Key extra metadata and supertype dependencies by the complete
(type, named) identity.

Reject named aliases that collide with a canonical supertype. Such an
identity cannot be represented as both a concrete node and an abstract
supertype in node-types.json, and previously caused generation to panic.

All output entries now come from the map keyed by (type, named), so no
two entries can reach the final sort with the same identity. Remove the
unreachable root and extra tie-breakers and the now-redundant deduplication.

BREAKING CHANGE: Alters a public error enum for the generate crate.
2026-08-23 13:40:32 -04:00
Will Lillis 78267a0a96 fix(generate): merge anonymous token aliases in node-types.json
When an anonymous token alias and an anonymous syntax-node alias have
the same name, node-types.json emits two entries with the same type and
named status. For example,

```
alias($._node, "same")
```
and

```
alias("!", "same")
```

produce separate anonymous "same" entries. Add anonymous tokens to
the node-type map instead. When a token shares an identity with a
structured node, retain its possible children and fields but mark
them as optional because the token appearance is a leaf.
2026-08-23 13:40:32 -04:00
Will Lillis 00beb27f83 fix(generate): distinguish named and anonymous node types
A node-types entry is identified by both its type name and its `named`
value. The generator only keyed accumulated entries by name, so aliases
like

    alias($._node, $.same)
    alias($._node, "same")

were incorrectly merged into one entry. Whichever alias was processed
first determined the entry's `named` value, and the structures of two
distinct node types could be combined.

Key accumulated entries by `NodeTypeRef` so named and anonymous nodes
with the same type name remain separate.
2026-08-23 13:40:32 -04:00
Will Lillis 7bd12334c4 fix(generate): include aliased supertypes in node-types.json
Aliasing a supertype makes the aliased occurrence appear as a regular
node in the syntax tree. For example,

```
alias($.expression, $.expression_target)
```

can produce:

```
(expression_target (identifier))
```

Previously, node-types generation skipped the source supertype entirely.
It could reference `expression_target` as a field or child type without
emitting a corresponding top-level entry for it.

Continue emitting the canonical `expression` entry with its `subtypes`,
but pass aliased appearances through regular node generation so their
children and fields are recorded and merged normally.
2026-08-23 13:40:32 -04:00
Will Lillis 54a46eb49b fix(rust): remove must_use attribute from Tree::changed_ranges
`ExactSizeIterator` implements `std::iter::Iterator`, which is already
`must_use`.
2026-08-23 09:45:42 +02:00
Christian Clason 2452dc7a71 chore: remove Dockerfile
Problem: The committed Dockerfile is not used by the standard tooling in
this repo and therefore bitrots freely, which increases maintenance
burden on the (non-Docker-using) maintainers.

Solution: Drop the Dockerfile from the repo.
2026-08-23 00:35:12 -04:00
Amaan Qureshi 74b7d0c951 feat!: add an eof function
This commit adds an `eof()` function for grammars, which is easier to
use than the NUL byte directly. It compiles down to a constraint that
the enclosing production can only reduce at end of input, not to a
shiftable token.

BREAKING CHANGE: Public error types for `tree-sitter-generate` were modified.

Co-authored-by: Will Lillis <will.lillis24@gmail.com>
2026-08-21 20:02:58 -04:00
Will Lillis baad4174e5 fix(generate)!: hold IoError inside GenerateError::GrammarPath 2026-08-20 22:11:42 -04:00
Will Lillis cde84508ac fix(generate)!: error when nonexistent _file_ path is passed to
`generate_parser_in_directory`.
2026-08-20 22:11:42 -04:00
Max Brunsfeld 43623ec9bf
Upgrade to latest wasmtime, improve robustness and perf of wasm-based parsing (#5847)
* build(deps): upgrade wasmtime C API to 48.0.0

Upgrade the Rust and Zig Wasmtime dependencies and enable reference values with the null GC collector.

Wasmtime 48 requires a newer Rust toolchain, whose Clippy version identifies three item helpers that can be const. Mark them const so the workspace continues to pass Clippy with warnings denied.

* feat(benchmark): support Wasm grammars

* perf(wasm): cache language function handles

* fix(wasm): improve validation and failure cleanup

Bounds-check dylink metadata parsing, require exact import and export names, and restore memory and function-table allocation offsets when language loading fails.

* fix(wasm): copy the complete supertype map
2026-08-20 21:02:11 +00:00
Will Lillis fe3fe327e2 fix(generate): correct test assertion for inlined supertype warning 2026-08-20 02:47:10 -04:00
Will Lillis 03ae6710cd fix(ci): run all workspace tests
Without `--workspace`, all generate tests were silently skipped.
2026-08-20 02:47:10 -04:00
Amaan Qureshi 067f85e5a2 generate: hold StrIds in node-types JSON output
The JSON output types now hold ids from the string pool instead of
cloning into owned `String`s, which makes `NodeTypeJSON` `Copy` and
drops most allocations when building the output.

Co-authored-by: Will Lillis <will.lillis24@gmail.com>
2026-08-19 20:30:17 -04:00
Amaan Qureshi 5800563fe7 generate: refactor get_variable_info and generate_node_types_json
This splits both functions into small, focused helpers with no
behavioral change.
2026-08-19 20:30:17 -04:00
Amaan Qureshi 14c158bbba generate: warn when a symbol is both a supertype and inlined
Currently, a symbol listed in both `supertypes` and `inline` produces
a phantom supertype entry in `node-types.json` for a rule that can
never appear in a tree. `intern_symbols` now drops the supertype with
a warning. A hard error would break 29 published grammars, including
python, go, ruby, rust, and scala, so that that decision is deferred
to the next breaking release. Fixes #5218
2026-08-19 20:30:17 -04:00
dependabot[bot] f235c2f1c3 build(deps): bump the cargo group with 4 updates
Bumps the cargo group with 4 updates: [bstr](https://github.com/BurntSushi/bstr), [cc](https://github.com/rust-lang/cc-rs), [clap_complete_nushell](https://github.com/clap-rs/clap) and [thiserror](https://github.com/dtolnay/thiserror).


Updates `bstr` from 1.13.0 to 1.13.1
- [Commits](https://github.com/BurntSushi/bstr/compare/1.13.0...1.13.1)

Updates `cc` from 1.4.2 to 1.4.3
- [Release notes](https://github.com/rust-lang/cc-rs/releases)
- [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.4.2...cc-v1.4.3)

Updates `clap_complete_nushell` from 4.6.1 to 4.6.2
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete_nushell-v4.6.1...clap_complete_nushell-v4.6.2)

Updates `thiserror` from 2.0.19 to 2.0.20
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/2.0.19...2.0.20)

---
updated-dependencies:
- dependency-name: bstr
  dependency-version: 1.13.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: cc
  dependency-version: 1.4.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: clap_complete_nushell
  dependency-version: 4.6.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: thiserror
  dependency-version: 2.0.20
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-18 10:39:56 +02:00
dependabot[bot] 95eaaa2130 build(deps): bump the npm group across 1 directory with 3 updates
Bumps the npm group with 3 updates in the /lib/binding_web directory: [esbuild](https://github.com/evanw/esbuild), [tsx](https://github.com/privatenumber/tsx) and [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint).


Updates `esbuild` from 0.28.1 to 0.28.2
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG.md)
- [Commits](https://github.com/evanw/esbuild/compare/v0.28.1...v0.28.2)

Updates `tsx` from 4.23.11 to 4.23.12
- [Release notes](https://github.com/privatenumber/tsx/releases)
- [Changelog](https://github.com/privatenumber/tsx/blob/master/release.config.cjs)
- [Commits](https://github.com/privatenumber/tsx/compare/v4.23.11...v4.23.12)

Updates `typescript-eslint` from 8.66.0 to 8.67.0
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.67.0/packages/typescript-eslint)

---
updated-dependencies:
- dependency-name: esbuild
  dependency-version: 0.28.2
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: tsx
  dependency-version: 4.23.12
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: typescript-eslint
  dependency-version: 8.67.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-18 10:37:31 +02:00
dependabot[bot] dff1fd868c build(deps): bump esbuild and vite in /lib/binding_web
Bumps [esbuild](https://github.com/evanw/esbuild) and [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite). These dependencies needed to be updated together.

Updates `esbuild` from 0.27.7 to 0.28.1
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG.md)
- [Commits](https://github.com/evanw/esbuild/compare/v0.27.7...v0.28.1)

Updates `vite` from 7.3.2 to 7.3.6
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v7.3.6/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v7.3.6/packages/vite)

---
updated-dependencies:
- dependency-name: esbuild
  dependency-version: 0.28.1
  dependency-type: indirect
- dependency-name: vite
  dependency-version: 7.3.6
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-15 10:13:38 +02:00
Max Brunsfeld 0e2af0d8d1
Allow using Tree-sitter rust lib in multi-threaded web apps compiled to wasm32-unknown-unknown (#5851)
* feat(wasm): make syntax trees sendable

* test(wasm): transfer trees across workers

* test(wasm): use JSON grammar for tree transfer

* test(wasm): edit trees across workers

* test(wasm): share dlmalloc with tree-sitter

* test(wasm): simplify worker tree exchange

* test(wasm): drive tree exchange from Rust

* test(wasm): split sendable-tree xtask

* test(wasm): generalize Rust web fixture

* test(wasm): exercise parallel Rust tree access

* fix(wasm): use Rust global allocator for C core

* test(wasm): use default Rust allocator

* feat(wasm): support external scanners in Rust web apps

* Simplify example further, add a readme

* Regenerate wasm-stdlib

* Fix wasm_stdlib check script

* Vendor the Wasm standard library subset

* Test Unicode Ruby scanner behavior in Wasm

* Make Wasm tree languages instance-aware

* Test multi-threaded use of queries in wasm32-unknown

* Refactor reference-counted language storage

* Check ABI version compat before loading rest of language

* 🎨 Remove redundant #ifdef block

* Reject unsupported Rust Wasm builds on 0.26
2026-08-14 17:05:42 -07:00
Will Lillis 21e3614b8d perf(lib): fast path for ASCII characters in ts_lexer__advance
Yields a 0-5% improvement on parse speed (very grammar dependent).
2026-08-14 18:11:27 +02:00
Will Lillis 730946cfd5 perf(lib): fast path for ASCII characters in ts_lexer__get_lookahead
Yields a ~2% improvement on parse speed.
2026-08-14 18:11:27 +02:00
Christian Clason 277f53f886 build(swift)!: drop Package.swift
Problem: `Package.swift` build script is unmaintained and leads to build
errors.

Solution: Remove `Package.swift`; downstream tools should rely on the
swift-tree-sitter bindings (or, if they want a custom bare-metal build,
handle this in their own build scripts).
2026-08-14 12:51:38 +02:00
Christian Clason f8e735212b build(deps): bump binaryen to v132 2026-08-14 09:33:39 +02:00
Tim Vermeulen f30ee2b300 fix(parser): nest error children during recovery 2026-08-14 00:51:11 -04:00
Tim Vermeulen 869638f6cf fix(lib): accumulate error costs through hidden error nodes 2026-08-14 00:51:11 -04:00
Will Lillis c279989118 fix(xtask): check for vitest rather than chai and mocha
`test::run_wasm` gated dependency installation on `node_modules/chai` and
`node_modules/mocha`. Neither is a dependency (vitest is used instead),
so the check never passed and every `cargo xtask test-wasm`
reran `npm install`.
2026-08-14 00:13:54 -04:00
Will Lillis c68605f18d fix(rust)!: tie language string lifetimes to the proper containers
`Node::kind`, `Node::grammar_name`, the field name accessors,
`TreeCursor::field_name`, and the `Language` name lookups returned `&'static
str` while pointing into storage owned by the `TSLanguage`. Releasing the last
handle to a Wasm language frees that storage.

`Node` and `TreeCursor` now return `&'tree str`, which is ok because
`ts_tree_new` takes a reference to the language via `ts_language_copy` and
holds it until `ts_tree_delete`. The `Language` lookups return strings borrowed
from `&self`.
2026-08-14 00:13:54 -04:00
Will Lillis 7be497a14e fix(web)!: report null when lookahead iterator is not positioned
`currentType` and `currentTypeId` return `null` before the first iteration
step, after exhaustion, and after a reset.

`currentType` also falls back to the language's own name table instead of the
literal 'ERROR' when `Language.types` has no entry (auxiliary symbols). Other
bindings report `end` where this one reported 'ERROR'.
2026-08-14 00:13:54 -04:00
Will Lillis 081929092f fix(rust)!: make lookahead accessors fallible and iteration fused
`current_symbol` and `current_symbol_name` return an `Option` (`None` when the
iterator is not positioned on a symbol). Change `iter_names`'s item from
`&'static str` to `&str`.
2026-08-14 00:13:54 -04:00
Will Lillis 7bf4a10995 fix(lib)!: make lookahead iterator exhaustion sticky and retain its language
Track the iterator's phase so exhaustion is sticky, and gate the symbol name on
it, so `NULL` means "not positioned on a symbol".

`ts_lookahead_iterator_new` was also the only language consuming constructor
that did not `ts_language_copy`, so an iterator outliving a wasm language read
freed memory. Retain in `_new` and `_reset`, release in `_delete`.

Previously:
- `ts_lookahead_iterator__next` left a small parse state's cursor one past its
group end, so re-advancing an exhausted iterator resumed returning `true` and
walked through the rest of `ts_small_parse_table` and off the end of it.

- `ts_lookahead_iterator_current_symbol_name` returned `NULL` only when the
exhausted symbol index happened to fall outside the names table, so a grammar
with aliases returned a real but wrong name instead.
2026-08-14 00:13:54 -04:00