slackhq / tree-sitter-hack

Hack grammar for tree-sitter
MIT License
33 stars 16 forks source link

fix: set alias for /function(s)?/ to highlight it as "function" #36

Closed theHamsta closed 2 years ago

theHamsta commented 2 years ago

Summary

Regexes don't appear in the AST, so in lambdas "function" and "(" can not be highlighted properly.

Solution: replace regex by equivalent tokens.

Requirements (place an x in each [ ])

Wilfred commented 2 years ago

FWIW this doesn't seem right to me. The function in (function(int): int) is part of a type hint, so I wouldn't expect function to be treated as a keyword here. The other syntax highlighters for Hack don't treat it as a keyword.

Wilfred commented 2 years ago

I guess it makes sense to parse function as a separate token here, but I'd highlight it differently to function in global function or method declarations.