Repository navigation
gotreesitter v0.57.0
Highlights
- Add a pure-Go command for parsing, queries, highlights, symbols and corpus tests.
- Correct highlight priorities and inheritance, with explicit upgrade notes for changed captures.
- On pinned fixtures, legacy YAML parse time fell 5.39% over 20 paired runs;
a compact 1 MiB Go parse allocated 17.52% fewer bytes (#1486, #1504).
Upgrade notes
-
grammars.JSONTokenSource,NewJSONTokenSourceandNewJSONTokenSourceOrEOF
are removed, and the registry no longer routesjsonthrough a token source.
To upgrade, callparser.Parse(src)where you called
ParseWithTokenSource(src, grammars.NewJSONTokenSourceOrEOF(src, lang)), and
parser.ParseIncremental(src, old)for incremental parses. Drop
WithTokenSourceFactoryfrom highlighters and taggers for JSON. Code that
callsentry.TokenSourceFactory(...)without a nil check must check for nil
and fall back toParse. Trees differ from the old ones on 6 JSON files in the
test corpus, and in each of them only the DFA tree matched C. -
Highlightand its incremental and UTF-16 variants no longer return a range
for aspell,nospell,conceal,none, underscore-prefixed or
locals-directive capture. Code that reads aspell,noneor underscore
capture fromHighlightno longer receives it. -
Injected child layers keep their own pattern order on identical spans, as a
standalone file does. Before, a layer lost its pattern indexes and the order of
the matches decided. In a Markdown fence of starlark,{changes from
punctuation.brackettopunctuation.special. -
On a span that an injected language and its host both capture, the injected
capture now wins. Before, the host's capture won unless it came from the first
pattern of the host's query. -
Queries that set
(#set! priority N)now resolve overlaps by priority. Before,
the directive had no effect and the narrower capture won. Sixteen shipped
queries set a priority. In the diff query, the---,+++,-and+
markers now takediff.minusordiff.plusinstead ofpunctuation.special.
In hare,:outerinbreak :outer;is onelabelrange where it was a
punctuation.delimiterrange and avariablerange, and in tablegen,!addis
onefunctionrange where it was apunctuation.specialrange and a
functionrange. -
ExternalVMscanner APIs are removed. Implement a Go
gotreesitter.ExternalScannerinstead (#1536). -
The
grammarsfacade drops per-language scanner aliases and unused helpers,
includingDecodeAndCertifyLanguageBlob. Importgrammars/runtimefor the
equivalents exported there (#1536). -
Replace
corpuscheck.RunLanguageLimitedwithRunLanguageWithOptionsand
RunOptions{MaxCases: n}(#1536). -
The
tsquerycommand now requires-lang. Supply the registered grammar
name so the query is compiled and validated before code generation
(#1537). -
Use
gotreesitter testin place of the standalonecorpuscheckcommand.
Corpus mismatches return exit status 1; an empty selection or a requested
language that cannot run returns status 2 (#1524). -
Callers can no longer use a nil root to recognize an accepted parse with no
syntax nodes. Check the input itself for an empty byte slice and inspect
HasError()for parse errors (#1543). -
Curated and inherited highlight queries change some capture names. Check
themes that map built-in captures to colors (#1539).
Added
-
Add
cmd/scannercert, a report-only tool that replays external scanner calls
from saved state and reports any difference from the live result. It grants no
incremental-reuse approval and changes no scanner capability flag
(#1518). -
Add the pure-Go
gotreesittercommand for parsing, querying, highlighting,
tags, outlines, code patterns and corpus tests. It accepts files or standard
input and supports JSON output (#1524). -
Add
LangEntry.Parse,NewParserandNewHighlighterhelpers that use the
entry's registered token source when one is available (#1537).
Changed
-
Make the highlighter return only captures that name a color. It no longer
returns private captures (a leading underscore),@spell,@nospell,
@conceal, or the directives of a locals query (@local.scope,
@local.reference,@local.definition,@local.definition-valueand
@local.definition.*); predicates and directives still read them.@none
clears the colors of its own priority beneath it, including the color of an
enclosing capture of that priority, and is not returned. It does not clear a
capture of a lower priority, so the reset that the Markdown query puts on a
fence leaves the injected language's own colors, such as zig's strings at
priority 95. This follows the convention nvim-treesitter documents for
@none; tree-sitter-highlight and Neovim's own highlighter keep the enclosing
color under an inner@nonenode.(#set! priority N)sets the priority of a
pattern's captures, with a default of 100. Injected child queries follow the
same rules, and at equal priority an injected capture wins over the host's
capture on the same span. A VHDL comment keeps its@commentcolor, and a
private capture such as@_keyno longer hides the color of its node
(#454). -
Remove the BitBake, Corn, DTD, Templ, and Wolfram result-compatibility
arms. None of them rewrote a node on any registered witness, and the trees
on the production, compact, forest, and incremental routes are the same with
the arms removed.ParseRuntime().NormalizationPassesand the
GTS_DISPATCHER_CENSUSoutput no longer list adispatch.<language>pass
for these five languages. The five languages are now eligible for
compact-tail elision. The Perl arm stays: it still regroupspush @a => ...
arguments the way locked C does. -
Reduce YAML parse time and allocation. The YAML scanner caches the current
rune within each request (#1486), prepares its scanner bindings once
(#1491) and keeps indentation type and width in one frame stack (#1514).
The cached-rune change cut legacy YAML parse time by 5.39% (p=.004, 20 pairs);
the prepared bindings cut ordinary YAML parse time by 2.60% (p=.028). -
Reduce memory on the compact parse route. Allocated bytes for a fresh 1 MiB
Go parse fall 17.52% (453,602,488 to 374,143,160 B/op, p<.001) because public
subtrees now live in 64K-record blocks (#1504). Graph nodes shrink from 24
to 16 bytes (#1500) and no longer copy the whole arena when it grows
(#1502). Dependency and lexer-history allocations also shrink (#1480);
allocation for a 20 KB query compile falls from 140,563 to 10,512 B. Timing
differences were inconclusive. The compact route is not the default for every
language. -
Parse JSON with the grammar's own DFA lexer, and delete its hand-written token
source (grammars/runtime/json_lexer.go). Both paths were compared with the
locked C parser on 303 JSON files: the DFA path matched C on 303 files, and the
token source on 297. No file matched C only through the token source.
LangEntry.TokenSourceFactoryis now nil for JSON, soParseFile,
ParseFilePooledand the other registry helpers useParser.Parse. The Java
token source stays: it is the only implementation of the end-of-file comment
append proof, and without it typing at the end of a trailing comment in a
Java file runs a hidden fresh parse on every keystroke. C, C++ and authzed
also keep their token sources: C matched C on 4 corpus files where the DFA path
did not, and the C++ token source matches C on a malformed class body that the
DFA path parses without an error. -
Compose highlight queries from first-line
; inherits:directives and add
curated query coverage, including Apex, Vue, V, Typst and HLSL. Imported
queries carry source and license attribution (#1539). -
Scan YAML comment content in batches (#1567).
-
Reduce DFA, publication and read-history overhead in certified Go incremental
parsing. Unsupported or unproven reuse retains fresh verification
(#1570). -
Publish compact parse results through owned node views and preserve recovery
and scanner-history checks (#1569). -
Page compact compatibility snapshots and cap the scrubbed workspace retained
between calls. On the qualified roughly 2 KiB TypeScript fixture, allocated
bytes fell from 167.425 to 3.139 KiB per parse; the separate 1 MiB probe's peak
RSS fell from 294,732 to 165,056 KiB (#1577).
Fixed
-
Go: make compact recovery return
(source_file (ERROR))for,, as the C
parser does. Reuse completed Scala snippet roots, which removes about 17 MB of
allocation for malformed 24-30 byte Scala inputs (#1452). -
TypeScript and TSX: parse an async generic arrow such as
async <T>(v: T): Promise<T> => vcorrectly instead of as a
binary_expression(#1483). -
TypeScript and TSX: parse generic tagged template calls such as
tag<string[]>`text`instead of reading them as comparisons or failing
(#1515). This regeneratestypescript.binandtsx.bin. -
Generated grammars: keep the span of a consumed hidden newline when a
newline-or-NUL terminator follows (#1513). None of the 206 shipped grammars
takes the changed branch. -
32-bit builds: fix a panic when a parser state with the high bit set became a
negativeintin a bounds check (#1485). -
Compact projection: publish hidden-supertype ancestry and synthetic-root
metadata exactly. The Go supertype query failed before this fix (#1484). -
Make: accept builtin names such as
$(file)and${dir}as variable
references, including nested expressions, while preserving function calls
(#1561). -
Kotlin: preserve queued reduction alternatives for the certified shipped
grammar, including the generic-call regression cases (#1568). -
Accepted parses with no syntax nodes now return a zero-width
ERRORroot
instead of a nil root, matching locked C on the affected cases (#1543). -
Generated C exports for pre-ABI-15 grammars compile against the pinned runtime
headers while retaining the older lexer-mode table layout (#1579). -
PowerShell: update the pinned grammar and scanner so native arguments such
as comma lists, bare--and-, attached option values and trailing&
parse cleanly. The replay preserves the original contributor's work
(#1576, #1574). -
Keep trailing comments outside recovered
ERRORnodes when an ancestor
recovery path contains a discontinuity (#1580).
Evidence
- Validation and measurement scope are recorded in the linked pull requests,
including the qualified Go incremental run,
#1569 and #1579. The release receipt binds the final commit and its full manual CI run.