yolowsyntax
Pure-Rust, Hardware-Accelerated Tree-Sitter Runtime & 41-Language Code Outline Extractor
English · 简体中文 · Benchmarks · Changelog
A pure-Rust, hardware-adaptive parser runtime compatible with converted tree-sitter parse tables and ported external scanners, extracted from PageSift and released under MIT (see THIRD-PARTY.md for MIT / Apache-2.0 upstream grammar and scanner notices). Zero C compiler required at build time, #![deny(unsafe_op_in_unsafe_fn)] with audited SIMD intrinsics and portable scalar fallbacks, a single pure-Rust runtime dependency (yolowzstd 0.3.1), embedded Zstd-compressed parse tables for 41 languages with lazy per-language decompression, and direct-arena code outline extraction.
At a Glance
- Zero C Toolchain, Hardware-Adaptive Pure Rust: No
cc, nobindgen, no C FFI. Uses#![deny(unsafe_op_in_unsafe_fn)]with runtime AVX2/SSSE3/SSE2 (x86-64) and NEON (AArch64) dispatch, bit-identical scalar fallbacks, and LinuxPROT_NONEMMU guard-page zero-overread tests (MSRV1.89+, verified on Linux x86-64, Windows x86-64, and macOS AArch64). - 41 Embedded Languages, Lazy Zstd Decompression: Ships
yolowzstd 0.3.1level-22.pslg.zparse tables (4.30 MiBacross 41 grammars;3.95 MiB.cratepackage) and pure-Rust ports of upstream external scanners for one-shot (&[u8]) parsing. Only the languages you actually call are decompressed (0.074–12.193 mscold load) and cached viaOnceLockusing zero-copy streaming table loading. - Scope & Compatibility: Embeds 41 compiled grammars and ported scanners, rather than aiming for drop-in C
tree-sitterAPI compatibility—there is no dynamic C grammar loading, no Tree-sitter Query DSL, and no incremental re-parsing (tree.edit). - 5,875 / 5,875 (100.00%) Active Official Corpus Cases: Passes all
5,875active test cases across 41 pinned upstreamtest/corpussuites (0failed;5,844S-exp matches +31expected:errorcases;22skipped due to:language(...)dialect mismatch across shared suites;:skip/:cst/excluded:platformdirectives are also skipped by the runner, with0present here). - Direct-Arena Code Outline Extraction (
outline): For 32 symbol-bearing languages, walks the parse arena directly to extractsymbols,imports, and contiguoussections(losslessly concatenating back to the original source). The remaining 9 markup/config grammars still parse into syntax trees viaapi::parse(), whileoutline()short-circuits in O(1) toNone(also returningNonewhen a file yields no definitions or exceeds2 MiB/20%error bytes). - Cooperative Resource Budgets (
Limits): Bounds GLR stack depth, version count (max_versions = 6), AST node count (max_nodes = 4,000,000), parser step budget, and an optional cooperative wall-clock deadline (max_millis = 0by default = disabled), returning a tinytruncateddegraded tree on overflow. Note: this is in-process cooperative bounding, not OS/cgroup memory isolation, and does not guarantee protection against OOM for arbitrary host allocations outside parser step/budget checks.
Story
When PageSift added source-code extraction for LLM and RAG pipelines, we needed to split source files along real structural boundaries—top-level functions, classes, structs, traits, and imports—rather than chopping code at arbitrary line counts.
Using the standard C tree-sitter ecosystem meant pulling in a C compiler (cc), linking dozens of native src/parser.c and src/scanner.c compilation units across 41 languages, and passing untrusted files from the open web through C FFI. At the same time, we did not need incremental editing for a live IDE buffer—we needed a one-shot, pure-Rust parser with explicit runtime budgets.
So we built yolowsyntax:
- A compact
.pslg.zbinary table converter (ts-convert) that reads upstreamparser.cfiles offline and packs their parse tables into Zstd level-22 blobs (yolowzstddecompresses a language lazily on first use and streams entries straight into dense/sparse tables). - A hardware-coupled Elkhound hybrid LR(1)/GLR runtime (
#![deny(unsafe_op_in_unsafe_fn)]) combining Moore-factored + Mealy sink-fused lexing, 2-nibblevpshufb/vqtbl1q_u8SIMD self-loops, DFS-compiled O(1) keyword hash tables, half-cache-line32 BNodehot/cold splitting,8 BstackLinks, whole-loop AVX2 specialization, pure-Rust external scanners, and cooperativeLimits. - A direct-arena lossless code outline layer (
outline) that extracts top-level/container symbols, imports, and contiguous byte-rangesections(sectionsjoined == original file whenSome) without building intermediate trees or descending into function bodies.
Install
[]
= "0.2"
To enable the offline grammar converter and corpus/parse CLI tools (ts-convert, ts-corpus, ts-parse):
[]
= { = "0.2", = ["tools"] }
Usage
1. Extract Code Outline (outline)
use outline;
let src = r#"
use std::collections::HashMap;
pub struct Config {
pub limit: usize,
}
pub fn build_index(items: &[&str]) -> HashMap<String, usize> {
items.iter().enumerate().map(|(i, s)| ((*s).to_string(), i)).collect()
}
"#;
let out = outline.expect;
assert_eq!;
assert_eq!;
// Every section maps cleanly back to the original source bytes
let reconstructed: String = out.sections.iter.map.collect;
assert_eq!;
2. Direct Syntax Tree Parsing with Cooperative Budgets (api::parse)
use ;
let lang = from_tag.unwrap.table.unwrap;
let limits = Limits ;
let tree = parse;
assert!;
assert!;
println!;
outline() Semantics & When It Returns None
symbols: Top-level declarations plus methods/constructors/fields nested directly inside types (struct,class,trait,impl,interface,enum) or single-file module containers; capped at2,000symbols.imports: Extractedimport/use/includestatements; capped at500entries.sections: Contiguous non-overlapping byte ranges covering[0..source.len())anchored on top-level symbol boundaries (leading preamble hastitle: None).- Returns
Nonewhen: the tag is unknown, input is empty or> 2 MiB, parsing hitsLimits(including the internal3,000 mscooperative budget), syntax error spans exceed20%of input bytes, the language has no outline rules (html,css,vue,svelte,nix,dockerfile,make,scheme,hcl), orsymbolsis empty (e.g., expression-only files or code wrapped inside a single IIFE/block).
Supported Languages (41)
- Systems & Compiled:
c,cpp,rust,go,objc,d,pascal,verilog - JVM & Managed:
java,csharp,kotlin,groovy,dart - Web & Scripting:
javascript(jsx),typescript,tsx,python,php,ruby,lua,bash(sh,shell,zsh),powershell - Functional & ML:
ocaml,elixir,erlang,elm,gleam,scheme,commonlisp,julia,r - Web Templates, Config & Build:
html,css,vue,svelte,nix,dockerfile,cmake,make,hcl(terraform),solidity
Benchmarks
Measured on Intel Core i7-10700 (taskset -c 4, AVX2), Linux 7.0.0-43-generic x86-64, rustc 1.99.0 (--release, lto = "fat", codegen-units = 1) against tree-sitter 0.26.13 + upstream C grammar crates (median of 25 alternating rounds). Both corpus parity and error parity are verified by the harness (y_err == ts_err); full scripts, RSS (4,104–21,624 KiB), real OSS file runs, and 41-language results are in benchmarks/README.md.
~64 KiB Corpus-Concatenated Suite (Historical Baseline, Hardware/Dataset-Specific)
These 2.80×–5.46× speedups apply specifically to ~64 KiB concatenated upstream test/corpus snippets under this harness configuration, not as a universal multiplier for all inputs:
| Language | Active Corpus (yolowsyntax) |
yolowsyntax parse (ms ↓) |
C tree-sitter parse (ms ↓) |
yolowsyntax outline (ms ↓) |
Speed (ts / yolow ↑) |
Parity / outline |
|---|---|---|---|---|---|---|
| C | 85 / 85 (100%) | 3.856 | 21.048 | 4.293 | 5.46× | exact / some(361) |
| Go | 67 / 67 (100%) | 3.808 | 11.136 | 4.343 | 2.92× | exact(both_err) / some(724) |
| Java | 108 / 108 (100%) | 2.765 | 9.141 | 3.191 | 3.31× | exact / some(615) |
| Python | 117 / 117 (100%) | 4.881 | 15.624 | 5.271 | 3.20× | both_err_diff / some(255) |
| JavaScript | 116 / 116 (100%) | 4.626 | 13.738 | 5.062 | 2.97× | exact(both_err) / some(253) |
| TypeScript | 111 / 111 (100%) | 4.252 | 11.893 | 4.973 | 2.80× | exact(both_err) / some(902) |
| Rust | 151 / 151 (100%) | 4.334 | 13.891 | 4.854 | 3.21× | exact(both_err) / some(722) |
| Bash | 100 / 100 (100%) | 8.699 | 26.799 | 8.783 | 3.08× | exact(both_err) / some(2) |
Standalone Real-World OSS Files (31 KiB – 176 KiB, real-bench)
| Language (File) | Bytes | yolowsyntax parse (ms ↓) |
C tree-sitter parse (ms ↓) |
yolowsyntax outline (ms ↓) |
Speed (ts / yolow ↑) |
Parity / outline |
|---|---|---|---|---|---|---|
C (parser.c) |
78,797 | 1.865 | 14.066 | 1.971 | 7.54× | exact(both_err) / some(59) |
Go (decode.go) |
36,112 | 1.700 | 4.609 | 1.752 | 2.71× | exact / some(38) |
Java (ImmutableList.java) |
31,280 | 0.609 | 2.107 | 0.674 | 3.46× | exact / some(85) |
Python (argparse.py) |
102,236 | 2.590 | 9.678 | 2.675 | 3.74× | clean(py_expr_stmt) / some(161) |
JavaScript (moment.js) |
176,435 | 5.016 | 19.178 | 5.016 | 3.82× | exact / none |
TypeScript (types.ts) |
153,859 | 7.077 | 20.494 | 7.440 | 2.90× | exact / some(372) |
Rust (searcher/mod.rs) |
39,771 | 0.710 | 2.600 | 0.795 | 3.66× | exact / some(72) |
Bash (nvm.sh) |
148,844 | 4.968 | 35.476 | 5.066 | 7.14× | exact / none |
License
MIT License — see LICENSE, THIRD-PARTY.md (for MIT and Apache-2.0 upstream grammar/scanner attributions), and UPSTREAM.md.