"Eco: An Editor for Composed Programs" based on SDE (Syntax Directed Editing)

This essay about Syntax Directed Editing by Laurence Tratt bubbled up on hackernews recently.

I had not heard specifically of SDEs before (although I had read some papers about JetBrains MSP and some of their R&D around abstract-syntax-tree driven editors), so I found the example Laurence provides about how his Eco editor uses grammars to define how polyglot code blocks can and cannot be composed together in the editor to be at least superficially similar to prosemirror’s schema + node architecture.

Below are a couple excerpts from the essay. Note how, like prosemirror,

  1. the editor depends on a predefined grammar defining what nodes are valid in the document

  2. the document cannot be serialized to plain text / ascii without loosing information, so instead the source code is serialized as compressed json.

I’m curious to know if prosemirror contributors have heard of SDEs before or if the architectural similarities are more the product of convergent evolution (or convergent design).


[in our prototype editor Eco,] we have taken a pre-existing incremental parsing algorithm and extended it such that one can arbitrarily insert language boxes at any point in a file. Language boxes allow users to use different language’s syntaxes within a single file. This simple technique gives us huge power. Before describing it in more detail, it’s easiest to imagine what using Eco feels like.

Imagine we have three modular language definitions: HTML, Python, and SQL. For each we have, at a minimum, a grammar. These modular languages can be composed in arbitrary ways, but let’s choose some specific rules to make a composed language called HTML+Python+SQL : the outer language box must be HTML; in the outer HTML language box, Python language boxes can be inserted wherever HTML elements are valid (i.e. not inside HTML tags); SQL language boxes can be inserted anywhere a Python statement is valid; and HTML language boxes can be inserted anywhere a Python statement is valid (but one can not nest Python inside such an inner HTML language box). Each language uses our incremental parser-based editor. An example of using Eco can be seen in Figure 1.


Since, in general, one cannot guarantee to be able to parse as normal text the programs that Eco can write, Eco’s native save format is as a tree [4]. This does mean that one loses the traditional file-based notion of most programming languages. Fortunately, other communities such as Smalltalk have long since worked out how to deal with important day-to-day functionality like version control when one moves away from greppable, diffable, files. We have not yet incorporated any such work, but it seems unlikely to be a hugely difficult task to do so.

If you’re interested in finding out more about Eco , you can read the (academic) SLE paper this blog post is partly based on, or download Eco yourself [5]. The paper explains a number of Eco 's additional features—it has a few tricks up its sleeves that you might not expect from just reading this blog.

ref footnote
[4] It currently happens to be gziped JSON, which is an incidental detail, rather than an attempt to appeal to old farts like me (with gzip) as well as the (JSON-loving) kids.
[5] Depending on when you read this, you may wish to check out the git repository, in order to have the latest fixes included.

I hadn’t seen Eco before, but variants of these ideas can be found in structured Lisp editors like Paredit or even visual block languages like Scratch. I’m not a fan of them for programming, because their interfaces tend to either be painful to use or have a very steep learning curve, but who knows, with further improvements this might have a future.

Wikipedia redirects “Syntax Directed Editing” to the article “Structure editor”, and claims the phrases are synonymous.

“In linguistics, syntax is the study of the structure of grammatical utterances, and accordingly syntax-directed editor is a synonym for structure editor. Language-based editor and language-sensitive editor are also synonyms”

I started this thread mostly because I was surprised to see correspondence between prosemirror and this esoteric / forgotten approach to code editor architecture. The author indicated that SDEs AKA Structure Editors are rather exotic and not widely used or developed. But the WP article implies it is more well known. That said, the most recent reference in the citations is from 2000, and the majority are from the 1980s.

I’m generally interested in ways Structured Editing techniques could be employed to make better tools for writing, working with, reusing, and verifying documents, data, and files that are not intrinsically executable or structured. Gentle, unobtrusive automated ETL assistance, data capture / entry, file naming folder organization, content (re)discovery, staleness checking, progress reporting, document templating, intent modeling & workflow optimization…

The (ridiculously named) hottness these days is “robotic process automation”, basically DSLs and orchestration platforms to assist business information workers in being more efficient by automating otherwise manual (read: mouse) tasks, esp those that involve shuttling digital works-in-progress through an assembly line of sequential software tools that are not well integrated and may never offer official APIs powerful enough to enable deep integration. In effect, as more and more work is conducted digitally, workers are increasingly needed to fulfill the function the conveyer belt in an otherwise purely digital assembly line. The inputs are all digital. The tools are all digital. The output is all digital. The individual tools can be automated to some degree. But expert human operators are required to set up the tool, install it “on the line,” and very often direct or supervise its operation on each unit of work.

Why can’t our software assembly lines partially configure themselves, or at least suggest 10 best-guesses at how they might be configured, given 1) a set of representative inputs to to the work process (csvs, expense reports, SOPs, pdf forms, etc); 2) a couple of key words related to the desired output and/or representative mock output files; and/or 3) a constantly-refined markov model of previous workflow configurations based on observing / inferring process models from all previous file, disk, and application activity that seemed to be contingent a given Finished Document that was identified as such when it was emailed to the boss / client / printer. This is Process Mining. The data are probably already captured by IT departments in digital forensic log / enterprise antivirus / security database.

While 9 out of 10, or even 99 out of 100 of these autosuggested configurations or workflow scaffolds might be semantically invalid, if it only takes 10 minutes to evaluate all of the guesses, 1 hour to do a first pass to validate the behavior of the most promising prototype, but it alternatively will take 10+ hours to do the same manually… then man, why are knowledge workers effectively doing menial tasks akin to workholding, material transport, setting up and connecting the machines needed for the production run, etc.

Is anyone else interested in implicitly / inferentially structured data, “structured editing”, or in general trying to figure out how to build tools that reduce manual labor in digital assembly lines?