-
Notifications
You must be signed in to change notification settings - Fork 20
Add support for dict syntax #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
|
@nojaf thank you!! let dict = dict{"A": 5, "B": 6, "C": 7}
tree-sitter-rescript/src/scanner.c Lines 304 to 322 in d2df8a2
|
There was a problem hiding this 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.
aspeddro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds great!! 🎉
Claude and I had a chat about this. I'm no expert on treesitter but this all seems legit to me from afar.