-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1ddb03a
Add support for dict syntax
nojaf 7d2ec8c
Install node version from nvmrc in CI
nojaf b2f52fc
Add dict highlighting
nojaf 5542c26
Update tree-sitter-cli
nojaf 5702498
Fix highlighting
nojaf 13df1e6
Rename CLAUDE.md to AGENTS.md and add symlink
nojaf d066837
Take dict keyword into account in the scanner
nojaf d499567
Generate with correct version
nojaf 4b4ee93
Add script to generate
nojaf 48941cf
Update title
nojaf bb6c794
Merge branch 'main' into dict-syntax
nojaf 494d89e
Bump rescript
nojaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v23.7.0 | ||
| v24.11.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # AGENTS.md | ||
|
|
||
| This file provides guidance to AI/LLM when working with code in this repository. | ||
|
|
||
| ## Build and Test Commands | ||
|
|
||
| ```bash | ||
| # Generate parser from grammar (required after grammar.js changes) | ||
| npx tree-sitter generate | ||
|
|
||
| # Run all corpus tests | ||
| npx tree-sitter test | ||
|
|
||
| # Run tests for a specific grammar rule (filter by name) | ||
| npx tree-sitter test --include "switch" | ||
|
|
||
| # Parse a file to see syntax tree (useful for debugging) | ||
| npm run parse path/to/file.res | ||
|
|
||
| # Compare with ReScript compiler's AST (useful for debugging grammar issues) | ||
| npx bsc -dparsetree -only-parse -ignore-parse-errors path/to/file.res | ||
|
|
||
| # Launch interactive playground (builds WASM first) | ||
| npm start | ||
|
|
||
| # Install npm dependencies | ||
| npm install | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Grammar Definition | ||
|
|
||
| **grammar.js** - The main grammar definition using Tree-sitter's JavaScript DSL. Key sections: | ||
| - `externals` - Tokens handled by the custom scanner (newlines, comments, template strings, decorators, parentheses) | ||
| - `precedences` - Operator precedence rules for expressions and module paths | ||
| - `conflicts` - Shift/reduce conflict resolutions for ambiguous constructs | ||
| - `rules` - All grammar rules (~80+ covering statements, expressions, types, modules, JSX) | ||
|
|
||
| ### External Scanner | ||
|
|
||
| **src/scanner.c** - Custom C scanner for context-sensitive tokens that the grammar alone cannot handle: | ||
| - Significant vs insignificant newlines (statement-ending vs formatting) | ||
| - Nested multiline comments (`/* /* */ */`) | ||
| - Template string interpolation (`\`hello ${name}\``) | ||
| - Parenthesis nesting tracking (affects newline significance) | ||
| - `list{` and `dict{` constructor detection | ||
| - Decorator parsing (`@decorator` vs `@decorator(args)`) | ||
|
|
||
| The scanner maintains state (`ScannerState`) tracking parenthesis nesting depth, whether inside quotes/backticks, and EOF reporting. | ||
|
|
||
| ### Generated Files (do not edit manually) | ||
|
|
||
| - `src/parser.c` - Generated LR parser from grammar.json | ||
| - `src/grammar.json` - Intermediate grammar representation | ||
| - `src/node-types.json` - AST node type definitions | ||
|
|
||
| ### Query Files | ||
|
|
||
| **queries/** - TreeSitter query files in S-expression syntax: | ||
| - `highlights.scm` - Syntax highlighting rules mapping AST nodes to semantic scopes | ||
| - `injections.scm` - Language injection boundaries | ||
| - `locals.scm` - Variable scope definitions | ||
| - `textobjects.scm` - Editor text object definitions | ||
|
|
||
| ### Test Corpus | ||
|
|
||
| **test/corpus/*.txt** - Test cases in Tree-sitter's corpus format. Each test has a name, ReScript code, and expected parse tree. Files cover: comments, decorators, expressions, functions, JSX, let bindings, literals, modules, type declarations. | ||
|
|
||
| ## Development Workflow | ||
|
|
||
| 1. Modify `grammar.js` to add/fix grammar rules | ||
| 2. Run `tree-sitter generate` to regenerate the parser | ||
| 3. Add test cases in `test/corpus/*.txt` with expected parse trees | ||
| 4. Run `tree-sitter test` to verify | ||
| 5. For scanner changes, edit `src/scanner.c` and rebuild | ||
|
|
||
| ## Language Bindings | ||
|
|
||
| Bindings are provided for Node.js, Python, Rust, Go, Swift, and C in the `bindings/` directory. CI tests Rust, Python, and Go bindings automatically. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| AGENTS.md | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.