mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:36:22 -04:00
The previous implementation of `InputGrammar::normalize` (inlined in `parse_grammar` iterated over every variable, checking whether it was reachable _backwards_ from teh root by recursing over rules that referenced it. This means that each and every top level call re-traversed the entire graph. The runtime performance of this backwards walk was dependent on the _order_ of rules as declared in `grammar.js`. All existing grammars have an ordering that's reasonably friendly to this iteration pattern (BFS-ish order, top down from the start rule), but this leaves us open to a catastrophic performance cliff. Instead, seed a `used` set with the start rule, the word token, and an names referenced from `extras`/`externals`. Then propagate via direct rule references. This yields anywhere from a 2-~2200x speedup for `parse_grammar`. This greatly speeds up `--no-parser` runs, but is relatively unimportant for `parser.c` generation for _existing_ grammars. The important piece is eliminating the potential cliff. |
||
|---|---|---|
| .cargo | ||
| .github | ||
| .zed | ||
| crates | ||
| docs | ||
| lib | ||
| test/fixtures | ||
| .dockerignore | ||
| .editorconfig | ||
| .envrc | ||
| .gitattributes | ||
| .gitignore | ||
| .taplo.toml | ||
| build.zig | ||
| build.zig.zon | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CMakeLists.txt | ||
| CONTRIBUTING.md | ||
| Dockerfile | ||
| flake.lock | ||
| flake.nix | ||
| FUNDING.json | ||
| LICENSE | ||
| Makefile | ||
| Package.swift | ||
| README.md | ||
tree-sitter
Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited. Tree-sitter aims to be:
- General enough to parse any programming language
- Fast enough to parse on every keystroke in a text editor
- Robust enough to provide useful results even in the presence of syntax errors
- Dependency-free so that the runtime library (which is written in pure C) can be embedded in any application