tree-sitter / tree-sitter-go

Go grammar for tree-sitter
MIT License
310 stars 65 forks source link

How do you handle automatic semicolon insertion in go grammar? #129

Closed bzy-debug closed 1 year ago

bzy-debug commented 1 year ago

I checkout the tree-sitter grammar repos of both javascript and scala, both of them have scanner.c to handle automatic semicolon. But tree-sitter-go seems not to have an external scanner, how do you handle automatic semicolon insertion then?

bzy-debug commented 1 year ago

I found the definition of terminator:

newline = '\n',
terminator = choice(newline, ';', '\0')

It seems that this rule simulates the behavior of automatic semicolon insertion.

If so, does this simulation achieve the same effect as ASI in go?

amaanq commented 1 year ago

Yeah because JS (and presumably scala) have edge-cases where a newline cannot handle automatic semicolon insertion, but Go is just fine.