Concept tabs, one by one¶
Audience: language designers · ~10 min read · Prerequisites: The Language Editor
What each tab of a concept holds and the form it draws: the text syntax template, rules, running, scope and flow, tests, menus and the generation rules. The Appearance tab is described in Editing a concept. How the tabs behave (rows of rules, completion, undo) is in Editing a concept.
Text syntax: the template each grammar prints¶
The Text syntax tab shows how a concept is written in a model file, one template per grammar (python, javascript, ...):
python: print`${pad}while ${cond}:\n${suite(self.body)}`
javascript: print`${pad}while (${cond}) ${block(self.body)}`
reads "while_statement": condition → cond (derived), body → body (derived)
Literal text is plain. A blue chip is a slot of the concept (${cond}; a modifier such as .sf(false) follows it when the
grammar's default is not right). A pink chip is anything else a hole can hold: the statement's own indentation (${pad}),
a body (${suite(self.body)}, ${block(self.body)}), a joined list, or a part that is only there when a slot is
(${self.name.opt(...)}). \n is a line break.
readsline. Under a grammar that also reads text, it names the syntax-tree node it matches and which field fills which slot. A field marked derived needs nothing more (the slot's kind says how to read it); one marked explicit carries the modifier that says it otherwise (.as("text"),.inner()).- Host syntax nodes. A concept that is the host grammar's own syntax node (the TypeScript family) is drawn tagged with its
node type,
node("if_statement")`${prefix}${condition}${infix}...`, one hole per slot in stored order. An operator is one line,return infix("+");. - Rows after the reads. One per line: the reasons a syntax node is given up on (
.rejects(unlessToken("of"), ifFieldType("left", "identifier"))), how the types of a template are told apart (.forType(...)), a token that wraps the result (.wrapsWhenToken("async", "async")). Names complete from the builders. A call the tab cannot read stays after the template as written and is never dropped.
Edit the literal text and the names in place. Saving without an edit never reprints the body, and an edit prints the template back exactly as the tab shows it. The Syntax | Code switch shows the TypeScript the tab stores. A new Text syntax (the Create button of an empty tab) starts as the Python grammar's text with one hole per slot.
Rules: settings that complete¶
On the Rules tab each rule is an entry tab (see Editing a concept) of settings written key: value and the function that runs. A setting's key completes to
name, severity, slot and description; the value of severity completes to "error", "warning" and "info", and the value of slot to the
concept's own slots (the target of the rule); a value is the literal as written, so clear it first (Ctrl+Space lists what matches the text in the cell). The Rules | Code switch shows the TypeScript the rules print.
Running and Scope & flow¶
The Running tab shows what the node returns when it is run, in plain words: returns null, returns result of {left} awaited,
returns each {stmts} in order, result of the last, or returns code <expression> for anything else. Statements before the
return are the setup (code). In an empty result { builds the child hole with the caret in its slot cell (Ctrl+Space
lists the concept's slots), and the words constant, child, each and code pick a result from the completion. A new rule
starts from the concept's slots: a list child is evaluated in order, a single child is the result, a concept with no child
returns null. The Rules | Code switch shows the TypeScript.
The Scope & flow tab (Scope and Control flow) lists the flags the analysis reads; each known flag says what it means after
an arrow, for example isTerminator = true -> ends the flow or nameSlot = 0 -> is named by the child at this index. A flag's
key completes to the flags the analysis knows; an unknown setting has no caption and is kept as written. The words flag,
handler (a function such as process or analyze) and delegate pick a member from the completion. The scope settings
scope: block|function and visible: after declaration are not part of the hook and are not shown.
A function such as introduces: (node) => { ... } is shown with its body as highlighted code and printed as a method once you
edit the rules; an arrow function that reads this is kept exactly as written.
Tests, refactorings and migrations¶
The Tests tab shows each example as the snippet and what running it must give: given `1 + 2` expect result 3,
expect prints "hi", or expect fails (give fails an argument such as "not defined" to name a part of the error message).
Ctrl+Space after expect lists result, prints and fails; the cell after it holds the value, text or message part as
written. A backtick or ${ typed into the snippet is escaped for you. An example the form cannot say (a throw, several
statements, a snippet with ${...} in it) stays code, with the reason above it. The Example | Code switch shows the TypeScript.
Refactorings and Migrations stay code: they are decorated methods (@refactoring, @migration) that change the model, so there
is no fixed shape to draw. The completion menu says what each destructured parameter is (node, ask, model), and a new one
starts from a skeleton that shows the helpers. ask("Label", default) puts a question to you before the refactoring runs; it
needs a literal label and a literal default, and the default's type (text, number, true/false) is the type of the answer. A
migration @migration(1, 2) runs over the model: const item = model.resolve("concept", "name"), old = model.resolve("slot", "name/old"); for (const n of model.nodes(item)) n.set(old, n.property(old)).
Menus & actions¶
The Menus & actions tab has two forms for what a concept adds to the workbench. contributes() (the actions and commands it
offers on a node and in menus) reads as a form: actions: and commands: sections, each entry with its id, label, the
menus it is offered in and the code it runs. menus: ["context", "palette"] is one cell per menu, and Ctrl+Space in one
lists the real menus an action can be offered in (palette, context, edit); a command's menu setting completes to the
host's top-level menus (file, edit, view, run, navigate, tools, help). The code (run, isApplicable) stays code,
and so does events: {...}, a spread or anything else the form does not model, kept exactly as written. A diagram's
diagramActions() (the buttons on its toolbar) shows one tab per button, named by its label. Add either from the … menu.
Generation¶
The Generation tab starts with Rules of this concept: what every transformation of the language has for the open concept (a text template, a function, files, a reduce or a weave rule), read-only. Rules are written in generator models, which the tab lists with an Open button each (Writing a generator as a model). A bundled language's rule has Customize for this project: it copies the rule into a generator model of your project, which then replaces the bundled rule for this project only (delete the model to go back); see Generators and Open Preview.
The tab also shows a concept's reduce rule (the model-to-model rule that builds an output tree from the node) as the tree it
builds: builds Output with one line per argument. In the empty list click no arguments, press Ctrl+Space and pick a
word: copy (a copy of a slot's node, itself reduced afterwards), property (a slot's value as a property), each (a body once
per element of a slot; LOOP.index is the position), weave (a body woven in once per element), node (a nested output node),
value (a literal) or code (anything else, kept as written). Slots are named by the rule's parameters (bodyFn, fieldsFn,
…). This form is opt-in and new: no bundled concept has a reduce body. A body that is not one return stays code, with the
reason above it, and so does the weave hook (a rule that rewrites the output afterwards). Rules | Code shows the TypeScript.
Output text is a generator rule¶
There is no Output text tab. A concept's text is a rule of the language's generate transformation, written in a generator model (Writing a generator as a model): a text template such as while ${self.cond}: with ${self.slot} holes, or a code rule when the text needs code. A class that still has a generate() method is no longer run: Run Generator reports each such concept (its text is a /* generator error ... */ comment naming it), the Health section lists them, and the method shows under More until you move its text into a rule.