syntax: align for-header grammar to cstage (Go's three forms)

The bbdd8bed residue, ruled by the Go derivation (ww's for IS the Go
for; the cstage grammar is the language definition and already the
Go-shaped one):
- bare `for { }` accepted (align UP to parse.c:1023, incl. for-else);
- 3-clause cond and post each omissible — `for (init;; post)`,
  `for (init; cond)`, `for (init;)` (align UP, parse.c:1092-1097);
- 2-clause `for (cond; post)` REJECTED (align DOWN): the form exists
  in neither Go nor cstage (parse.c:1101 eats a stray ';' then
  requires ')'), so the old wwstage accept was a parser bug. The
  reject wording mirrors cstage's failure mode per stage.

forhdr_{brace,emptymid,partial} run fixtures pin the accepted forms
byte-identically; forhdr_twoclause_reject pins both reject fragments.
Corpus pin 1745/346/21/209/1169/3490.
This commit is contained in:
2026-08-08 19:19:27 +09:00
parent b52f30a894
commit 241f28c96b
6 changed files with 87 additions and 18 deletions

View File

@@ -0,0 +1,10 @@
//ww:run-exit 5
package main;
export fn main() i32 = {
let i: i32 = 0;
for {
i += 1;
if (i >= 5) { break; };
};
return i;
};

View File

@@ -0,0 +1,10 @@
//ww:run-exit 10
package main;
export fn main() i32 = {
let s: i32 = 0;
for (let i: i32 = 0;; i += 1) {
if (i >= 4) { break; };
s += i;
};
return s + 4;
};

View File

@@ -0,0 +1,20 @@
//ww:run-exit 12
package main;
export fn main() i32 = {
let a: i32 = 0;
for (let i: i32 = 0; i < 5) {
i += 1;
a = i;
};
let b: i32 = 0;
for (let j: i32 = 0;) {
j += 1;
if (j >= 3) { break; };
};
b = 3;
let k: i32 = 0;
for (k < 4;) {
k += 1;
};
return a + b + k;
};

View File

@@ -0,0 +1,12 @@
//ww:error c "expected ), got IDENT" ww "expected ')' after for"
// 2-clause `for (cond; post)` is a form in neither Go nor the cstage
// grammar — the old wwstage accept was a parser bug (aligned DOWN,
// rule 10 / the Go-derivation ruling). Both parsers consume the stray
// ';' and then demand ')'.
package main;
export fn main() i32 = {
let i: i32 = 0;
for (i < 5; i += 1) {
};
return i;
};