Language settings, styles and concept files¶
Audience: language designers · ~8 min read · Prerequisites: The Language Editor
Language settings¶
The Language tab is the language's settings page: one page for the whole language, not the open concept. Open it from the first tab of any concept, or right-click a language in the Explorer and choose Language settings…. Bundled and external languages show it read-only. Sections:
- Identity: name (renamed from the Explorer), label, description and Version. Raise the version when a change needs existing models migrated, then use Migrations… to write the steps.
- Imports: the languages whose concepts this one may use. Type a name to add one (completes from visible languages); a looping import is ignored with a warning.
- Persistence: the text Grammar models are stored in; saved models keep their own
# format:line. - Flags: the interfaces the language implements and their settings (see the class below).
- Generation: how nodes become text, or another language's model, read-only. The rules are written in generator models (Writing a generator as a model); this section lists what the language generates with. The set named
generateis the default (Run Generator andstrukts generate); any other name is a named output, run bystrukts generate --export <name>. - Generator plan: one row per step (
transform,checkpoint,fork,serialize); Move up, Move down and Delete step reorder from the keyboard; Add a plan starts one. - Enums, Styles (below) and Health: the coverage matrix, loops repaired at load (imports, concept hierarchies), notes on moved rules, concepts that still write text with a
generate()method (each should become a rule of thegeneratetransformation) and concepts with no type (they count asany). Names open the concept.
A rule is a text template (${self.slot} holes; .each(...) repeats per list item, .opt(...) writes only when a slot is filled), a function, files, a model-to-model rule, or a weave rule (a fragment injected after the reductions). A transformation also has one Post-process function over the whole output. In your own language edit a rule and press Apply (text that does not read is shown beside the rule and nothing changes), or use Add rule, Delete rule and Add transformation. A concept's own rules are edited in its Generation tab; here only the rules no concept tab shows are listed.
The language as a class¶
The language is drawn as a class, edited like any concept class:
export class Python extends Language(IHasReservedWords, IHasStringQuote) {
imports = ["core"];
enums = [{ "name": "Direction", "description": "", "members": [{ "name": "north", "value": 0 }] }];
styles = [{ "name": "kw", "color": "var(--kw)", "italic": true }];
reservedWords(lang) { return ["if", "else"]; }
stringQuote(lang) { return "'"; }
}
Language(...) names the interfaces it implements: ISupportsHostExecution, IShowsHoverTooltips, IHasReservedWords, IHasCommonModules, IHasStringQuote, IHasNullLiteral (reserved words, common modules, quote char, null literal glyph, host executor, preview format, file extension, hover tooltips). Extending an interface means implementing it: a method of the class holds the value (a literal, or code computed from lang). + extend an interface… adds one with its default method; Ctrl+Space inside Language(...) lists them.
Interface changes apply by themselves when you pause typing; the imports, enums and styles fields (plain list literals, written only when not empty) need Apply. A missing method is added with its default; a method no interface declares, an unknown interface, a bad import or a syntax error is reported under the class and nothing changes.
Coverage¶
The Coverage section is the health view: one row per concept, one column per aspect. Check coverage reads every concept's class (it runs when you ask) and shows ● where the concept declares something, ○ where it is empty and ✖ where it has errors or warnings. Click a cell or press Enter to open that concept on that aspect. The table is one tab stop (arrows, Home, End) with a full-sentence label per cell for screen readers.
A rule lives on the concept or interface it checks (Types > Checking rules and Rules), not in a language-wide list. If an older language still has language-level rules, this tab says where each went at load: onto the concept it names, or onto the language's own Concept entry (which applies to every concept); a rule whose name the concept already uses is dropped, with a warning on that concept.
Styles¶
The Styles section is the language's style sheet: named text styles a template refers to by name (style="kw"). Each has a name, an optional parent (Extends), a colour, a weight, italic, underline, a background and Extra declarations (letter-spacing: 1px). Colours may be theme tokens such as var(--accent-text), which follow light, dark and high-contrast themes. + add creates one and ✕ removes it; the Aa sample shows the result.
A style sets only text appearance (colour, background, font, spacing, decoration, opacity); anything else, and any value that could load a resource (url(...)), is refused with a note. A style named like a built-in (kw) replaces that look in this language, or extends it. Styles of imported languages apply too, with your own winning. An undefined name is noted and renders unstyled.
Tick look to make a style a look: it paints nothing, lists Classes this look adds, and the Appearance tab merges it onto a piece. Edit as CSS shows the sheet as plain CSS (.style-name { ... }, the parent as /* extends: parent */, a look as /* look: classes */); leaving the box replaces the sheet. Refused rules are listed under the box and stay in the text.
A project can override styles without touching the language: put a project.styles.json next to project.json, for example {"styles": [{"name": "kw", "color": "var(--accent-text)", "italic": true}]}. It uses the same fields and safe set, wins over the language's styles, is plain data (no trust prompt) and is read at project open and on window focus.
Concept files and libraries¶
A project language can keep concepts as class files. Put them in a folder named after the language file, beside it: for shapes.lang.js, the folder is shapes.concepts/, and each *.concept.js holds one or more concepts in the class form the bundled languages use (class Circle extends Concept(IStatement) { head = "circle"; ... }, with JSX in editor). Add new concept writes <name>.concepts/<Head>.concept.js and opens it on the same tabs; edits are written to the file and applied to the language at once.
- Imports are optional. The names a concept file needs are provided without one:
Concept,Interface,Prop,ChildSlot,Ref,Text,Child,Children,Br,Indent,Computed,Optional, the standard interfaces (IExpression,IStatement,INamedConcept, ...),node,typing(typing.result("number"),typing.same("expr"),typing.untyped("why"),typing.noValue()) and the Text syntax builders (persist,print,pad,suite, ...). You may spell them out withimport { Concept, Prop, Text } from "strukts/engine";; a name the engine does not provide is an error. All files of a language are one module, so an interface declared in one is visible in the others. - A library of the project holds shared code: a model folder whose
model.jsonsays"role": "library"and which holds one JavaScript file (helpers/model.jsonandhelpers/helpers.jsfor a libraryhelpers). A concept file imports it by the folder's name:import { shout } from "helpers";. A library keeps its other names private and can import only from"strukts/engine". Only named imports work; any other form, an unexported name or a clash is an error that says which. Libraries are found at any depth, not insidenode_modules,generatedor a*.conceptsfolder, and are models in the Explorer with no roots. The function rules of the transformations take their imports from Language settings > Transformations > Imports for the rule functions. - Where you see them. The Explorer lists libraries in a Libraries folder beside Concept files (hover to see who imports one, click to open it; right-click offers Open as text file); a concept from a file with imports shows an Imports line, marking an unresolved one "not found".
- Heads must be new: one a bundled or other project language already uses is refused, naming the owner. Comment-like text in JSX (
/*,//) is read as a comment; write it as a string. - It is code. Like the
.lang.jsbeside it, the folder runs as JavaScript, so it asks for trust once for the language, its concept files and its libraries together; editing any asks again, and the prompt lists what it covers. The command-line tool refuses it without--trust-project-code(Security and privacy). Saving the language writes its data only; the classes stay in their files. - Older concepts convert when the project opens. A concept kept as data in
.lang.jsis rewritten as a class file after a check that it describes exactly the same concept; anything that cannot convert stays as data and the editor says why. The original is kept once as<name>.lang.js.pre-classes.bak.
Bundled versus your own, and live changes¶
Bundled concepts are class-backed: the editor edits the concept's source file in the repository's plugins/ folder, so it works only in a development checkout, and the banner reads "Built-in language - changes made here are saved directly and can't be reverted to the shipped default." A concept you make is a class file too. To see changes live, open a model in the language you are editing in a split tab: every open editor on that language re-renders and re-checks, and nodes that no longer fit stay in the model as problems, never deleted.