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:
1 parent
49835424ee
commit
e029853e32
375 files changed
+6591
-4790
No files matched your search
+100
-69
@@ -3,12 +3,14 @@ import:
|
||||
utf8: "../text/utf8.mq.md"
|
||||
---
|
||||
|
||||
# @exec file
|
||||
|
||||
## 读文本
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
以 UTF-8 读取一个有界的项目文件。文件在打开时整文件载入,上限 8 MiB;
|
||||
结果使用可恢复 `Result` 形状。
|
||||
结果使用可恢复 Result 形状。
|
||||
|
||||
**流 = resource.open("file", 路径, ["read"])**
|
||||
|
||||
@@ -18,32 +20,40 @@ import:
|
||||
|
||||
**关闭 = resource.close(流)**
|
||||
|
||||
1. `not 读取.ok`
|
||||
`if not 读取.ok`
|
||||
|
||||
*读取*
|
||||
`return 读取`
|
||||
|
||||
2. `not 关闭.ok`
|
||||
`else`
|
||||
`if not 关闭.ok`
|
||||
|
||||
*关闭*
|
||||
`return 关闭`
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**文本 = utf8.解码(内存, 0, 读取.value.count)**
|
||||
**文本 = utf8.解码(内存, 0, 读取.value.count)**
|
||||
|
||||
1. `not 文本.ok`
|
||||
`if not 文本.ok`
|
||||
|
||||
*文本*
|
||||
`return 文本`
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: 文本.value}*
|
||||
`return {ok: true, value: 文本.value}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
## 写文本
|
||||
|
||||
`(路径, 文本)`
|
||||
`params(路径, 文本)`
|
||||
|
||||
把文本按 UTF-8 写入项目文件。路径必须已经通过 `fs_write` 授权;
|
||||
文件只在 `resource.close` 成功时创建或覆盖,写入缓冲上限 8 MiB。
|
||||
把文本按 UTF-8 写入项目文件。路径必须已经通过 fs_write 授权;
|
||||
文件只在 resource.close 成功时创建或覆盖,写入缓冲上限 8 MiB。
|
||||
|
||||
**内存 = memory.new(128, 128)**
|
||||
|
||||
@@ -55,24 +65,29 @@ import:
|
||||
|
||||
**关闭 = resource.close(流)**
|
||||
|
||||
1. `not 写入.ok`
|
||||
`if not 写入.ok`
|
||||
|
||||
*写入*
|
||||
`return 写入`
|
||||
|
||||
2. `not 关闭.ok`
|
||||
`else`
|
||||
`if not 关闭.ok`
|
||||
|
||||
*关闭*
|
||||
`return 关闭`
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: {count: 写入.value.count}}*
|
||||
`return {ok: true, value: {count: 写入.value.count}}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
## 复制文件
|
||||
|
||||
`(源, 目标)`
|
||||
`params(源, 目标)`
|
||||
|
||||
按字节复制一个有界的项目文件。源读取和目标写入分别需要
|
||||
`fs_read`/`fs_write` 授权,结果值与 [`写文本`](#写文本) 相同。
|
||||
fs_read/fs_write 授权,结果值与 [写文本](#写文本) 相同。
|
||||
|
||||
**输入 = resource.open("file", 源, ["read"])**
|
||||
|
||||
@@ -82,125 +97,141 @@ import:
|
||||
|
||||
**关闭输入 = resource.close(输入)**
|
||||
|
||||
1. `not 读取.ok`
|
||||
`if not 读取.ok`
|
||||
|
||||
*读取*
|
||||
`return 读取`
|
||||
|
||||
2. `not 关闭输入.ok`
|
||||
`else`
|
||||
`if not 关闭输入.ok`
|
||||
|
||||
*关闭输入*
|
||||
`return 关闭输入`
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**输出 = resource.open("file", 目标, ["write"])**
|
||||
**输出 = resource.open("file", 目标, ["write"])**
|
||||
|
||||
**写入 = resource.write(输出, 内存, 0, 读取.value.count)**
|
||||
**写入 = resource.write(输出, 内存, 0, 读取.value.count)**
|
||||
|
||||
**关闭输出 = resource.close(输出)**
|
||||
**关闭输出 = resource.close(输出)**
|
||||
|
||||
1. `not 写入.ok`
|
||||
`if not 写入.ok`
|
||||
|
||||
*写入*
|
||||
`return 写入`
|
||||
|
||||
2. `not 关闭输出.ok`
|
||||
`else`
|
||||
`if not 关闭输出.ok`
|
||||
|
||||
*关闭输出*
|
||||
`return 关闭输出`
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: {count: 写入.value.count}}*
|
||||
`return {ok: true, value: {count: 写入.value.count}}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
## 存在
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
*resource.request("fs.exists", [路径])*
|
||||
`return resource.request("fs.exists", [路径])`
|
||||
|
||||
## 元数据
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
*resource.request("fs.metadata", [路径])*
|
||||
`return resource.request("fs.metadata", [路径])`
|
||||
|
||||
## 是文件
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
**元数据 = resource.request("fs.metadata", [路径])**
|
||||
|
||||
1. `not 元数据.ok`
|
||||
`if not 元数据.ok`
|
||||
|
||||
*元数据*
|
||||
`return 元数据`
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: 元数据.value.kind == "file"}*
|
||||
`return {ok: true, value: 元数据.value.kind == "file"}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
## 是目录
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
**元数据 = resource.request("fs.metadata", [路径])**
|
||||
|
||||
1. `not 元数据.ok`
|
||||
`if not 元数据.ok`
|
||||
|
||||
*元数据*
|
||||
`return 元数据`
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: 元数据.value.kind == "directory"}*
|
||||
`return {ok: true, value: 元数据.value.kind == "directory"}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
## 列出目录
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
*resource.request("fs.list", [路径])*
|
||||
`return resource.request("fs.list", [路径])`
|
||||
|
||||
## 创建目录
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
*resource.request("fs.mkdir", [路径])*
|
||||
`return resource.request("fs.mkdir", [路径])`
|
||||
|
||||
## 删除
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
删除一个文件或空目录。非空目录返回 `fs.not_empty`,不递归删除。
|
||||
删除一个文件或空目录。非空目录返回 fs.not_empty,不递归删除。
|
||||
|
||||
*resource.request("fs.remove", [路径])*
|
||||
`return resource.request("fs.remove", [路径])`
|
||||
|
||||
## 重命名
|
||||
|
||||
`(源, 目标)`
|
||||
`params(源, 目标)`
|
||||
|
||||
目标已存在时返回 `fs.exists`,不覆盖。
|
||||
目标已存在时返回 fs.exists,不覆盖。
|
||||
|
||||
*resource.request("fs.rename", [源, 目标])*
|
||||
`return resource.request("fs.rename", [源, 目标])`
|
||||
|
||||
## 追加文本
|
||||
|
||||
`(路径, 文本)`
|
||||
`params(路径, 文本)`
|
||||
|
||||
把文本追加到项目文件;文件不存在时创建。仍受 8 MiB 单次读取上限和
|
||||
`fs_write` 授权约束。
|
||||
fs_write 授权约束。
|
||||
|
||||
*resource.request("fs.append", [路径, 文本])*
|
||||
`return resource.request("fs.append", [路径, 文本])`
|
||||
|
||||
## 读取片段
|
||||
|
||||
`(路径, 偏移, 长度)`
|
||||
`params(路径, 偏移, 长度)`
|
||||
|
||||
从偏移处读取最多 `长度` 字节,按 UTF-8 解码后返回文本。偏移/长度必须
|
||||
从偏移处读取最多 长度 字节,按 UTF-8 解码后返回文本。偏移/长度必须
|
||||
是非负整数,长度上限 8 MiB。
|
||||
|
||||
*resource.request("fs.read_at", [路径, 偏移, 长度])*
|
||||
`return resource.request("fs.read_at", [路径, 偏移, 长度])`
|
||||
|
||||
## 遍历
|
||||
|
||||
`(路径)`
|
||||
`params(路径)`
|
||||
|
||||
递归列出目录下的普通文件,返回相对项目根的路径列表。跳过符号链接,
|
||||
深度上限 64,条目上限 4096。
|
||||
|
||||
*resource.request("fs.walk", [路径])*
|
||||
`return resource.request("fs.walk", [路径])`
|
||||
Reference in new issue
Block a user