vantreeseba / tree-sitter-haxe

MIT License
26 stars 11 forks source link

Implement more accurate semicolon rules #43

Closed tobil4sk closed 3 months ago

tobil4sk commented 3 months ago

Haxe semicolon rules are a bit weird. In most places, a semicolon is required unless the previous token was }. The haxe parser implements this by looking back at the previous token: https://github.com/HaxeFoundation/haxe/blob/62854a7c2947ca95fd7b85a80d7e056cbf1d4d41/src/syntax/grammar.mly#L105-L114

I've added an external scanner to do something similar here, and it seems to be doing an alright job.

This could be further improved in this case:

a {} // this should be: a; {}

Here, haxe gives a missing semicolon error, but currently there is no useful error given by the grammar here:

(module
  (ERROR (identifier))
  (object)
)

This would be the test case for this:

===================
Omitted semicolon before block
===================
test{}
---
(module
  (identifier)
  (MISSING _lookback_semicolon)
  (object)
)
vantreeseba commented 3 months ago

Nice thanks, I'll look over this soon and pull it in.