The glyphs
Stoic has no keywords. It has seventeen glyphs, each with one job. Here is every one, with an example the compiler reads back.
- Element (< />) A thing. Any word is a tag: nothing is a keyword. Structure
- Name (:) Names an element, so it can be reused or tested. Structure
- Bind (=) Binds an element to data, or gives a field a value. Structure
- Reuse (->) A copy of another element, to adjust. Leave things out with #- and @-. Structure
- Repeat (*) One per entry of the parent’s data. Structure
- Field (#) A property, with its rules: limits, matches, capabilities. Structure
- Event (@) A trigger, and what it does, in plain words. Behaviour
- Note ("…") A quoted string touching a word fine-tunes that word. Behaviour
- How it runs (~ &) An animation (~, quick ~+, slow ~-), or in the background (&). Behaviour
- Strict (!) No exceptions. On an element, it holds for everything inside. Firmness
- Can bend (?) A preference, not a rule. Firmness
- Or-value (|) A value the field takes whatever its limits say. Firmness
- Examples (+ −) Accepted and rejected inputs. Each one is a test. Tests
- Given (^) A step that has happened before the action. Tests
- Expect (=>) What must, or must not (=>!), happen. Guidance for the test. Tests
- Checked value (=>=) An exact value the test reports back. Verify compares it with the lock. Tests
- Kept comment (<!--!) Guidance the implementer sees, for what a rule can’t say. Tests
- Your words (abc) Every tag, field, event, handler and capability. Nothing is a keyword. Everything else
Stoic has no vocabulary. Every tag, field, event, handler and capability is a word you choose, passed through verbatim for the reader to interpret, person or agent. What is fixed is a small set of glyphs, and each has exactly one job. Most are borrowed from things you already read: HTML's angle brackets, a shell's &, a pointer's ->.
They fall into four families: structure (what exists), behaviour (what happens), firmness (how strictly it holds) and tests (how we'll know).
Element
<tag … /> or <tag> children </tag> is a thing. A button, a table, a service, a pipeline step, a module's method. Leaving one unclosed at the end of a file is a warning.
<gallery>
<card />
</gallery>
A gallery. It contains a card.
Name
:name names an element, so it can be reused with ->, tested with <test:… =name>, or referred to by a field. Names are unique within a file, and within one lock a name is defined once.
<button:like @click="like the post" />
A button like that does "like the post" on click.
Bind
= after a tag binds an element to data or state. On a field, = gives a value, and when that value names another element it is a reference, not a copy.
<table:orders=postgres #region="eu-west-1" />
<query:recent=orders @run="orders placed in the last day" />
A table orders bound to postgres. Field region is eu-west-1.
A query recent bound to orders that does "orders placed in the last day" on run.
Reuse
-> makes a copy of another element to adjust, in this file or another (->ui.buttons.primary is primary in ui/buttons.stoic). #-name and @-name leave a field or event out.
<service:api #replicas(>=3) @crash="page oncall" />
<service:worker->api @-crash />
A service api that does "page oncall" on crash. Field replicas must be at least 3.
A service worker (like api). Field replicas must be at least 3.
Repeat
* after a tag means one per entry of the parent's data. The parent's actions apply to each one.
<list=todos #more([done, delete])>
<row* @click="open todo" />
</list>
A list bound to todos. Field more provides actions on each row: done and delete. Each row does "open todo" on click.
Field
#name(…) is a property and its rules: limits (>=3), quoted matches ("email"), must-not-contain (!" "), capabilities (sort, filter) and actions ([add, remove]).
<form #username(>=3, <=20, !" ") #created(sort, filter) />
A form. Field username must be at least 3 and at most 20 and must not contain spaces. Field created supports sort and filter.
Event
@name="…" is a trigger and what it does, in plain words. @* is every event. The handler is passed to the implementer verbatim, so write it the way you'd say it.
<pipeline @push="run checks" @tag="release to production" />
A pipeline that does "run checks" on push and does "release to production" on tag.
Note
A quoted string touching a word, with no space, fine-tunes that word. Notes go wherever detail matters: tags, events, fields, capabilities and actions. With a space it's an error, so you can't attach one by accident.
<button"pill shaped" @click"debounce 300ms"="save draft" />
A button ("pill shaped") that does "save draft" on click ("debounce 300ms").
How it runs
Between @ and the event: ~ is an animation (~+ quick, ~- slow) and & runs in the background, like & in a shell. They combine: @&~click.
<card @~hover @&open="prefetch the photo" />
A card that has an animation on hover and does "prefetch the photo" in the background on open.
Strict
! touching a name: no exceptions. On an element, it's the default for everything inside it.
<form!:payment #amount(>0) #note(<=140) />
A form payment (strict). Field amount must strictly be more than 0. Field note must strictly be at most 140.
Can bend
? touching a name: a preference, not a rule. Tests don't bend: a ? field's examples are still tests.
<form #bio?(<=500) #name(>=1) />
A form. Field bio should be at most 500 (can bend). Field name must be at least 1.
Or-value
|value is a value the field takes whatever its limits say: #cycles(>=1, |null) reads "must be at least 1, or null".
<job #retries(>=1, <=5, |null) />
A job. Field retries must be at least 1 and at most 5, or null.
Examples
+"…" must be accepted and -"…" rejected. +=1 and -=1.5 are values rather than text. Each example is a test, with an ID like signup_username_rejects_ad. +=>="…" and -=>="…" say what accepting and rejecting reports, as checked values.
<form:signup #username(>=3, +"ada", -"ad", +=>="'ok'", -=>="'TOO_SHORT'") />
A form signup. Field username must be at least 3, accepts "ada", and rejects "ad". Each accepted example reports exactly "'ok'"; each rejected one, exactly "'TOO_SHORT'".
Given
^"…" is a step that has already happened before a test's action, as many as it takes, in order. Among a field's arguments, it's how each of the field's examples is tried.
<cart:c @add="add an item" />
<test:full=c ^"99 items in the cart" @add =>="'FULL'" />
A cart c that does "add an item" on add.
A test full of c: given 99 items in the cart, on add, expect exactly "'FULL'" (reported back and compared).
Expect
=>"…" is what must happen and =>!"…" what must not. These are guidance for whoever writes the test: verify only sees whether it passed. They're marked (not checked) everywhere they're printed, honestly.
<form:f @submit="save" />
<test:saves=f @submit =>"saved" =>!"error shown" =>status="201" />
A form f that does "save" on submit.
A test saves of f: on submit, expect "saved", must not "error shown", and expect status exactly "201" (reported back and compared).
Checked value
=>="…" (or =>label="…" when a test has several) is the glyph that does the enforcing. The test reports the value it observed, and verify compares it with the locked one, as a value: numbers by value, objects in any key order. A test body can be wrong. Its observation can't hide.
<method:fee @call="8.75% of amount, rounded half to even" />
<test:fee600=fee @call="600" =>fee="52" />
A method fee that does "8.75% of amount, rounded half to even" on call.
A test fee600 of fee: on call with "600", expect fee exactly "52" (reported back and compared).
Kept comment
<!-- … --> is private and never appears in any output. <!--! … --> is kept: guidance for the implementer, for what a rule can't say. It belongs to the element it's in or right before, or to the whole file when it stands alone.
<!--! Left open: whether emails are trimmed. Your choice. -->
<form #email("email") />
A form. Field email must match "email".
Left open: whether emails are trimmed. Your choice.
Your words
Everything else is yours. <gallery>, <chip>, @tap, @clk and #vibe are as valid as <table> and @click. Stoic never checks a name against a vocabulary, because the reader, a person or a model, already knows what a gallery is.
<ritual:morning @dawn="make coffee, then read" #duration(<=30) />
A ritual morning that does "make coffee, then read" on dawn. Field duration must be at most 30.
All 18 examples on this page were compiled by Stoic at build time.