refactor(expression): own the v2 payload statement grammar

Move keyword recognition out of the Markdown mapper and into the single
expression/statement parser:

- add parse_payload_statement + PayloadStatement for if/else/while/end/
  return/params/ordinary; keyword matching uses complete tokens, requires
  whitespace before a control expression, rejects trailing tokens/colons
  and reserves the statement words in expression positions
- keep expression spans payload-relative so the frontend can rewrite them
  onto the file; malformed params(...) interiors stay owned by the
  signature parser (one sem.syntax diagnostic, not a duplicate)
- simplify the frontend mapper to control-stack lowering and mapped
  semantic diagnostics only
- emit sem.no_entry_function from run when no Exec H2 main exists
- add else-under-while, params-in-quote, Knowledge-inertness and
  no-entry tests; update the corpus counts
- make the EBNF parameter type annotation optional (params(n) is valid)

Verified: cargo fmt --check, cargo clippy -D warnings and
cargo test --workspace --locked: 501 passed, 0 failed, 2 ignored.
This commit is contained in:
cflmy committed 2026-11-21 12:29:07 +08:00
1 parent e029853e32
commit ffd1cc9862
14 files changed
+334 -145

No files matched your search

+18
View File
@@ -41,6 +41,18 @@ pub enum TokenKind {
Or,
/// `not`
Not,
/// `if` (statement keyword, not an identifier)
If,
/// `else` (statement keyword)
Else,
/// `while` (statement keyword)
While,
/// `end` (statement keyword)
End,
/// `return` (statement keyword)
Return,
/// `params` (signature keyword)
Params,
/// `(`
LParen,
/// `)`
@@ -307,6 +319,12 @@ impl<'a> Lexer<'a> {
"and" => TokenKind::And,
"or" => TokenKind::Or,
"not" => TokenKind::Not,
"if" => TokenKind::If,
"else" => TokenKind::Else,
"while" => TokenKind::While,
"end" => TokenKind::End,
"return" => TokenKind::Return,
"params" => TokenKind::Params,
_ => TokenKind::Ident(text.to_owned()),
}
}