Self-hosting (38)
The plan: rewrite the front end in Trine, one stage at a time, each stage checked against the Rust implementation on the same inputs before the next starts.
38a: the lexer (selfhost/lexer.tr)
trine tokens FILEprints the Rust lexer's tokens in a canonical form (one per line:line:col Kind payload, orerror line:col message).trine run selfhost/lexer.tr --allow-read=DIR -- DIR FILE.trprints the same from Trine.- The test suite compares them on every example, 17 corner cases (each lexer error, CRLF, f-string parts and
:.N,{{, unbalanced brackets, empty input) and the lexer's own source. 40 fuzzer programs also matched when it was written. - ~330 lines of Trine; it uses only what the card documents (records,
match,Resultwith?, maps for the keyword and symbol tables,chars/ord). Writing it found one gap: Trine strings have no\rescape (it useschr(13)). - Known difference: outside strings and comments a non-ASCII character counts as a letter (Rust's
is_alphabetichas the Unicode tables; Trine doesn't yet).
Next: the parser (38b), producing the same AST dump as the Rust parser.