Skip to content

Conversation

@nojaf
Copy link
Member

@nojaf nojaf commented Jan 12, 2026

image

Claude and I had a chat about this. I'm no expert on treesitter but this all seems legit to me from afar.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for dict (dictionary) syntax to the ReScript tree-sitter grammar, enabling parsing of dict expressions and dict patterns in switch statements. The implementation follows the established patterns used for similar constructs like lists and arrays.

Changes:

  • Added dict expression and dict_pattern grammar rules with support for key-value pairs
  • Added syntax highlighting for dict constructs
  • Added test cases covering dict expressions and dict patterns in switch statements
  • Updated build infrastructure (Node.js version, CI config, rescript dependency, documentation)

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
grammar.js Added dict and dict_pattern rules with dict_entry/dict_pattern_entry, added dict/dict_pattern conflict resolution
src/grammar.json Auto-generated grammar representation reflecting dict additions
src/node-types.json Auto-generated AST node type definitions for dict, dict_entry, dict_pattern, dict_pattern_entry
test/corpus/expressions.txt Added test cases for dict expressions and dict pattern matching in switch statements
queries/highlights.scm Added syntax highlighting rules for dict constructs, marking "dict" keyword as type.builtin and keys as properties
package.json Added rescript ^12.0.2 as devDependency
package-lock.json Added rescript and its platform-specific optional dependencies
CLAUDE.md Added new documentation file with build commands, architecture overview, and development workflow
.nvmrc Updated Node.js version from v23.7.0 to v24.11.1
.github/workflows/ci.yml Added Node.js setup step using .nvmrc for version consistency
Comments suppressed due to low confidence (1)

test/corpus/expressions.txt:1966

  • Consider adding more comprehensive test cases for dict expressions to match the coverage provided for similar constructs like lists. Suggested additions: trailing comma test (e.g., dict{"A": 5,}), multiline formatting test, and dict in let binding pattern matching (e.g., let dict{"key": value} = myDict).
================================================================================
Dict expression
================================================================================

dict{"A": 5, "B": 6}
dict{}

--------------------------------------------------------------------------------

(source_file
  (expression_statement
    (dict
      (dict_entry
        (string
          (string_fragment))
        (number))
      (dict_entry
        (string
          (string_fragment))
        (number))))
  (expression_statement
    (dict)))

================================================================================
Dict pattern in switch
================================================================================

switch json {
| Object(dict{"lat": Number(lat)}) => lat
| _ => 0.0
}

--------------------------------------------------------------------------------

(source_file
  (expression_statement
    (switch_expression
      (value_identifier)
      (switch_match
        (variant_pattern
          (variant_identifier)
          (formal_parameters
            (dict_pattern
              (dict_pattern_entry
                (string
                  (string_fragment))
                (variant_pattern
                  (variant_identifier)
                  (formal_parameters
                    (value_identifier)))))))
        (sequence_expression
          (expression_statement
            (value_identifier))))
      (switch_match
        (value_identifier)
        (sequence_expression
          (expression_statement
            (number)))))))


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aspeddro
Copy link
Collaborator

@nojaf thank you!!

Take a look at #190 and #189

let dict = dict{"A": 5, "B": 6, "C": 7}
(source_file [0, 0] - [1, 0]
  (ERROR [0, 0] - [0, 39]
    (dict_pattern [0, 4] - [0, 39]
      (ERROR [0, 9] - [0, 15])
      (dict_pattern_entry [0, 16] - [0, 22]
        (string [0, 16] - [0, 19]
          (string_fragment [0, 17] - [0, 18]))
        (number [0, 21] - [0, 22]))
      (dict_pattern_entry [0, 24] - [0, 30]
        (string [0, 24] - [0, 27]
          (string_fragment [0, 25] - [0, 26]))
        (number [0, 29] - [0, 30]))
      (dict_pattern_entry [0, 32] - [0, 38]
        (string [0, 32] - [0, 35]
          (string_fragment [0, 33] - [0, 34]))
        (number [0, 37] - [0, 38])))))

dict can be a valid identifier. The check to determine whether dict{} is an identifier or a dictionary constructor should be done in the lexical analyzer.

if (valid_symbols[LIST_CONSTRUCTOR]) {
lexer->result_symbol = LIST_CONSTRUCTOR;
if (lexer->lookahead == 'l') {
advance(lexer);
if (lexer->lookahead == 'i') {
advance(lexer);
if (lexer->lookahead == 's') {
advance(lexer);
if (lexer->lookahead == 't') {
advance(lexer);
if (lexer->lookahead == '{') {
lexer->mark_end(lexer);
return true;
}
}
}
}
}
}

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@aspeddro aspeddro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds great!! 🎉

@nojaf nojaf merged commit 97cf83e into rescript-lang:main Jan 13, 2026
1 check passed
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.

3 participants