Skip to content

tree-sitter-rx: a tree-sitter grammar for .rx - #88

Merged
ryansolid merged 7 commits into
solidjs:mainfrom
oddcelot:tree-sitter-rx
Nov 20, 2026
Merged

ryansolid merged 7 commits into
solidjs:mainfrom
oddcelot:tree-sitter-rx

Conversation

@oddcelot

Copy link
Copy Markdown
Contributor

Hi! This adds a tree-sitter grammar for .rx and .d.rx in tooling/tree-sitter-rx.

The language server README mentions that Neovim has no .rx grammar and Zed has no extension. Both need the same thing, so I started here. A Zed extension can follow on top of it.

What you get

  • Highlighting that keeps working while a file is half typed, which is exactly when the language server can't help.
  • Outline, folding, indentation and text objects, even in a folder with no tsconfig.json or node_modules.
  • A way for structural tools like ast-grep to query .rx.

How it works

grammar.js extends tree-sitter-typescript's TSX grammar, so expressions, types and JSX keep the node names you already know from TSX. Each .rx form gets its own node (source_declaration, equation, write_statement, …). The README has the full table.

It differs from TSX in three places, which are the parts most worth a close look:

  • No assignment expressions. A statement-level x = e is always an equation, as the spec says.
  • Where statements end. src/scanner.c is TypeScript's scanner with my changes marked rx:. A newline ends a statement before <, (, [ and a template. On one line, a statement keyword, a write target followed by :=, or a call after a whole expression starts the next statement.
  • Contextual keywords. server, client, error and draft can also be names, as in server = await loadTodos().

Important

compiler/src/parse.rs stays the definition of the language. If the grammar disagrees with it anywhere, that's a bug in the grammar, and I'd love to hear about it.

How I tested it

  • 67 corpus tests in test/corpus
  • All 206 tracked .rx files parse with no ERROR or MISSING node (pnpm run parse:repo)
  • highlights.scm and injections.scm run without query errors, and CSS is injected into <style> bodies
  • The parser builds to WebAssembly with wasi-sdk, the way Zed compiles it
  • A CI job, .github/workflows/tree-sitter.yml: a stale src/ check, the corpus, the repo parse and the queries

Note

The build failure is the deleted Solid next branch, fixed in #87.

What it doesn't do yet

  • A bare word doesn't start a statement on the same line: a = 1 b = 2 parses in parse.rs but not here.
  • A type named ref doesn't parse in type position, where ref is the accessor modifier.
  • The grammar is a bit looser than the compiler in places: JS for and while in handlers, JSX in expression position.
  • highlights.scm is ordered so a later pattern wins (Zed, Neovim). Helix takes the first match and would need the order reversed.

Tip

Don't be alarmed by the diff size. Almost all of it is src/parser.c, which tree-sitter generate writes. It's committed because Zed compiles it from a pinned commit without running the generator. The hand-written part is 17 files.

Thanks for taking a look. Feedback on the node names is especially welcome, since queries will depend on them.

Extends tree-sitter-typescript's TSX grammar. compiler/src/parse.rs stays the reference.
Committed because Zed compiles src/parser.c as it is.
- a signature's return may be an accessor: `): ref string`, `[ref boolean, …]`
- an element's text ends at `<`, `{` and `}` only, so `>` and a bare `&` are text
- a newline before a fn's `{` no longer ends it as a signature
- a `<style>` inside an element is raw CSS
- `import server from "./x"`: a side only before `pure` or `{`
- on one line, a statement keyword, a `use` target and a call start a statement;
  brackets in a string do not count
- a chain of catches folds left
- an attribute's value may be a primary expression without braces: `value=1`
- highlights: a capitalised name is no longer always a type
src/parser.c is committed, so the CLI and the TSX grammar that write it are exact.
…input

- reading ahead on one line, the scanner skips a /* */ comment, and stops at //
- `effect (,) { … }` no longer parses
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​tree-sitter-javascript@​0.23.11001008086100
Addednpm/​tree-sitter-cli@​0.27.2921008394100
Addednpm/​tree-sitter-typescript@​0.23.21001008486100

View full report

@oddcelot

Copy link
Copy Markdown
Contributor Author

For comparison (because it is not totally obvious) here are some other parser.csizes
Of course you would assume for ReactiveScript to be larger than TSX at least.

Grammar parser.c
Verilog 46.4 MB
C# 39.5 MB
Kotlin 35.3 MB
Scala 30.9 MB
C++ 25.9 MB
Julia 24.1 MB
Haskell 19.9 MB
ReactiveScript ✨ 10.8 MB
TSX 8.8 MB
TypeScript 8.7 MB
Rust 6.5 MB
JavaScript 2.9 MB
Svelte 0.24 MB
Astro 0.12 MB

@oddcelot

Copy link
Copy Markdown
Contributor Author

Also maybe worth to take a look at the diff somewhere else since GitHub collapses a lot: https://diffshub.com/solidjs/reactivescript/pull/88 😅

@oddcelot

Copy link
Copy Markdown
Contributor Author

Not to be spammy, but there is light at the end of the tunnel 😄
This is how it could look in Zed:
image

@ryansolid
ryansolid merged commit b470614 into solidjs:main Nov 20, 2026
2 checks passed
ryansolid pushed a commit that referenced this pull request Nov 20, 2026
solid-next.sh takes #87's version (fetch the pin by hash, SOLID_BRANCH); the pin stays 99db9bce4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWLtkg281f1NkGEDjCt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants