Skip to content

Releases

v0.8.1

Choose a tag to compare

@github-actions github-actions released this 05 Dec 02:57

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@latest

The 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 of DO in 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 with LANGUAGE PYTHON, JAVASCRIPT or JS, JAVA or SQL, as Snowflake, BigQuery and Databricks write it, and the SQL of EXECUTE IMMEDIATE.
  • trino: the body of a function with LANGUAGE PYTHON.
  • oracle: the SQL of EXECUTE IMMEDIATE, also in a q-string.
  • sqlserver: the SQL of EXEC('...') and of sp_executesql, and the @script of sp_execute_external_script when its @language is N'Python'.
  • mysql: the SQL of PREPARE ... 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

Choose a tag to compare

@kenshaw kenshaw released this 02 Dec 01:19

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 styles

The 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 onedark now follows joshdick/onedark.vim as Neovim shows it, in place of the onedark of chroma (D150). SQL keywords are blue, and the words that start a statement, such as SELECT and CREATE, are purple.
  • Style.LookupLanguage gives the entry of a capture name in a language. A style can give one language an entry of its own, such as keyword.sql, and the command transit uses 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 as keyword, 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.ChangedRanges no 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.ChangedRanges compares 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/templates holds the new array.h and parser.h of upstream.

Other

  • FieldForName matches 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

Choose a tag to compare

@kenshaw kenshaw released this 29 Nov 19:45

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, ::name is now a colon followed by the variable :name, as psql reads it. psql has no cast rule in psqlscanslash.l, the lexer for the arguments of a backslash command. So with \set foo bar, \echo x::foo gives x: and the variable foo.
  • 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

Choose a tag to compare

@kenshaw kenshaw released this 29 Nov 18:46

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, \restrict and \unrestrict.
  • \list takes the modifiers x and +, and \k and \kube take +. Before, the grammar read a name such as \list+ as one command name.
  • The describe commands, \l, \lo_list and \z take the modifier x, as \dtx+ does. \d takes the class i, and \dP takes the kinds i, t and n.
  • The other commands parse as before. Each new command with no modifiers already parsed as one command name.

v0.7.9

Choose a tag to compare

@kenshaw kenshaw released this 28 Nov 03:16

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.md is 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.md shows images of the highlighting of PostgreSQL, Go and usql in the styles onedark and github. test/cmd/stylesvg draws them in docs/images/.
  • The status of the work moved from README.md to the start of docs/PLAN.md.
  • docs/BACKLOG.md lists the languages that GitHub highlights, in tiers by use, for small grammars for the code blocks of Markdown. Questions 113 to 115 in docs/PLAN.md ask how to build them.
  • The documents name the maintainers, not one person.

Examples

  • grammars/go has examples that highlight Go code with the highlight query and a style of styles, as text and as ANSI colors. The module now requires github.com/xo/transit/styles.
  • grammars/json has examples that read the fields of a node and find the parse errors.
  • grammars/usql has examples that split a script with the options of a dialect and that get the parse states at a cursor.
  • grammars/postgres/postgres has examples that find the layers of a function with a PL/pgSQL body and get the parse states at a cursor.

v0.7.8

Choose a tag to compare

@kenshaw kenshaw released this 09 Nov 22:20

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 BeginEndBlocks on, 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 the END of the spec as the END of 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

Choose a tag to compare

@kenshaw kenshaw released this 09 Nov 21:33

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 BeginEndBlocks on, the scanner keeps an Oracle package spec, package body and type body in one statement, up to the ; after the END that closes the unit (D144). Before, each one split at its first ;.
    • The END of 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 BEGIN part, the code that runs when the package loads.
    • The closing END can name the unit or not: END name; or END;.
    • A plain CREATE TYPE that is not TYPE BODY does not change.
    • With the option off, nothing changes.
  • 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 FUNCTION query still needs \; for each ; inside its functions.
  • The serialized state of the scanner grows from 13 to 15 bytes.

v0.7.6

Choose a tag to compare

@kenshaw kenshaw released this 09 Nov 02:40

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/sql is now a grammar that xo writes (D143), in place of the grammar of DerekStride/tree-sitter-sql. The package path github.com/xo/transit/grammars/sql, the package name sql and 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, PIVOT and UNPIVOT, LATERAL, ARRAY, STRUCT and MAP, 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.go is 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-sql stays in the golden set, with no Go package.

v0.7.5

Choose a tag to compare

@kenshaw kenshaw released this 05 Nov 03:25

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 BackslashEscapes decides 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 one quoted_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'...' or e'...' 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.
  • The default language and the default build of src/scanner.c keep the escapes on, so the default corpus does not change.
  • BackslashEscapes is a flag of dbmeta with the same name, Syntax.BackslashEscapes (dbmeta D266). dbmeta holds its value for each dialect. The sample programs set it for mysql and clickhouse.

v0.7.4

Choose a tag to compare

@kenshaw kenshaw released this 05 Nov 00:38

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 Brackets makes a name between square brackets, such as [l'état], one quoted_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 :name inside does not end the name. An open [ keeps the statement open. With the option off, nothing changes, so a[1] and ARRAY[1,2] of PostgreSQL stay as they are. The sample programs set it for sqlserver and sqlite3.
  • 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.md says that the default options of src/scanner.c include dash comments (D139).