Skip to content

Update grammar to cover array spreads, variant type spreads and newer operators. #267

Open
mvaled wants to merge 3 commits intorescript-lang:mainfrom
mvaled:main
Open

Update grammar to cover array spreads, variant type spreads and newer operators. #267
mvaled wants to merge 3 commits intorescript-lang:mainfrom
mvaled:main

Conversation

@mvaled
Copy link
Copy Markdown

@mvaled mvaled commented Apr 11, 2026

Disclosure: This PR was generated with AI assistance and reviewed by the author. The author's goal is to improve the Emacs rescript-ts-mode (jjlee/rescript-mode#19).

Summary

This PR updates the Tree-sitter grammar to better match recent ReScript language features across three areas:

  1. ReScript 12 operator support
  2. Variant spread syntax
  3. Array spread expressions

What changed

1. ReScript 12 operator support

Added grammar support for the newer operator syntax introduced in ReScript 12, including:

  • modulo: %

  • bitwise operators:

    • &&&
    • |||
    • ^^^
    • ~~~
  • shift operators:

    • <<
    • >>
    • >>>

2. Variant spread syntax

Added support for:

  • variant type spreads, e.g.

    type base = Start | Stop | Pause
    type extended = | ...base | Resume
  • variant pattern spreads, e.g.

    let handle = (event: extended) =>
        switch event {
        | ...base as core => Console.log2("base", core)
        | Resume => Console.log("resuming")
        }

3. Array spread expressions

Added support for spread elements inside array literals, including multiple spreads, e.g.

let animals = ["🐶", "🐱", "🐷"]
let moreAnimals = [...animals, "🐔", "🐴", "🐮", ...otherAnimals]

This brings the grammar in line with array spread syntax available since ReScript v11.

mvaled added 3 commits April 10, 2026 16:23
Add parser support for the ReScript 12 operator improvements that were
missing from the grammar.

This covers modulo, bitwise operators, and shift operators, and adds
corpus and highlight updates for the new syntax. Unrelated untracked
files are left out of the commit.
Add grammar support for variant type spreads and variant pattern
spreads.

This adds corpus coverage for type declarations and expressions,
including a dedicated variant pattern spread example.

Also ignore local uv lockfiles via .git/info/exclude.
Allow spread elements in array expressions.

Add corpus coverage for array spread syntax using the ReScript 11.1
style example, including multiple spreads in the same array literal.
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.

1 participant