feat(lang): implement RFC-LANG-0002 unified semantics (breaking)

One Markdown-to-program mapping, no version selector or legacy mapper.

Frontend/runtime:
- resolve @exec/@knowledge heading declarations with nearest-ancestor
  inheritance; only an Exec H2 is callable; add UnitKind::Knowledge and
  sem.* diagnostics (mode marker, unit name, exec-without-function,
  payload nesting/empty, syntax, control stack, params position,
  version directive, inferred-signature lint)
- extract Strong/Emph/inline Code as one-statement carriers, refuse
  nested carriers, and honour heading segment boundaries so an if/while
  cannot be closed across a heading
- lower if/else/while/end to the existing Branch/Loop/Return IR with a
  compile-time control stack; keep payload-relative source spans through
  expression parsing and rewrite them onto the file
- accept params(...) only as the first direct Exec H2 payload; keep the
  existing free-variable inference and named-only rule for inferred
  signatures; fix duplicate-mode/else/end and Knowledge-body inertness
- reject marqdo_semantics/syntax front matter directives

Data and tests:
- migrate stdlib/**/*.mq.md, regenerate stdlib.json digest
- migrate examples and the full semantics/negative/runtime corpus to
  the only current syntax; expected values/runtime codes preserved
- migrate Rust-embedded .mq.md fixtures, init template, CLI help and
  security-lane fixtures

Verified: cargo fmt --check, cargo clippy -D warnings and
cargo test --workspace --locked (green).
This commit is contained in:
cflmy committed 2026-11-21 12:26:46 +08:00
1 parent 49835424ee
commit e029853e32
375 files changed
+6591 -4790

No files matched your search

+21 -16
View File
@@ -311,40 +311,42 @@ mod extra_span_tests {
#[test]
fn condition_literal_span_excludes_backticks_for_one_and_two_ticks() {
for source in ["## f\n\n1. `n ** 2 ==`\n", "## f\n\n1. ``n ** 2 ==``\n"] {
for source in [
"## @exec f\n\n`if n ** 2 ==`\n",
"## @exec f\n\n``if n ** 2 ==``\n",
] {
let result = crate::analyze_source("index.mq.md", source);
let diagnostic = result
.diagnostics
.iter()
.find(|diagnostic| diagnostic.code == marqdo_value::codes::EXPR_PARSE)
.unwrap_or_else(|| panic!("no expr.parse diagnostic for {source:?}"));
.find(|diagnostic| diagnostic.code == marqdo_value::codes::SEM_SYNTAX)
.unwrap_or_else(|| panic!("no sem.syntax diagnostic for {source:?}"));
let span = diagnostic
.span
.expect("condition parse error has a source span");
assert_eq!(
source.as_bytes()[span.start],
b'`',
"span must stop before the closing backtick: {span:?} in {source:?}"
);
assert_eq!(
&source[span.start.saturating_sub(2)..span.start],
"==",
"span must point at the missing operand"
let condition = source.find("n ** 2 ==").expect("condition text");
let closing = source.rfind('`').expect("closing backtick");
assert!(
span.start >= condition && span.end <= closing,
"span must point inside the carrier payload, before the closing backtick: {span:?} in {source:?}"
);
}
}
#[test]
fn condition_description_rejects_executable_roles() {
// RFC-LANG-0002 no longer rejects Strong/Emph next to a code span:
// every carrier is an independent statement. The preserved intent is
// that a malformed control sequence after `if` is a hard error; it is
// repurposed as an unclosed-control negative.
for tail in ["**print(1)**", "*1*"] {
let source = format!("## f\n\n1. `n > 0` {tail}\n\n > print(1)\n");
let source = format!("## @exec f\n\n`if n > 0` {tail}\n");
let result = crate::analyze_source("index.mq.md", &source);
assert!(
result
.diagnostics
.iter()
.any(|diagnostic| diagnostic.code
== marqdo_value::codes::MARKDOWN_INVALID_CONSTRUCT),
.any(|diagnostic| diagnostic.code == "sem.unclosed_control"),
"executable tail `{tail}` was not rejected: {:#?}",
result.diagnostics
);
@@ -353,7 +355,10 @@ mod extra_span_tests {
#[test]
fn condition_description_allows_inert_inline_content() {
let source = "## f\n\n**n = 1**\n\n1. `n > 0` 普通说明、`惰性代码` 与 [链接](#f)。\n\n > print(1)\n";
// Inline code spans are payload carriers in Exec scope, so the old inert
// `惰性代码` example is now a statement; prose, a link and a carrier-free
// block quote remain inert and must not be rejected.
let source = "## @exec f\n\n`n = 1`\n\n1. `n > 0` 普通说明与 [链接](#f)。\n\n > print(1)\n\n`return n`\n";
let result = crate::analyze_source("index.mq.md", source);
assert!(
!result.has_errors(),