3 ms·
(Personal opinion) Constructing or incrementally updating an AST is not cheap. In particular, most ASTs are very fragile and there are characters when inserted
by Gehinnn 5y ago
(Personal opinion)
Constructing or incrementally updating an AST is not cheap. In particular, most ASTs are very fragile and there are characters when inserted at the wrong position invalidate the entire AST (e.g. prepending a C-like document with `/*`). Even prepending documents with `{` could render all nodes of the AST invalid, as they might get a different meaning (a class declaration might now be parsed as block statement).
The AST for the language of well-formed bracket pairs is very robust. There is no character that invalidates the entire AST.
There are characters though that invalidate all tokens, but there is a separate asynchronous (slow) method that updates them in the background and only then incrementally the bracket pair AST.
- pbiggar 5y ago> Constructing or incrementally updating an AST is not cheap. In particular, most ASTs are very fragile and there are characters when inserted at the wrong position invalidate the entire AST (e.g. prepending a C-like document with `/*`). Even prepending documents with `{` could render all nodes of the AST invalid, as they might get a different meaning (a class declaration might now be parsed as block statement). I think you have a worldview where text is being edited and ASTs are constantly being replaced via parsing. In an AST-based language, it doesn't necessarily have meaning to add some random character at some random spot, in the way that it does with text. With text, you can only recreate the entire AST by parsing, and discover that the parse is broken. With an AST-based language (such as https://darklang.com https://darklang.com), the editor could inform you that that character cannot be added in that place. Or it could allow you to put it there, informing you that that particular piece of text has no valid meaning, while the rest of the AST is still valid. (Darklang uses both approaches).
- sweetsocks21 5y agoI don't see why it couldn't be cheap if the editor always enforced being structurally valid? Then AST transformations are as fast as modifying a tree. A comment node would just wrap the necessary items and could unwrap them in linear/constant time. https://twitter.com/dm_0ney/status/1414742962442014720 https://twitter.com/dm_0ney/status/1414742962442014720