Skip to content

Commit 0f89d0d

Browse files
hyperpolymathclaude
andcommitted
compiler: port Parser.res -> Parser.affine (recursive-descent parser)
Fourth and largest module (1150 lines). Complete error-tolerant recursive-descent parser, faithful grammar and precedence. Functional state-threading: ParserState is immutable; producers return (Option<X>, ParserState) and callers thread via `let (x, st) = f(st)`; ReScript `ref` accumulators became `let mut` locals with (acc, state) while-loops. Full coverage: the expression ladder (ternary -> logical-or/and -> equality -> comparison -> term -> factor -> unary -> postfix -> primary), array/lambda/grouped primaries, call/index/member postfix chains; type expressions incl. Echo<A,B> / EchoR<A,B> and the >>-split close-angle; the full statement set incl. gutter-block error recovery; function/struct/main declarations; and the `parse` driver returning (Program, [Diagnostic]). Verified green with `affinescript check` and the full harness (Types/Lexer/Cst/Parser all ok). Documented faithful deviations: the >>-split token rewrite reproduced via array rebuild (tokens are immutable); the pre-existing node-`start` quirk reproduced exactly rather than corrected; minor error-recovery loop hardening to guarantee progress on a stray token. AffineScript checker bug found + worked around: an if-statement immediately followed by a tuple literal in tail position fails with E0104 "Expected a function, got Unit" (the if's () is applied to the tuple). Used explicit `return (...)`. Third affinescript bug this migration (after the module-resolver struct-field gap and the global `len` builtin-shadow); all worth upstreaming. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0195yA45jSSP7YDPwJSpw4bM
1 parent 5adb0fb commit 0f89d0d

1 file changed

Lines changed: 1150 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)