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
#<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
...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 token | Meaning |
| blank | ignored |
# | comment to end of line (trailing comments: see 02 §1) |
use PATH | import another .self file's rules here, in place (see 05). Only its rules block is read. |
scope NAME | subsequent rules belong to named scope NAME, until next scope or block end |
scope (no name) | return to the default scope |
set KEY VALUE | document setting or variable (see table below) |
off [WHERE] PATTERN / off NAME | disable 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 word | a 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):
| Key | Default | Effect |
rules | show | hide tells editors to fold and hide the rules block. HTML output never contains it. |
blanklines | collapse | keep renders each blank line between top-level nodes as a break |
linebreaks | collapse | keep renders each line break inside a paragraph as a break (br) instead of a space (D123); the plain rulebook sets it |
indent | 2 | spaces per nesting level, 1..16 (a tab always counts as one level) |
title | none | document 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. |
project | on | off ignores host-supplied project and workbook defaults (05 §2) |
| any other | stored 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.
| Token | Meaning |
| `` + ASCII punctuation | escape: 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 line | switch the active rule scope until @end or end of the enclosing region |
@end on its own line | close the innermost @scope |
Lines beginning with @ that are not one of the above are ordinary text.
4. Whitespace and encoding
#- Input is UTF-8.
\nand\r\nboth end a line; the\ris never content. The source isnever rewritten, so spans stay valid; all output uses
\n. - Leading indentation of a body line is measured (tabs = one level, spaces =
indentsetting) 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
diagnosticentries 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.