Stream: ideas

Topic: structural editing with temporarily invalid ASTs


view this post on Zulip Richard Feldman (Jul 20 2022 at 17:21):

I heard from Paul Biggar (who made Dark lang) that of the couple thousand people who have used Dark, a common experience is that creating text in Dark's structural editor feels nice, but editing doesn't feel nice

view this post on Zulip Richard Feldman (Jul 20 2022 at 17:21):

an example is when you have fn ["foo", "bar"] and you want to combine the two string literals by putting the right after the " in "bar and pressing backspace 4 times

view this post on Zulip Richard Feldman (Jul 20 2022 at 17:22):

in a traditional text editor, at some point in there you have a syntactically invalid state like fn ["foo", bar"]

view this post on Zulip Richard Feldman (Jul 20 2022 at 17:23):

or copy/pasting one part of the AST into another part, while highlighting something that doesn't happen to be right on an expression boundary, or even on a token boundary

view this post on Zulip Richard Feldman (Jul 20 2022 at 17:25):

it seems like tylr has an interesting solution to this!

Other structure editors restrict you to simple operations on the AST. For example, if you have the expression 2 + 3 * 4 in Scratch or MPS, you can't select things like * 4 or even 2 + 3—never mind directly manipulate them—because they don't correspond to complete subtrees in the AST. Uniquely among structure editors, tylr lets you select and manipulate near-arbitrary range selections, including those corresponding to sub- and cross-tree portions of the AST.

view this post on Zulip Richard Feldman (Jul 20 2022 at 17:26):

it also seems like doing this from an AST perspective in conjunction with typed holes from a type-checking perspective can mean that we can still support type introspection and related editor plugin things, even if parts of the tree are temporarily malformed

view this post on Zulip Ayaz Hafiz (Jul 20 2022 at 17:55):

It sounds like that in some sense, you'd like both editing over the AST and over the actual text buffer

view this post on Zulip Brendan Hansknecht (Jul 20 2022 at 17:58):

Didn't we already talk about how we want to be able to turn any node into a text buffer node. So if you ever directly edit the the text, it will convert the smallest section possible into a buffer node instead of a true AST node? If we can parse all or part of the buffer node, that will be converted into an AST node.

view this post on Zulip Richard Feldman (Jul 20 2022 at 17:59):

yeah, what's interesting is seeing a project that actually addresses the UX problem in practice!!

view this post on Zulip Anton (Jul 20 2022 at 18:00):

We've talked about something similar to the buffer node before, but your idea may be even better @Brendan Hansknecht :)

view this post on Zulip Qqwy / Marten (Jul 20 2022 at 18:05):

Cool! And definitely important to consider!

view this post on Zulip Qqwy / Marten (Jul 20 2022 at 18:06):

In Elixir there recently were new functions added to parse text into incomplete ASTs, also for better editor/language server /other tooling integration, for exactly the same reason


Last updated: Jun 16 2026 at 16:19 UTC