Repository navigation
Releases
v0.8.1
Every module of the repository has the tag v0.8.1: the root module, styles, cmd/transit, and each module under grammars/.
go install
The command transit now installs with go install (D152):
go install github.com/xo/transit/cmd/transit@latestThe tag cmd/transit/v0.8.1 names a commit whose go.mod has no replace block. The archives of the command for Linux, macOS and Windows are attached to this release, as for v0.8.0.
Code inside strings
The SQL grammars that xo writes now highlight the code inside a string with the grammar of its language (D153):
postgres: the body of a function or ofDOin PL/Python goes to python, in PL/v8 and PL/JS to javascript, and in PL/sh to bash, besides PL/pgSQL and SQL. A body in single quotes is highlighted too.sql: the body of a function withLANGUAGE PYTHON,JAVASCRIPTorJS,JAVAorSQL, as Snowflake, BigQuery and Databricks write it, and the SQL ofEXECUTE IMMEDIATE.trino: the body of a function withLANGUAGE PYTHON.oracle: the SQL ofEXECUTE IMMEDIATE, also in a q-string.sqlserver: the SQL ofEXEC('...')and ofsp_executesql, and the@scriptofsp_execute_external_scriptwhen its@languageisN'Python'.mysql: the SQL ofPREPARE ... FROM.
A string in these grammars is one token with its quotes. The new option inject.WithOffset() reads the directive #offset! of an injection query, as Neovim does, so that a layer parses the text without its quotes. Without the option, inject works as before. A program that highlights these grammars with inject passes the option to get the new layers.
Bash
grammars/bash/queries/highlights-xo.scm, which xo writes, adds to the copied query of tree-sitter-bash (D151). It colors $name, ${name:-word}, $(command) and $((expression)) apart from the string around them. A consumer reads it after highlights.scm.
The command transit
- The command reads the new query of bash and the new injections.
- The code of an injected layer no longer keeps the color of the string around it.
- In the style
onedark, a variable of bash is red, and${,},$((and))are yellow, as in Neovim with onedark.vim.
v0.8.0
Every module of the repository has the tag v0.8.0: the root module, styles, cmd/transit, and each module under grammars/.
The command transit
transit is now a syntax highlighter, in the module github.com/xo/transit/cmd/transit (D149). It highlights a file or the standard input in a terminal, as an HTML page or as an SVG image, with each of the 35 languages of the repository and each style of the package styles. The default style is onedark. This release has an archive of the command for Linux, macOS and Windows, on amd64 and arm64.
transit main.go
transit -s github -n main.go
git show HEAD:main.go | transit --filename main.go
transit -f svg main.go > main.svg
transit preview go
transit preview -f svg --styles onedark,github --columns 2 postgres > postgres.svg
transit languages
transit stylesThe file config.yaml in the config folder of the user, such as ~/.config/transit/config.yaml, gives the defaults of the flags, as in usql and hail. --config FILE or $TRANSIT_CONFIG names another file:
style: github
line-numbers: true
background: true
preview:
styles: [onedark, github]The new package github.com/xo/transit/samples holds a short code sample of each language. transit preview highlights them. The command replaces test/cmd/stylesvg, and _samples moved to test/_prototypes.
Styles
- The style
onedarknow followsjoshdick/onedark.vimas Neovim shows it, in place of the onedark of chroma (D150). SQL keywords are blue, and the words that start a statement, such asSELECTandCREATE, are purple. Style.LookupLanguagegives the entry of a capture name in a language. A style can give one language an entry of its own, such askeyword.sql, and the commandtransituses it.
SQL grammars
- The highlight queries of sql, postgres, mysql, sqlite3, sqlserver, oracle, duckdb, clickhouse, trino and cql give the words that start a statement the capture
keyword.statement. A style without that capture colors them askeyword, so a program that uses another style sees no change.
Upstream tree-sitter
transit now matches upstream tree-sitter at 7f893020, the head of upstream master on 2026-12-02. This release ports the 82 upstream commits after dfe77085. 33 of them change code that transit ports. The others change only parts that transit does not port, such as the CLI, the WebAssembly build and CI. docs/upstream/ledger.tsv lists each commit.
Incremental parsing
An incremental parse now gives the same tree as a fresh parse in these cases:
- A node before a non-terminal extra, or before any extra that the parser lexes again.
- A node that starts with a missing token.
- A node that ends with a zero-width token while the stack is split.
- A word token under a different set of reserved words.
- A node whose first leaf is a keyword that is not valid in the new state.
Changed ranges
Tree.ChangedRangesno longer trusts a match partway through a node, or a match of a rebuilt subtree that holds an error.
Error recovery
- A character that the lexer does not recognize costs the same as any other skipped token.
- When recovery extends an error, it pops one path of the stack.
Speed
- The parser reuses rotated nodes of a repetition, and a reduction of a repetition is no longer fragile.
- A reduction with one path pops its children in place.
- The search for a missing token reads each state once.
- The lexer checks one bound in its ASCII fast path, and it no longer checks the logger on each character.
Tree.ChangedRangescompares only end bytes, and it finds an external token only when it needs one.
The generator
- Two parse states with different reserved words are no longer merged when the merge would reserve a word that one state reads as an identifier. The parse tables of php, php_only, clickhouse, duckdb, postgres and sqlserver change.
generate/templatesholds the newarray.handparser.hof upstream.
Other
FieldForNamematches only a field name of the same length, also for a name that holds a NUL byte.- The repeat depth of a subtree is 32 bits, so a long repetition no longer wraps.
- The test module builds its C grammars again when the generator changes.
v0.7.11
Every module of the repository has the tag v0.7.11: the root module, styles, and each module under grammars/.
This release changes how the usql grammar reads :: in an argument of a meta command. Only the scanner of grammars/usql changes. transit still matches upstream tree-sitter at dfe77085.
The usql grammar
- In an argument of a meta command,
::nameis now a colon followed by the variable:name, as psql reads it. psql has no cast rule inpsqlscanslash.l, the lexer for the arguments of a backslash command. So with\set foo bar,\echo x::foogivesx:and the variablefoo. - In a statement,
::is still a cast. - In a list of options, such as
(title=a::t),::is still text, because the value of an option is one word, one string or one variable.
v0.7.10
Every module of the repository has the tag v0.7.10: the root module, styles, and each module under grammars/.
This release brings the meta commands of the usql grammar in line with metacmd/descs.go of usql. Only the scanner of grammars/usql changes. transit still matches upstream tree-sitter at dfe77085.
The usql grammar
- The scanner knows 16 more meta commands of usql:
\errverbose,\gdesc,\ef,\ev,\s,\hist,\history,\list,\k,\kube,\config,\html,\uset,\dump,\restrictand\unrestrict. \listtakes the modifiersxand+, and\kand\kubetake+. Before, the grammar read a name such as\list+as one command name.- The describe commands,
\l,\lo_listand\ztake the modifierx, as\dtx+does.\dtakes the classi, and\dPtakes the kindsi,tandn. - The other commands parse as before. Each new command with no modifiers already parsed as one command name.
v0.7.9
Every module of the repository has the tag v0.7.9: the root module, styles, and each module under grammars/.
This release changes the documents and adds examples. The runtime, the generator and the grammars do not change. transit still matches upstream tree-sitter at dfe77085.
Documents
README.mdis now for a person who uses transit. It shows how to install transit, parse a text, highlight it with a style, run a query, edit a tree, walk it with a cursor, find injections, use the options of the usql grammar and get the parse states at a cursor.README.mdshows images of the highlighting of PostgreSQL, Go and usql in the stylesonedarkandgithub.test/cmd/stylesvgdraws them indocs/images/.- The status of the work moved from
README.mdto the start ofdocs/PLAN.md. docs/BACKLOG.mdlists the languages that GitHub highlights, in tiers by use, for small grammars for the code blocks of Markdown. Questions 113 to 115 indocs/PLAN.mdask how to build them.- The documents name the maintainers, not one person.
Examples
grammars/gohas examples that highlight Go code with the highlight query and a style ofstyles, as text and as ANSI colors. The module now requiresgithub.com/xo/transit/styles.grammars/jsonhas examples that read the fields of a node and find the parse errors.grammars/usqlhas examples that split a script with the options of a dialect and that get the parse states at a cursor.grammars/postgres/postgreshas examples that find the layers of a function with a PL/pgSQL body and get the parse states at a cursor.
v0.7.8
Every module of the repository has the tag v0.7.8: the root module, styles, and each module under grammars/.
This release fixes a fault of v0.7.7 in the usql grammar. transit still matches upstream tree-sitter at dfe77085.
The usql grammar
- With the option
BeginEndBlockson, a\;after the header of a function or a procedure in an Oracle package spec now ends the header, as a;does (D144). In v0.7.7 it did not, so the scanner took theENDof the spec as theENDof a subprogram, and the statement after the spec joined it. - An escaped
;still does not end the statement. A script that escapes each;inside a package spec, a package body or a type body, as D138 told scripts to do, works with the options on or off.
v0.7.7
Every module of the repository has the tag v0.7.7: the root module, styles, and each module under grammars/.
This release changes the usql grammar. transit still matches upstream tree-sitter at dfe77085.
The usql grammar
- With the option
BeginEndBlockson, the scanner keeps an Oracle package spec, package body and type body in one statement, up to the;after theENDthat closes the unit (D144). Before, each one split at its first;.- The
ENDof a function or a procedure inside a package body or a type body does not end the statement. - A package body can end with its own
BEGINpart, the code that runs when the package loads. - The closing
ENDcan name the unit or not:END name;orEND;. - A plain
CREATE TYPEthat is notTYPE BODYdoes not change. - With the option off, nothing changes.
- The
- A function, a procedure and a trigger were already kept whole with the option on (D112). Point 5 of D138 now lists every unit that the option keeps whole.
- An Oracle
WITH FUNCTIONquery still needs\;for each;inside its functions. - The serialized state of the scanner grows from 13 to 15 bytes.
v0.7.6
Every module of the repository has the tag v0.7.6: the root module, styles, and each module under grammars/.
This release replaces the generic SQL grammar. transit still matches upstream tree-sitter at dfe77085.
The generic SQL grammar
grammars/sqlis now a grammar that xo writes (D143), in place of the grammar ofDerekStride/tree-sitter-sql. The package pathgithub.com/xo/transit/grammars/sql, the package namesqland its functions do not change. The node names and the trees change.- The grammar reads the SQL of the standard that the fallback dialects of usql share, and the forms that Snowflake, BigQuery and Databricks add. Examples are
QUALIFY,PIVOTandUNPIVOT,LATERAL,ARRAY,STRUCTandMAP,MERGE,COPY INTO,CLONE, time travel,CONNECT BY,MATCH_RECOGNIZE, pipe syntax, and the scripting blocks of the three dialects. - The grammar is lenient, because it serves highlighting. Strings take backslash escapes. The grammar has no external scanner.
- Of the code examples in the documentation, 96% of Snowflake, 91% of BigQuery and 90% of Databricks parse with no error. The old grammar parsed 39%, 54% and 40% of them.
parser.gois 2.58 MB, down from 6.57 MB. The package adds about 1.3 MB to a binary, down from about 3.0 MB.DerekStride/tree-sitter-sqlstays in the golden set, with no Go package.
v0.7.5
Every module of the repository has the tag v0.7.5: the root module, styles, and each module under grammars/.
This release changes the usql grammar. transit still matches upstream tree-sitter at dfe77085.
The usql grammar
- The new option
BackslashEscapesdecides whether a backslash escapes the next character in a'...'string and in a"..."name (D142). It amends item 4 of D105, which made a backslash escape in every family.- With it on,
\',\"and\\escape, as before for'...'. So MySQL's"a\"b"is onequoted_identifier. - With it off, a backslash is text, and only a doubled quote escapes a quote. So
select 'C:\data\';closes, as in psql, and a string in Shift JIS or Big5 whose last character ends in the byte of a backslash keeps its closing quote. - A string of the form
E'...'ore'...'of PostgreSQL keeps the backslash escapes with the option off. - A backslash in backticks, in square brackets and in the arguments of a meta command does not change.
- With it on,
- The default language and the default build of
src/scanner.ckeep the escapes on, so the default corpus does not change. BackslashEscapesis a flag of dbmeta with the same name,Syntax.BackslashEscapes(dbmeta D266). dbmeta holds its value for each dialect. The sample programs set it formysqlandclickhouse.
v0.7.4
Every module of the repository has the tag v0.7.4: the root module, styles, and each module under grammars/.
This release changes the usql grammar. transit still matches upstream tree-sitter at dfe77085.
The usql grammar
- The new option
Bracketsmakes a name between square brackets, such as[l'état], onequoted_identifier, as SQL Server and SQLite read it (D140).]]is an escaped]. Each character inside the brackets is the text of the name, so a', a;, a comment, a backslash or a:nameinside does not end the name. An open[keeps the statement open. With the option off, nothing changes, soa[1]andARRAY[1,2]of PostgreSQL stay as they are. The sample programs set it forsqlserverandsqlite3. - U+FEFF, the byte order mark, is white space at each position outside a string, a quoted name, a dollar quote and a comment (D141). So a script that joins files that each start with a byte order mark splits into clean statements, and the result does not depend on where a parse starts. Inside quotes and comments, U+FEFF is text. The runtime still skips it only at byte 0, as upstream does. A meta command keeps the white space at the end of its line, so it can end with U+FEFF, as it can end with a space.
Documents
docs/GRAMMAR.mdsays that the default options ofsrc/scanner.cinclude dash comments (D139).