Skip to content
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

Add try-catch, for, while, while do, and enum, and fix if #60

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gerblesh
Copy link

@gerblesh gerblesh commented Dec 22, 2024

Hi! Was working on Helix support for the queries when I realized the grammar hadn't implemented these structures. Figured I'd have a go at it. First time playing around with treesitter so things probably aren't ideal but it mostly works. I still also need to get tests passing and write some tests

@gerblesh gerblesh marked this pull request as draft December 22, 2024 05:17
@gerblesh
Copy link
Author

gerblesh commented Dec 22, 2024

There's some odd behavior where when trying to do the range operator on two ints, the grammar thinks it's a float:
1...5 would give (float) instead of ( (integer) (integer))

@gerblesh
Copy link
Author

I have also yet to figure out the best way to do array comprehension, accounting for while, do while and for, and also making sure that nested comprehension works as well

@gerblesh
Copy link
Author

gerblesh commented Dec 23, 2024

it may be worth looking into https://tree-sitter.github.io/tree-sitter/creating-parsers#external-scanners for the range operator/floats, the regex for the floats would be hard to get right

@gerblesh
Copy link
Author

gerblesh commented Dec 23, 2024

"fixed" the range expression for now. Still really confused on how to deal with the conditional operator thing. Looks like it conflicts with type_params??

@tobil4sk
Copy link
Contributor

Instead of having specific constructs for array comprehensions, perhaps for/while should be allowed as a generic "expression" element, and expressions should be allowed within [ ].

@tobil4sk
Copy link
Contributor

There's some odd behavior where when trying to do the range operator on two ints, the grammar thinks it's a float:
1...5 would give (float) instead of ( (integer) (integer))

Fixing this regex may solve the float problem:

float: ($) => choice(/[\d_]+[\.]+[\d_]*/, /[\d_]+[\.]+[\d_]*e[\d_]*/),

Right now it accepts any number of . >= 1.

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.

2 participants