SelfscribeDownloadOpen the app

01 Kernel

The kernel is the only fixed grammar in Selfscribe. It must fit on one page and must never be extendable by rules, because it is what reads the rules.

1. Document shape

#
text
<optional rules block>
<body>

The rules block, if present, is the first non-blank content of the file (a UTF-8 BOM is skipped):

selfscribe
~~~ selfscribe
...rule lines and directives...
~~~
  • Opening fence: a line that is exactly ~~~, one or more spaces, selfscribe (case-insensitive). No indentation.
  • Closing fence: the next line that is exactly ~~~. Trailing whitespace is allowed on both fences.
  • Anything after the closing fence is the body. Later ~~~ lines in the body are ordinary text.
  • No closing fence: there is no rules block; the whole file is body, with a warning.
  • A file with no rules block behaves as if it started with ~~~ selfscribe / use markdown / ~~~

    (unless the host supplies project or workbook defaults, see 05 §2).

2. Lines inside the rules block

#

Each line is one of:

First tokenMeaning
blankignored
#comment to end of line (trailing comments: see 02 §1)
use PATHimport another .self file's rules here, in place (see 05). Only its rules block is read.
scope NAMEsubsequent rules belong to named scope NAME, until next scope or block end
scope (no name)return to the default scope
set KEY VALUEdocument setting or variable (see table below)
off [WHERE] PATTERN / off NAMEdisable a previously defined rule by pattern, or by as name
palette NAME VALUE [dark VALUE]a named colour (or any CSS value), used by rules as var(--NAME) (02 §4, D129)
palette (alone)start of a palette block: indented NAME VALUE [dark VALUE] lines follow
class NAME { css }style every element with class NAME, without a rule (02 §4, D130)
inline line block worda rule (grammar in 02)
rule [NAME]start of a full-form rule; indented key value lines follow (02 §5)

Settings understood by the kernel (set KEY VALUE):

KeyDefaultEffect
rulesshowhide tells editors to fold and hide the rules block. HTML output never contains it.
blanklinescollapsekeep renders each blank line between top-level nodes as a break
linebreakscollapsekeep renders each line break inside a paragraph as a break (br) instead of a space (D123); the plain rulebook sets it
indent2spaces per nesting level, 1..16 (a tab always counts as one level)
titlenonedocument title, exposed to renderers. Never inherited from imports.
slot_the capture-slot character for patterns that follow it in this file. Any single non-space character except \` . #`. Per file: never leaks into the importer.
projectonoff ignores host-supplied project and workbook defaults (05 §2)
any otherstored as a variable, readable by the var target (style is also read by hosts: 04 §6)

3. Body tokens the kernel owns

#

Only three things in the body are kernel-level. Everything else is rule-driven.

TokenMeaning
`` + ASCII punctuationescape: that character is literal and can never be part of a pattern match. Before anything else `` is an ordinary character.
@scope NAME on its own lineswitch the active rule scope until @end or end of the enclosing region
@end on its own lineclose the innermost @scope

Lines beginning with @ that are not one of the above are ordinary text.

4. Whitespace and encoding

#
  • Input is UTF-8. \n and \r\n both end a line; the \r is never content. The source is

    never rewritten, so spans stay valid; all output uses \n.

  • Leading indentation of a body line is measured (tabs = one level, spaces = indent setting) and kept on the AST node. Rules match against the line after indentation.
  • Trailing whitespace is ignored for matching but preserved inside verbatim regions.

5. Guarantees

#
  • The kernel never fails. Malformed rule lines become diagnostic entries and are skipped.
  • The kernel never executes anything. There is no eval, no expression language.
  • The kernel is total: any byte sequence produces an AST plus a (possibly non-empty) diagnostics list.