-
Notifications
You must be signed in to change notification settings - Fork 29
Add reserved words #117
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
Open
ddickstein
wants to merge
1
commit into
tree-sitter:master
Choose a base branch
from
ddickstein:reserved-words
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add reserved words #117
Conversation
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
Tree-sitter now supports reserved keywords for better error recovery. This commit updates the OCaml grammar to mark reserved words. For example, before ```ocaml let x = type t = int ``` was parsed as ``` (compilation_unit ; [0, 0] - [4, 0] (value_definition ; [0, 0] - [2, 12] "let" ; [0, 0] - [0, 3] (let_binding ; [0, 4] - [2, 12] pattern: (value_name) ; [0, 4] - [0, 5] "=" ; [0, 6] - [0, 7] body: (infix_expression ; [2, 0] - [2, 12] left: (application_expression ; [2, 0] - [2, 6] function: (value_path ; [2, 0] - [2, 4] (value_name)) ; [2, 0] - [2, 4] argument: (value_path ; [2, 5] - [2, 6] (value_name))) ; [2, 5] - [2, 6] operator: (rel_operator) ; [2, 7] - [2, 8] right: (value_path ; [2, 9] - [2, 12] (value_name)))))) ; [2, 9] - [2, 12] ``` and now it is parsed as ``` (compilation_unit ; [0, 0] - [4, 0] (value_definition ; [0, 0] - [0, 5] "let" ; [0, 0] - [0, 3] (let_binding ; [0, 4] - [0, 5] pattern: (value_name))) ; [0, 4] - [0, 5] (ERROR ; [0, 6] - [0, 7] "=") ; [0, 6] - [0, 7] (type_definition ; [2, 0] - [2, 12] "type" ; [2, 0] - [2, 4] (type_binding ; [2, 5] - [2, 12] name: (type_constructor) ; [2, 5] - [2, 6] "=" ; [2, 7] - [2, 8] equation: (type_constructor_path ; [2, 9] - [2, 12] (type_constructor))))) ; [2, 9] - [2, 12] ```
List of reserved words taken from https://ocaml.org/manual/5.3/lex.html#sss:keywords |
nice! |
I was working on this myself at 314eter/tree-sitter-ocaml. But the tests are failing because the Python bindings don't support 0.25 yet, so I was waiting on that to get released to create a PR. Some things I did that are missing here:
|
Oh okay - should I close this PR then?
…On Mon, Apr 21, 2025 at 10:54 AM Pieter Goetschalckx < ***@***.***> wrote:
I was working on this myself at 314eter/tree-sitter-ocaml
<https://github.com/314eter/tree-sitter-ocaml/tree/tree-sitter-0.25>. But
the tests are failing because the Python bindings don't support 0.25 yet
<tree-sitter/py-tree-sitter#333>, so I was
waiting on that to get released to create a PR.
Some things I did that are missing here:
- Upgraded the dependencies to tree-sitter 0.25
- Excluded the nonrec keyword. It's new since OCaml 4.02, so old code
may be using it as a variable.
- Included the binary operators or, lor, lxor, mod, land, lsl, lsr and
asr by making them tokens in the grammar.
- Used a different set of keywords for attribute_id.
—
Reply to this email directly, view it on GitHub
<#117 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGD5T5QZAWMEKAEYQU2TID22UBCBAVCNFSM6AAAAAB3QJUKFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJYGY3DMMZYGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
*314eter* left a comment (tree-sitter/tree-sitter-ocaml#117)
<#117 (comment)>
I was working on this myself at 314eter/tree-sitter-ocaml
<https://github.com/314eter/tree-sitter-ocaml/tree/tree-sitter-0.25>. But
the tests are failing because the Python bindings don't support 0.25 yet
<tree-sitter/py-tree-sitter#333>, so I was
waiting on that to get released to create a PR.
Some things I did that are missing here:
- Upgraded the dependencies to tree-sitter 0.25
- Excluded the nonrec keyword. It's new since OCaml 4.02, so old code
may be using it as a variable.
- Included the binary operators or, lor, lxor, mod, land, lsl, lsr and
asr by making them tokens in the grammar.
- Used a different set of keywords for attribute_id.
—
Reply to this email directly, view it on GitHub
<#117 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGD5T5QZAWMEKAEYQU2TID22UBCBAVCNFSM6AAAAAB3QJUKFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJYGY3DMMZYGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Tree-sitter now supports reserved keywords for better error recovery. This commit updates the OCaml grammar to mark reserved words. For example, before
was parsed as
and now it is parsed as