Re:Tree-sitter: an incremental parsing system for programmin...
by chrisseaton on Monday February 22, 2021 @12:50PM
(#26227633)
Right you could just have a phase to fix-it-up after parsing. Much better than trying to shoe-horn an imperative action into a nice more-pure parser. Great idea!
There's no symbol table in the parser, so at parse time, we don't distinguish those cases:
In both cases the bit after the semicolon just parses as (identifier).For some use cases (e.g. syntax highlighting, depending on your colorization rules) it doesn't matter, and so we don't want to pay the cost. If it does matter (like in an actual implementation), then you'd have to implement this yourself and drive it by the parse tree you get from tree-sitter.