Skip to content

s2/parse: FRONT parser into the s2 Ast, errors as data - #15

Merged
vic merged 1 commit into
mainfrom
s2-parse
Nov 9, 2026
Merged

vic merged 1 commit into
mainfrom
s2-parse

Conversation

@vic

@vic vic commented Nov 9, 2026

Copy link
Copy Markdown
Owner

FRONT rung 2: the parser (s2/parse.srs, module Parse), recursive descent into the s2 Ast as s1/parse.srs does it. Every production returns Parse.Ok(value, rest) or Parse.Err(line, expected).

Covered:

  • def and extern def, with [] {} <> groups and exit facts;
  • enum; protocol (states, start, end, drop, ops, rule defs); handler;
  • types T[args]^<caps>; expressions by s1 precedence (left associative), unary, calls f[T]{a}(x), methods;
  • if (newline before else allowed), while, assignment, postfix match;
  • blocks by layout; val, var, handle; val C(a, b) = e becomes a one-arm match; char literal as an int.

Not yet: trait, given, type decls, spec def, clauses, forall/exists.

Oracle: tests/s2/ast.out (the printer's text of hand-built Asts) parses and prints back. There is one known blank-line difference, because tests/s2/ast.srs:120-121 prints two decls in two calls. Extra cases cover val C(a,b), a left-associative chain, an else line, and three parse errors. Five mutants each change the output. Local tests/run.sh: 185 ok, 0 FAIL.

…ors as data

Parse.source lexes, then parses the tokens as s1/parse.srs: def and extern def with binder groups
[] {} <> before and after the params and exit facts after the result type; enum with cases; protocol
with states, start, end, drop, ops (A -> B transitions) and rule defs; handler; types T[args]^<caps>;
expressions by precedence (s1 opLevel, left associative), unary - and !, calls f[T]{a}(x), methods,
if (a NL before else allowed), while, assignment, postfix match with flat patterns; blocks by layout
(the value is the last expression statement); val, var, handle; val C(a, b) = e becomes a one-arm match
over the rest of the block; a char literal is its int value. Each production returns Parse.Ok(value,
rest) or Parse.Err(line, expected). Not yet: trait, given, type, spec def, clauses, forall.

tests/s2/parse: tests/s2/ast.out (the printer's text of hand-built Asts) parses and prints back, with
one known blank-line difference (ast.srs prints two decls in two calls); val C(a, b), a left
associative chain, an else on its own line; three parse errors. Mutants: * at the level of +, right
associative operators, no NL before else, no val C(a, b), [] groups as {}: each changes the output.
@vic
vic merged commit cdf1596 into main Nov 9, 2026
3 checks passed
@vic
vic deleted the s2-parse branch November 9, 2026 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant