tree-sitter-haxe icon indicating copy to clipboard operation
tree-sitter-haxe copied to clipboard

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

Open gerblesh opened this issue 1 year ago • 9 comments

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 avatar Dec 22 '24 05:12 gerblesh

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 avatar Dec 22 '24 09:12 gerblesh

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 avatar Dec 22 '24 09:12 gerblesh

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 avatar Dec 23 '24 05:12 gerblesh

"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??

gerblesh avatar Dec 23 '24 08:12 gerblesh

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 avatar Dec 23 '24 11:12 tobil4sk

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: https://github.com/vantreeseba/tree-sitter-haxe/blob/12e814cd9b0656b0eaa3e04b0036b3b6625cc0d7/grammar-literals.js#L12

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

tobil4sk avatar Dec 23 '24 11:12 tobil4sk

I think having this merged would also open up for support on Zed-Haxe, right?

9Morello avatar May 08 '25 15:05 9Morello

I think having this merged would also open up for support on Zed-Haxe, right?

This PR is still pretty underbaked and I don't have a whole lot of time to dedicate to learning haxe and treesitter as I am unfamiliar with haxe and treesitter currently. If you or anyone else wants to get this polished enough to merge and make a fully functioning haxe treesitter grammar feel free, not sure if the current maintainer checks this repo so it might be best to do the work in a fork

gerblesh avatar May 08 '25 19:05 gerblesh

That makes sense, thanks the detailed reply. :+1:

9Morello avatar May 12 '25 11:05 9Morello