Checklist for changing minimaxon's language — a keyword, syntax, layout, a rule or a diagnostic — across the grammar, self/, runtime/, the seed and cmd/convert. Use for any edit to Maxon.g4 or to what programs may say, however small (for example renaming `is` to `implements`).
Install
npx skillscat add maxon-lang/maxon-rewrite-bootstrap/language-change Install via the SkillsCat registry.
Changing the language
A language change reaches the grammar, the checker's messages, every program that uses the construct (corpus,self/, runtime/, the program generator), cmd/convert, and the docs. Work through the list; skip a step only when
it clearly does not apply.
The compiler is self/, built from the seed (seed/README.md). The seed has the old language, so a change thatself/ or runtime/ must follow takes two commits: first the compiler accepts the new form while self/ andruntime/ still use the old one, and .\seed.ps1 renews the seed; then self/ and runtime/ move to the new form,
and the old one goes. A change that self/ and runtime/ do not use needs no new seed. A change of a layout that the seed
bakes into the code it makes and that the runtime shares with it (a String's two words) is one commit with the seeds renewed
for it by .\seed.ps1 --staged before it is committed (seed/README.md, "A change of a layout the seeds bake in").
0. Look at current maxon first
minimaxon is compatible with current maxon (C:\Users\Eric\Dev\maxon) except for deliberate language changes. Before
choosing a spelling, rule or message, see how maxon does it, and follow maxon unless the change is deliberate:
- Syntax:
Grepthe construct indocs/BNF_SYNTAX.mdanddocs/LANGUAGE_REFERENCE.md(the reference is ~420 KB:
search it, never read it whole). Stdlib andspecs/show real usage; the parser ismaxon-bin/Compiler/Parser*.maxon
(~600 KB each: grep, then read line ranges). - Codes and messages:
maxon-bin/Compiler/ErrorCodeRegistry.maxon(the code, with a comment saying what it means); grepErrorCode.<name>inmaxon-bin/Compiler/for the message text where it is raised. - A deliberate difference goes in README "Where it differs from Maxon" in the same change. Where maxon code is not
converted, it is still the reference for behaviour, edge cases and names.
1. Programs first, while the old syntax still lexes
A keyword rename: run the token-aware rewrite before touching the grammar. It covers the corpus,
self/,runtime/, and the code spans and untagged ormaxonblocks of the docs:.\build.ps1 ; .\bin\minimaxon.exe rewrite --keyword=old=new tests self runtime docs README.mdIt changes only keyword tokens (not names, labels, comments, string text or Markdown prose) and names what it could
not lex but that contains the word: fix those by hand. It refuses onceoldis no longer reserved. Rewritingself/andruntime/belongs to the second commit (see above).A layout change (spaces, joins, indentation, blank lines, comments): change the rule first (
Maxon.g4'snoSpaceBefore/^, orgapBefore,lineFaultandendFaultinself/syntax/parser.maxon), then let the
formatter rewrite every program in the new layout, and check:.\build.ps1 ; .\bin\minimaxon.exe fmt tests self runtime docs README.md ; .\bin\minimaxon.exe fmt --check tests self runtime docs README.mdfmtreads the old layout through the lenient lexer, so a rule the lexer enforces (E2001) may need its lenient case
too; a rule only the parser enforces (E2010) is formatted by the same function that checks it. Over a directory it
skips files that contain// expect-error: E2001orE2010, the tests of the layout rules: update those by hand to
break the new rule. A file it cannot parse is listed and left alone.Other syntax changes: no tool yet. Edit by hand, or write a throwaway script in the scratchpad (a reusable one
is a command of the compiler or goes incmd/<name>/as plain Go). Match on declaration shapes, never bare words,
and read the diff for prose hits in.mdfiles.
2. The grammar and what it generates
- Edit
self/syntax/Maxon.g4, thengo generate ./internal/.... Never edit a*_gen.*file. - That regenerates
self/ast/nodes_gen.maxon(emit_maxon.go),self/syntax/tokens_gen.maxon
(emit_maxon_tokens.go),self/syntax/parser_gen.maxon(emit_parser.gothroughemit_parser_maxon.go) and the
keywordscmd/convertreserves (cmd/convert/reserved_gen.go).go test ./internal/grammargenfails when a
checked-in generated file is stale. self/'s hand-written code that uses the construct is rewritten with step 1's tools (rewrite,fmt) or a script,
so it compiles under the new grammar. Aself/file thatcmd/convertproduced is regenerated byconvert, never
hand-edited.
3. Words the compiler says
- Grep
self/check(andself/resolve,self/ir) for messages that spell the old syntax as a fix:grep -rn "'[^']*old[^']*'" self --include=*.maxon. Diagnostics name the fix, so they quote syntax often. - Identifiers named after a keyword (
convMutates): rename them too, so the code reads like the language. - A new diagnostic takes maxon's code and message text where maxon has one (
ErrorCodeRegistry.maxon). A code with no
maxon equivalent takes a number the registry does not use: check withgrep -n '"E3xxx"' C:\Users\Eric\Dev\maxon\maxon-bin\Compiler\ErrorCodeRegistry.maxonbefore adding its row toself/diag/codes.tsv(and its text tomessages.tsvwhere maxon words it), thengo generate ./internal/.... A
deliberately different message or code goes in "Where it differs from Maxon".
4. Programs built as text
- The program generator (
self/fuzz) spells each keyword it writes through one named constant
(self/fuzz/keywords.maxon), so a rename edits that constant. - Anything else that builds Maxon in strings (the self tests, the generators' Go tests over tiny grammars): grep for
the old form; the tests catch what grep misses.
5. cmd/convert
cmd/convert turns maxon code into minimaxon code (go run ./cmd/convert [--write] [--check] [--out=DIR] [<path>...];
it lays out its output with minimaxon.exe fmt, so build the compiler first). Its rules are incmd/convert/convert.go, tested by cmd/convert/convert_test.go:
- Converting maxon code must produce the new form: add or change the rule for the construct (
transformStmtAndExpr,transformFunctionHeader,transformTypealias, the header transforms,isNewReservedWord,renderFallbackLayout). - A change that makes minimaxon match maxon removes the rule that rewrote it, and its test case. Convert must leave
what now matches maxon alone. - Update the affected case in
convert_test.go, thengo test ./cmd/convert.
6. Tests
- Minimal testing: add a test only when a bug would otherwise come back or nothing in the corpus covers a feature.
A new rule or diagnostic does not need its own test by default; when one is added, an error test carries// expect-error: CODE at L:Cand a behaviour test goes intests/run/. - Test files named after the old syntax (
generic-mutates-argument-is-a-let.maxon) are renamed withgit mv.
7. Docs
README.md: the subset, layout, "Where it differs from Maxon", examples, reserved words, commands.docs/regions.mdwhen the memory model's syntax changes.- Reread every edited prose line: articles ("a
mutable", not "anmutable") and English uses of the word are the
usual mistakes.
8. Finish
.\check.ps1 --update-positionsIt runs every check (README "Tests"), stopping at the first failure; the corpus step receives the arguments.--update-positions moves expect-error positions that a change of line length shifted; read what moved. Before a
commit, .\check.ps1 passes. Commit only when asked, on main.