sh
sh copied to clipboard
syntax: consider incremental reparsing
Incremental reparsing has been around for a while, but it's getting popular as of recently. The idea is that one can very quickly re-parse an existing file if only a few bytes were changed, such as if the user wrote a character that modifies a single leaf syntax tree node.
In the extreme case, if a file has a million lines but only one line changed, it's reasonable to expect that re-parsing would only need to do considerable work for the changed line. The rest of the input should be skipped fairly fast, in the best-case scenario.
In particular, for big chunks of the syntax tree that have zero changes and would parse the same, we can avoid allocating strings and nodes in the parser. It's not clear to me that we can make the lexer do much less work, since in shell it's not independent. But we can try.