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

+3 -1
View File
@@ -3,8 +3,10 @@ import:
clock: "std:clock"
---
# @exec clock
## main
**现在 = clock.现在()**
*[现在.ok, 类型(现在.value), 现在.value > 1600000000000]*
`return [现在.ok, 类型(现在.value), 现在.value > 1600000000000]`
+3 -1
View File
@@ -3,10 +3,12 @@ import:
compress: "std:compress"
---
# @exec compress
## main
**压缩结果 = compress.压缩("hello 世界")**
**解压结果 = compress.解压(压缩结果.value)**
*[压缩结果.ok, 长度(压缩结果.value) > 0, 解压结果.ok, 解压结果.value]*
`return [压缩结果.ok, 长度(压缩结果.value) > 0, 解压结果.ok, 解压结果.value]`
+3 -1
View File
@@ -3,8 +3,10 @@ import:
console: "std:io/console"
---
# @exec console
## main
**行 = console.读取行()**
*[行.ok, 行.value]*
`return [行.ok, 行.value]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
csv: "std:data/csv"
---
# @exec csv
## main
**`行 = csv.解析行("甲,\"乙,丙\",\"说\"\"好\"")`**
@@ -17,4 +19,4 @@ import:
**格式化 = csv.格式化(多行.value)**
*[行.value, csv.格式化行(行.value), 空.value, 坏.code, 框.value, 多行.ok, 多行.value, 格式化]*
`return [行.value, csv.格式化行(行.value), 空.value, 坏.code, 框.value, 多行.ok, 多行.value, 格式化]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
datetime: "std:datetime"
---
# @exec datetime
## main
*[datetime.格式化(0), datetime.格式化(1700000000123), datetime.解析("1970-01-01T00:00:00Z").value, datetime.解析("2026-11-21T08:00:00.123Z").value, datetime.解析("2026-13-01T00:00:00Z").ok, datetime.解析("2026-02-29T00:00:00Z").ok, datetime.格式化(-1)]*
`return [datetime.格式化(0), datetime.格式化(1700000000123), datetime.解析("1970-01-01T00:00:00Z").value, datetime.解析("2026-11-21T08:00:00.123Z").value, datetime.解析("2026-13-01T00:00:00Z").ok, datetime.解析("2026-02-29T00:00:00Z").ok, datetime.格式化(-1)]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
demo: "std:demo"
---
# @exec demo
## main
*demo.演示函数()*
`return demo.演示函数()`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
env: "std:env"
---
# @exec env
## main
**存在 = env.存在("MARQDO_TEST_ENV")**
@@ -11,4 +13,4 @@ import:
**缺失 = env.读取("MARQDO_MISSING_ENV")**
*[存在.ok, 存在.value, 读取.ok, 读取.value, 缺失.ok, 缺失.code]*
`return [存在.ok, 存在.value, 读取.ok, 读取.value, 缺失.ok, 缺失.code]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
format: "std:format"
---
# @exec format
## main
*[format.字节长度("Aé"), format.显示(["文本", 2, 1.5]), format.显示({a: 1}), format.列表显示(["a", 2]), format.显示(None)]*
`return [format.字节长度("Aé"), format.显示(["文本", 2, 1.5]), format.显示({a: 1}), format.列表显示(["a", 2]), format.显示(None)]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
fs: "std:fs/file"
---
# @exec fs
## main
**创建 = fs.创建目录("out")**
@@ -33,4 +35,4 @@ import:
**删除目录 = fs.删除("out")**
*[创建.ok, 写入.value.count, 存在.value, 元数据.value.kind, 元数据.value.size, 列表.value, 是文件.value, 是目录.value, 重命名.ok, 读取.value, 追加.value, 片段.value, 遍历.value, 删除.ok, 删除目录.ok]*
`return [创建.ok, 写入.value.count, 存在.value, 元数据.value.kind, 元数据.value.size, 列表.value, 是文件.value, 是目录.value, 重命名.ok, 读取.value, 追加.value, 片段.value, 遍历.value, 删除.ok, 删除目录.ok]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
http: "std:net/http"
---
# @exec http
## main
**响应文本 = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n6\r\n world\r\n0\r\n\r\n"**
@@ -19,4 +21,4 @@ import:
**请求文本 = http.字节文本(请求字节)**
*[响应.状态, 响应.原因, 响应.头["Content-Type"], 响应.体, 请求, 响应字节.value.status, 正文.value, 请求文本.value]*
`return [响应.状态, 响应.原因, 响应.头["Content-Type"], 响应.体, 请求, 响应字节.value.status, 正文.value, 请求文本.value]`
+4 -2
View File
@@ -3,8 +3,10 @@ import:
io: "std:io"
---
# @exec io
## main
> io.写值("stdlib self-test")
> **io.写值("stdlib self-test")**
*None*
`return None`
+11 -7
View File
@@ -3,6 +3,8 @@ import:
json: "std:data/json"
---
# @exec json
## main
**`对象 = json.解析("{\"a\": 1, \"b\": [true, null, \"说\\\"好\"]}")`**
@@ -17,22 +19,24 @@ import:
**深度下标 = 0**
- `深度下标 < 130`
`while 深度下标 < 130`
**深度文本 = 深度文本 + "["**
**深度文本 = 深度文本 + "["**
**深度下标 = 深度下标 + 1**
**深度下标 = 深度下标 + 1**
`end`
**深度下标 = 0**
- `深度下标 < 130`
`while 深度下标 < 130`
**深度文本 = 深度文本 + "]"**
**深度文本 = 深度文本 + "]"**
**深度下标 = 深度下标 + 1**
**深度下标 = 深度下标 + 1**
`end`
**深度 = json.解析(深度文本)**
**`多个 = json.解析多个("1 2 [3]")`**
*[对象.ok, 对象.value.a, 对象.value.b[2], json.格式化(浮点.value), 失败.ok, 失败.code, 尾随.code, 深度.ok, 深度.code, 多个.ok, 多个.value]*
`return [对象.ok, 对象.value.a, 对象.value.b[2], json.格式化(浮点.value), 失败.ok, 失败.code, 尾随.code, 深度.ok, 深度.code, 多个.ok, 多个.value]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
path: "std:path"
---
# @exec path
## main
*[path.连接(["a", "", "b", "c"]), path.文件名("a/b/c.txt"), path.目录名("a/b/c.txt"), path.扩展名("a/b/c.txt"), path.规范("./a//b/../c"), path.规范("/a/./b/../c"), path.规范("../a/b"), path.是否绝对("/a"), path.是否绝对("a")]*
`return [path.连接(["a", "", "b", "c"]), path.文件名("a/b/c.txt"), path.目录名("a/b/c.txt"), path.扩展名("a/b/c.txt"), path.规范("./a//b/../c"), path.规范("/a/./b/../c"), path.规范("../a/b"), path.是否绝对("/a"), path.是否绝对("a")]`
+3 -1
View File
@@ -3,8 +3,10 @@ import:
process: "std:process"
---
# @exec process
## main
**结果 = process.运行("/bin/echo", ["hello"])**
*[结果.ok, 结果.value.status, 结果.value.stdout, 结果.value.stderr]*
`return [结果.ok, 结果.value.status, 结果.value.stdout, 结果.value.stderr]`
+3 -1
View File
@@ -3,10 +3,12 @@ import:
random: "std:random"
---
# @exec random
## main
**字节结果 = random.字节(16)**
**整数结果 = random.整数(100)**
*[字节结果.ok, 长度(字节结果.value), 整数结果.ok, 整数结果.value >= 0, 整数结果.value < 100]*
`return [字节结果.ok, 长度(字节结果.value), 整数结果.ok, 整数结果.value >= 0, 整数结果.value < 100]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
regex: "std:regex"
---
# @exec regex
## main
**`星号 = regex.匹配("a*b", "aaab")`**
@@ -31,4 +33,4 @@ import:
**捕获 = regex.捕获("^(a+)(b|c)$", "aab")**
*[星号.value, 加号.value, 锚点.value, 类.value, 否定类.value, 任意.value, 可选.value, 转义.value, 搜索.value, 无效.ok, 无效.code, 不支持.code, 扩展.value, 捕获.value.matched, 捕获.value.groups]*
`return [星号.value, 加号.value, 锚点.value, 类.value, 否定类.value, 任意.value, 可选.value, 转义.value, 搜索.value, 无效.ok, 无效.code, 不支持.code, 扩展.value, 捕获.value.matched, 捕获.value.groups]`
+3 -1
View File
@@ -3,8 +3,10 @@ import:
stream: "std:io/stream"
---
# @exec stream
## main
**结果 = stream.写文本("stream\n")**
*[结果.ok, 结果.value.count]*
`return [结果.ok, 结果.value.count]`
+3 -1
View File
@@ -3,6 +3,8 @@ import:
table: "std:data/table"
---
# @exec table
## main
**数据 = 表(["名称", "分数"], [["甲", 87], ["乙", 92], ["丙", 71]])**
@@ -25,4 +27,4 @@ import:
**分组 = table.分组(表(["类别", "值"], [["a", 1], ["b", 2], ["a", 3]]), 0, 1)**
*[选择, 过滤, 排序, 追加, 设置, 连接, 分组, 数据, table.转GFM(数据)]*
`return [选择, 过滤, 排序, 追加, 设置, 连接, 分组, 数据, table.转GFM(数据)]`
+3 -1
View File
@@ -3,10 +3,12 @@ import:
text: "std:text"
---
# @exec text
## main
**内存 = memory.new(1, 1)**
**长度 = text.utf8编码("é", 内存, 0)**
*[长度, 内存[0], 内存[1]]*
`return [长度, 内存[0], 内存[1]]`
+3 -1
View File
@@ -3,10 +3,12 @@ import:
utf8: "std:text/utf8"
---
# @exec utf8
## main
**内存 = memory.new(1, 1)**
**长度 = utf8.编码("é", 内存, 0)**
*[长度, utf8.解码(内存, 0, 长度).value, utf8.解码(内存, 0, 1).ok]*
`return [长度, utf8.解码(内存, 0, 长度).value, utf8.解码(内存, 0, 1).ok]`