Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

How to add a keyword

Adding a keyword is a language change and therefore needs an ADR first (ADR 0006 is the current keyword set, amended by ADR 0017 for the exception keywords). Once the decision is made, the mechanical steps are:

  1. Add the variant to lexer::token::Keyword and its entries in both from_ident and as_str. Update the "N reserved words" counts in the module docs.
  2. Handle it in the parser: a dispatch arm in parse_statement (or the expression parser), a parse_* method, and — if it starts a statement — an entry in synchronize's recovery set.
  3. Add an ExprKind / StmtKind variant in ast.rs and a dump_* arm.
  4. Visit the new node in resolver.rs and execute it in interpreter::exec_stmt / eval. If it adds a Signal variant, the compiler will point out every match that must handle it.
  5. Update the grammar and prose in docs/spec/02-grammar.md, the relevant other docs/spec/ section, the guide, and the keyword list in docs/spec/01-lexical-structure.md and docs/guide/README.md.
  6. Amend ADR 0006 (or supersede it), and write the feature's own ADR.
  7. Tests: lexer test, parser tests (success + the malformed-syntax error), resolver test, interpreter tests, a golden program under crates/korrin/tests/programs/, the korrin_ish() property generator, and a CHANGELOG.md entry.