From bfb10d172b5e27e60e2774289eb23743452240ac Mon Sep 17 00:00:00 2001 From: cflmy Date: Sun, 13 Sep 2026 20:38:53 +0800 Subject: [PATCH] feat(markup): adopt v0.3 as sole mapping (** code, * return) Make prose-unified Markup the only runtime: bold segments are executable, italic is return, params can be inferred from body/prose, with no v0.2 dual mode. Migrate lib and structure/keywords golds; gate on tests/markup-v03. Co-authored-by: Cursor --- .cursor/skills/marqdo/SKILL.md | 25 +- Cargo.lock | 4 +- doc/README.md | 5 +- doc/adr/0005-prose-unified-markup.md | 53 ++ doc/design/code-vs-comment.md | 17 +- doc/design/examples-and-tests.md | 27 +- doc/design/markdown-mapping-v0.3.md | 608 +++++++++++++++++++ doc/design/markdown-mapping.md | 3 +- doc/design/return-hr-and-code-surface.md | 22 +- doc/roadmap/markup-v0.3.md | 106 ++++ lib/browser.mq.md | 72 +-- lib/cli.mq.md | 2 +- lib/csv.mq.md | 4 +- lib/datetime.mq.md | 14 +- lib/encoding.mq.md | 12 +- lib/foreign.mq.md | 8 +- lib/fs.mq.md | 34 +- lib/hash.mq.md | 8 +- lib/html.mq.md | 4 +- lib/json.mq.md | 14 +- lib/log.mq.md | 18 +- lib/math.mq.md | 72 +-- lib/net.mq.md | 18 +- lib/path.mq.md | 14 +- lib/plugin.mq.md | 8 +- lib/re.mq.md | 10 +- lib/secrets.mq.md | 4 +- lib/stats.mq.md | 6 +- lib/subtask.mq.md | 10 +- lib/sys.mq.md | 18 +- lib/table.mq.md | 78 +-- lib/text.mq.md | 22 +- lib/time.mq.md | 10 +- lib/toml.mq.md | 2 +- lib/url.mq.md | 6 +- lib/uuid.mq.md | 2 +- lib/writeback.mq.md | 14 +- lib/命令行.mq.md | 2 +- lib/哈希.mq.md | 8 +- lib/地址.mq.md | 6 +- lib/外联.mq.md | 8 +- lib/子任务.mq.md | 10 +- lib/插件.mq.md | 8 +- lib/数学.mq.md | 72 +-- lib/文件.mq.md | 32 +- lib/文本.mq.md | 22 +- lib/日志.mq.md | 18 +- lib/日期时间.mq.md | 14 +- lib/时间.mq.md | 10 +- lib/机密.mq.md | 4 +- lib/标识.mq.md | 2 +- lib/正则.mq.md | 10 +- lib/浏览器.mq.md | 72 +-- lib/系统.mq.md | 18 +- lib/统计.mq.md | 6 +- lib/编码.mq.md | 12 +- lib/网络.mq.md | 18 +- lib/自写回.mq.md | 12 +- lib/表.mq.md | 78 +-- lib/超文本.mq.md | 4 +- lib/路径.mq.md | 14 +- lib/逗号表.mq.md | 4 +- lib/配置表.mq.md | 2 +- src/ast.rs | 2 + src/lex/mod.rs | 131 ++-- src/parse/mod.rs | 373 +++++++++++- src/parse/prose.rs | 150 +++++ tests/README.md | 1 + tests/gold.rs | 66 ++ tests/keywords/bool-logic.mq.md | 6 +- tests/keywords/input-escape.mq.md | 2 +- tests/keywords/input.mq.md | 2 +- tests/keywords/quoted-string.mq.md | 10 +- tests/keywords/stdlib-more.mq.md | 14 +- tests/keywords/stdlib.mq.md | 12 +- tests/keywords/zh-bool.mq.md | 6 +- tests/keywords/zh-builtins.mq.md | 8 +- tests/markup-v03/README.md | 21 + tests/markup-v03/bold-call.mq.md | 16 + tests/markup-v03/dead-bind.mq.md | 16 + tests/markup-v03/dual-call.mq.md | 16 + tests/markup-v03/empty-return-compat.mq.md | 15 + tests/markup-v03/empty-return-hr.mq.md | 15 + tests/markup-v03/empty-return-none.mq.md | 15 + tests/markup-v03/empty-return-stars.mq.md | 15 + tests/markup-v03/greet-default.mq.md | 23 + tests/markup-v03/inc-prose.mq.md | 16 + tests/markup-v03/multi-bold.mq.md | 9 + tests/markup-v03/print-bold.mq.md | 9 + tests/structure/bare-id-italic-bold.mq.md | 22 +- tests/structure/branch-consecutive.mq.md | 4 +- tests/structure/branch.mq.md | 2 +- tests/structure/collection-cell-expr.mq.md | 4 +- tests/structure/collection-map-list.mq.md | 6 +- tests/structure/collection-map.mq.md | 6 +- tests/structure/collection-records-at.mq.md | 4 +- tests/structure/collection-records.mq.md | 6 +- tests/structure/footnote-index.mq.md | 6 +- tests/structure/footnote-map-digits.mq.md | 4 +- tests/structure/gap-star-json-body.mq.md | 26 +- tests/structure/hello.mq.md | 2 +- tests/structure/import-lib.mq.md | 6 +- tests/structure/import/main.mq.md | 2 +- tests/structure/import/utils.mq.md | 2 +- tests/structure/inherit-explicit-super.mq.md | 20 +- tests/structure/inherit-override.mq.md | 16 +- tests/structure/inherit-parent-method.mq.md | 10 +- tests/structure/loop.mq.md | 4 +- tests/structure/narrative-bold.mq.md | 8 +- tests/structure/nested-call.mq.md | 4 +- tests/structure/ns/helpers.mq.md | 4 +- tests/structure/ns/path3.mq.md | 4 +- tests/structure/ns/use.mq.md | 2 +- tests/structure/object-handle.mq.md | 40 +- 114 files changed, 2271 insertions(+), 732 deletions(-) create mode 100644 doc/adr/0005-prose-unified-markup.md create mode 100644 doc/design/markdown-mapping-v0.3.md create mode 100644 doc/roadmap/markup-v0.3.md create mode 100644 src/parse/prose.rs create mode 100644 tests/markup-v03/README.md create mode 100644 tests/markup-v03/bold-call.mq.md create mode 100644 tests/markup-v03/dead-bind.mq.md create mode 100644 tests/markup-v03/dual-call.mq.md create mode 100644 tests/markup-v03/empty-return-compat.mq.md create mode 100644 tests/markup-v03/empty-return-hr.mq.md create mode 100644 tests/markup-v03/empty-return-none.mq.md create mode 100644 tests/markup-v03/empty-return-stars.mq.md create mode 100644 tests/markup-v03/greet-default.mq.md create mode 100644 tests/markup-v03/inc-prose.mq.md create mode 100644 tests/markup-v03/multi-bold.mq.md create mode 100644 tests/markup-v03/print-bold.mq.md diff --git a/.cursor/skills/marqdo/SKILL.md b/.cursor/skills/marqdo/SKILL.md index 06b7ef6..a8521e1 100644 --- a/.cursor/skills/marqdo/SKILL.md +++ b/.cursor/skills/marqdo/SKILL.md @@ -15,7 +15,7 @@ description: >- Marqdo = **Markdown markers as syntax**. A `.mq.md` file is both documentation and a runnable program. Read this skill **before** inventing syntax from Markdown habits or Python. -Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords.md`. Deeper tables: [reference.md](reference.md). Copy-paste patterns: [examples.md](examples.md). +Canonical design (repo): [`markdown-mapping-v0.3.md`](../../doc/design/markdown-mapping-v0.3.md) (**v0.3 · runtime**), `doc/design/keywords.md`. Legacy v0.2 notes: `doc/design/markdown-mapping.md` (historical). Deeper tables: [reference.md](reference.md). Copy-paste patterns: [examples.md](examples.md). **Authoring / library craft** (GFM-first, no json glue, how to develop Marqdo): use **[marqdo-dev](../marqdo-dev/SKILL.md)** whenever writing or refactoring `.mq.md`, `lib/*`, or `ext/*`. @@ -24,19 +24,18 @@ Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords. ## Hard rules (do not violate) 1. **File suffix** must be `.mq.md` (never plain `.md` for executable sources). -2. **Output is not `**bold**`.** Print with `> print text=…` (or `> 打印 内容=…`). Bold `**…**` is **return value only**. -3. **Prose vs code:** after a blank line, an unmarked first line starts a **comment paragraph**; every following non-blank line stays comment until the next blank line. Put a **blank line** between narration and executable lines. -4. **Do not invent keywords** `if` / `else` / `while` / `for` / `def` / `return`. Control flow is Markdown: **`+` params** (under heading), **`1.` `2.` … branches**, **`-` loops**, arm `N. *` = else, `#` = **object/type**, `##`+ = **function/method**, `**…**` = return. -5. **Identifiers use backticks** — params `` + `name` ``. **Exemptions:** foreach `` - [item](coll) ``; footnote `` name[^key] ``; **inside italic `*…*` / bold `**…**`**, bare ids are **variables** (Python-style unified namespace) and method-call receivers are bare too. **Drop the backticks on value-expression variable names and method receivers inside `*…*` / `**…**`** — they are redundant once the `*…*`/`**…**` markers mark the segment as code: `*分类 = 分类[^苹果]*`, `**n * 2**`, `*p = > page.主体装配 组件=home*`. **Text literals must be quoted**: `*a = > text.split value=src sep=","*`. Backticks **still required** where a bare word is *not* a variable in **standalone `>` calls** (bare = text there): `` > str `n` ``, `` > `obj`.method ``. **No trailing space** inside `*…*` / `**…**` wrapped code: the closing marker must touch the last token directly (`*a = 1*`, `**n**`), never `` *a = 1 * ``. -6. **Structure lines are not wrapped in italics.** `#` `>` `+` `-` `|` lines stand alone; use `*…*` only for general statements (bindings / expressions). -7. **Paths:** In bare *expressions* `/` is division. In **call args / param defaults / table cells**, unspaced `a/b` and quoted `".marqdo/agent-kb"` are path text — no `json.parse` needed. Numeric ratios that must stay text use quotes (`"1/5"`, `"16/9"`); bare `1/5` is division. -8. Prefer ending side-effect-only function bodies with a lone `---` or `***` line (or `****` empty return) so later siblings are not swallowed. +2. **`**…**` = code** (assign / call). **`*…*` = return value**. Output is **not** either marker — use `> print text=…` / `**print text="…"**` / `> 打印 内容=…`. +3. **Prose:** unmarked narrative may contain `` `名` `` (declare/ref), inline `**code**`, and `*return*`. Do **not** use `*`/`**` for Markdown emphasis in program files. Dead `` `名` `` (never read) is OK and does not become a param. +4. **Do not invent keywords** `if` / `else` / `while` / `for` / `def` / `return`. Control flow is Markdown: **`1.` `2.` … branches**, **`-` loops**, arm `N. *` = else, `#` = **object/type**, `##`+ = **function/method**. Params: prefer prose `` `名` `` / `` `名`=默认 `` (inferred); `` + `名` `` still accepted. +5. **Identifiers:** `` `名` `` in prose; inside `*…*` / `**…**`, bare ids are **variables**. **Text literals must be quoted** in bold/italic: `**print text="hi"**`. Standalone `>` calls: bare words = text; vars need ticks: `` > str `n` ``. +6. **Structure lines** (`#` `>` `+` `-` `|` `1.`) need not be wrapped in bold. +7. **Paths:** In bare expressions `/` is division. In call args / defaults / table cells, unspaced `a/b` and quoted paths are text. +8. Prefer ending side-effect-only bodies with `---` / `***` (or `*None*` / whole-line `**` / `****`). 9. **`ext/**` never calls `host_*`.** Agent/OKF helpers are plugin names (`agent_kb_*`, …) after `plugin.load`. Do **not** add agent/OKF domain code to `src/host/` (core bloat). See `doc/design/ext-agent.md` §4. 10. **Browser (route C/D/E/F):** client logic is Marqdo on WASM; official bridge is host glue and **may** implement lists, routing, storage, WebSocket, canvas, file read, observers — authors **must not hand-write business JS**. Use `web.client_embed` / `data-mq-source-url` auto-mount. Client effects: prefer **GFM tables + `lib/browser`** ([marqdo-dev](../marqdo-dev/SKILL.md)). 11. **Code-as-documentation / no bag glue:** Prefer **GFM tables** for maps, lists, wire, commands. Prefer **`table.put` / named helpers** over `json.set` / `json.append` chains. `lib/json` is for parse/stringify/quote only — not a dict builder. Unreadable json pipelines are a style bug. - -## Markup → meaning (v0.2) +## Markup → meaning (v0.3) | Marker | Meaning | |--------|---------| @@ -51,9 +50,9 @@ Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords. | Frontmatter `import bind:path.mq.md` / `导入` | Import file (bind library name) | | Frontmatter `import bind:lib.member` / `导入` | Short name for a library member (same keyword; no separate `use`) | | `> lib.member …` / `> lib.Type.member …` | Call via bare dotted path (instance methods need `` `var`.m ``) | -| `*…*` | Statement (bind / expr) — closing `*` touches last token, **no trailing space**; bare ids are variables | -| `**…**` | Return value — closing `**` touches last token, **no trailing space**; bare ids are variables | -| `****` or `**` + spaces + `**` | Return `None` and end function body | +| `**…**` | **Code** (assign / call) — closing `**` touches last token; bare ids are variables; quote text literals | +| `*…*` | **Return value** — closing `*` touches last token; bare ids are variables | +| `****` / whole-line `**` / `*None*` | Return `None` and end function body | | Lone `---` / `***` in function body | End function body (no value) | | GFM table after empty RHS bind | Collection (1-col list / ≥2-col map / `@`·`行`·`row` → list of maps); `` `x`[^1] `` / `` `m`[^key] `` | | `` ```lang `` | Foreign code block (via `lib/foreign`) | diff --git a/Cargo.lock b/Cargo.lock index d78106b..4516972 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -572,7 +572,7 @@ checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" [[package]] name = "marqdo" -version = "0.3.9" +version = "0.4.0" dependencies = [ "anyhow", "assert_cmd", @@ -603,7 +603,7 @@ dependencies = [ [[package]] name = "marqdo-wasm" -version = "0.3.9" +version = "0.4.0" dependencies = [ "marqdo", "serde_json", diff --git a/doc/README.md b/doc/README.md index 0f999ba..bdb759a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -15,7 +15,10 @@ | 文档 | 摘要 | |------|------| -| [design/markdown-mapping.md](design/markdown-mapping.md) | **v0.1 语法宪法** | +| [design/markdown-mapping.md](design/markdown-mapping.md) | **v0.2 语法宪法(现行运行时)** | +| [design/markdown-mapping-v0.3.md](design/markdown-mapping-v0.3.md) | **v0.3 草案:叙述统一 · 粗体代码 · 斜体返回 · 形参体推断** | +| [adr/0005-prose-unified-markup.md](adr/0005-prose-unified-markup.md) | **Proposed:采纳 mapping v0.3** | +| [roadmap/markup-v0.3.md](roadmap/markup-v0.3.md) | **Markup v0.3 实现路线(M0–M5)** | | [design/objects.md](design/objects.md) | **`#` 对象 / `##` 函数与方法** | | [design/ai-skill.md](design/ai-skill.md) | **AI 接入 Skill**([`skills/marqdo/`](../skills/marqdo/)) | | [design/code-vs-comment.md](design/code-vs-comment.md) | 叙述 / 可执行 / 外联 | diff --git a/doc/adr/0005-prose-unified-markup.md b/doc/adr/0005-prose-unified-markup.md new file mode 100644 index 0000000..196041f --- /dev/null +++ b/doc/adr/0005-prose-unified-markup.md @@ -0,0 +1,53 @@ +# ADR 0005:叙述统一的 Markup 映射(粗体即代码 · 斜体即返回 · 形参体推断) + +| | | +|---|---| +| Status | **Accepted** | +| Date | 2026-09-13 | +| Related | [markdown-mapping-v0.3.md](../design/markdown-mapping-v0.3.md) · [markdown-mapping.md](../design/markdown-mapping.md) · [return-hr-and-code-surface.md](../design/return-hr-and-code-surface.md) · [roadmap/markup-v0.3.md](../roadmap/markup-v0.3.md) | + +## Context + +- Marqdo 的产品承诺是「代码即文档 / 文档即代码」:`.mq.md` 打开是文章,运行是程序。 +- v0.2([markdown-mapping.md](../design/markdown-mapping.md))为消歧做了硬隔离:无标记 = 注释;`*…*` = 语句;`**…**` = 返回;调用必须 `>`;形参必须 `` + `名` ``。 +- 该隔离使叙述与程序**视觉割裂**;且与 AI/Markdown 习惯相反(模型偏好用 `**` 强调「要做的事」)。 +- 产品方重新审视后,希望合法化如下写法: + +```markdown +## 加一函数 +对于输入变量`n`,我们执行操作**n=n+1**接着返回*n*。 + +# main +> 加一函数 37 +或者可以直接这么调用**加一函数 37** +``` + +## Decision + +1. 采纳 **Markup 映射 v0.3** 为下一版语言宪法草案,全文见 [markdown-mapping-v0.3.md](../design/markdown-mapping-v0.3.md)。 +2. **角色对调**:`**…**` = 代码段(含可省略 `>` 的调用);`*…*` = 返回值。 +3. **叙述中的** `` `名` ``:**首次未赋值 = 声明变量**;未使用不报错;**仅当可执行面读取时升为形参**(见设计 §4.4 · §8.2)。不设「提及性」专用语法。 +4. **形参默认由函数体/叙述推断**(升参);`` + `名` `` 仅作迁移兼容。 +5. **`>` 调用面保留**(可选)。 +6. **空返回**用标记而非关键字:推荐 `---` / `***`;显式 `*None*` / `*无*`;整行 `**`;兼容 `****`(设计 §7.2)。 +7. **不做 v0.2 双模式兼容**(摸索阶段允许破坏性变更);旧 `.mq.md` 须改写。 +8. 金样例门禁:`tests/markup-v03/`;存量 suite 随后迁移。 + +## Consequences + +### Positive + +- 叙述与代码共用 Markdown 习惯,文档可读性上升。 +- 更贴合 AI 生成粗体「操作」的偏好,降低错用标记。 +- 去掉形参表仪式,函数更像「带名字的说明段落」。 + +### Negative / Risks + +- **破坏性**:与 v0.2 金样例、Skill、教程、大量 `lib/`/`ext/` 源码不兼容,必须分波迁移或双模式。 +- 段内扫描与形参推断增加解析/语义复杂度——空返回与升参规则已在设计 §7.2 / §8.2 钉死;其余 §12 项用金样例收口。 +- view/catalog/LSP 高亮规则需同步。 + +### Neutral + +- `#` / `##` 对象体系、标准库、插件 ABI、关键字最小集不变。 +- 输出仍是 `print` / `打印`,不是粗体/斜体。 diff --git a/doc/design/code-vs-comment.md b/doc/design/code-vs-comment.md index ce0c25a..841558d 100644 --- a/doc/design/code-vs-comment.md +++ b/doc/design/code-vs-comment.md @@ -2,8 +2,9 @@ | | | |---|---| -| 状态 | 与 mapping v0.1 / keywords 对齐(成段注释) | +| 状态 | 与 mapping **v0.2** 对齐(成段注释);**v0.3 草案**见 [markdown-mapping-v0.3.md](markdown-mapping-v0.3.md) §4 | | 日期 | 2026-08-04 | +| 修订 | 2026-09-13:注明 v0.3 叙述可含声明与行内代码段 | --- @@ -36,3 +37,17 @@ | `****` / 空粗体 | 空返回 + 结束函数体 | 是 | | `> print …` | 打印副作用 | 否(内置函数) | | 函数体 `---` / `***` | 结束函数体 | 是(边界) | + +--- + +## v0.3 草案预告(未实现) + +[mapping v0.3](markdown-mapping-v0.3.md) 拟改为: + +| 层 | 形态 | +|----|------| +| 叙述面 | 普通段落;`` `名` `` 可声明/引用 | +| 可执行面 | 结构标记 + **`**代码**`** + **`*返回*`**;调用可无 `>` | +| 外联面 | 不变 | + +现行实现与上表(v0.2)一致,直至路线图默认切换。 diff --git a/doc/design/examples-and-tests.md b/doc/design/examples-and-tests.md index ab56405..767fc1d 100644 --- a/doc/design/examples-and-tests.md +++ b/doc/design/examples-and-tests.md @@ -16,27 +16,17 @@ tests/ README.md gold.rs # 集成测试入口 - structure/ # 代码基础结构(Markup 架构) - hello.mq.md - nested-call.mq.md - positional-call.mq.md - branch.mq.md - loop.mq.md - collection.mq.md - import/ - main.mq.md - utils.mq.md - ns/ - helpers.mq.md - path3.mq.md - use.mq.md + structure/ # 代码基础结构(Markup 架构 · v0.2) + … keywords/ # 关键字与内置名 - print.mq.md - bool-logic.mq.md + … + markup-v03/ # Markup 映射 v0.3 草案金样例(实现前 ignore) + README.md + inc-prose.mq.md + … ext/ - agent-run-live.mq.md + … errors/ # 期望失败(诊断文案稳定后再加金样例) - ns-instance-method.mq.md … ``` @@ -51,6 +41,7 @@ tests/ |------|--------|----------| | **structure** | `#`/`##`、形参 `+`、`1.` 分支、`-` 循环、表、导入、点号路径 / `use`、位置/具名实参 | 关键字边角 | | **keywords** | `True`/`False`/`None`、`and`/`or`/`not`、`print`/`input` 约定 | 复杂控制流(可极简) | +| **markup-v03** | v0.3:叙述声明、粗体代码、斜体返回、升参、空返回、双调用面(见 [markdown-mapping-v0.3.md](markdown-mapping-v0.3.md)) | 在 `--markup v0.3` 落地前 `#[ignore]` | | **errors** | 未定义名、实参错误、语法错误的诊断 | 成功路径 | 未单独建夹、但应覆盖的其它测试(`src/**` 单测或日后 `tests/runtime/`): diff --git a/doc/design/markdown-mapping-v0.3.md b/doc/design/markdown-mapping-v0.3.md new file mode 100644 index 0000000..a16aabd --- /dev/null +++ b/doc/design/markdown-mapping-v0.3.md @@ -0,0 +1,608 @@ +# Marqdo 语法映射 v0.3(叙述统一 · 粗体即代码) + +| | | +|---|---| +| 状态 | **Accepted · 现行运行时目标(实现中)** | +| 日期 | 2026-09-13 | +| 取代 | [markdown-mapping.md](markdown-mapping.md) **v0.2(已废止为运行时宪法)** | +| ADR | [0005-prose-unified-markup.md](../adr/0005-prose-unified-markup.md) | +| 路线 | [markup-v0.3.md](../roadmap/markup-v0.3.md) | +| 相关 | [code-vs-comment.md](code-vs-comment.md) · [return-hr-and-code-surface.md](return-hr-and-code-surface.md) · [call-arguments.md](call-arguments.md) · [objects.md](objects.md) · [keywords.md](keywords.md) | + +> **v0.3 为唯一 Markup 映射。** 不做 v0.2 双模式 / `--markup` 版本身份。摸索阶段允许破坏性变更;旧 `.mq.md`(`*语句*` / `**返回**`)须改写。金样例见 `tests/markup-v03/`。 + +--- + +## 0. 一句话 + +让 **Markdown 叙述本身成为程序的一部分**:普通文字里用 `` `名` `` 出现变量(首次未赋值 = 声明);用 **`**…**` 粗体** 包裹可执行代码(含调用,不必再写 `>`);用 **`*…*` 斜体** 表示返回值。函数形参**不再手写 `+` 列表**,由函数体内的声明/赋值自行推断。 + +--- + +## 1. 动机(为何推翻 v0.2 的部分定论) + +v0.2 为了「标记即语法」的清晰边界,做了这些硬隔离: + +| v0.2 | 代价 | +|------|------| +| 无标记行 = 纯注释;变量只能写在 `*…*` / 结构行里 | 叙述与代码割裂,「文档即代码」读起来像两套语言叠在一起 | +| `*…*` = 语句,`**…**` = 返回 | 与常见 Markdown/AI 习惯相反:模型更爱用 `**` 强调「要执行的东西」,读者也更易看见粗体 | +| 调用必须 `>` | 行间调用要另起结构行,叙述中夹调用不自然 | +| 形参必须 `` + `名` `` | 仪式感强;函数头像「另一套签名语言」,与正文脱节 | + +古早示例(当时不能跑,正是本文要合法化的目标面): + +```markdown +## 加一函数 + +对于输入变量`n`,我们执行操作**n=n+1**接着返回*n*。 + +# main + +我要调用加一函数可以采用这样的办法: + +> 加一函数 37 + +或者可以直接这么调用**加一函数 37** +``` + +目标:上述文件在 v0.3 下应能解析、求值,且**读起来仍是一篇正常中文说明**。 + +--- + +## 2. 哲学(设计原则) + +### P1 — 叙述统一(Prose-unified) + +- Marqdo 注释采用 **Markdown 叙述**(段落、列表中的说明文字),不是第二种注释语法。 +- **变量可以出现在正常文字之间**:用 Markdown 行内代码 `` `n` `` 标识标识符。 +- **第一次出现且未赋值 = 声明变量**;之后的出现 = 引用。赋值发生在粗体代码段内(或兼容的结构赋值形)。 +- **未使用的变量无害**(不报错、不升参);真正的输入由「可执行面读取」升为形参(§8)。 +- 这样「说明文字」与「程序名字」共用同一套 Markdown 视觉习惯,整体更和谐。 + +### P2 — 粗体即代码(Bold-as-code) + +- **`**…**` = 代码段**(可执行):赋值、表达式、函数/方法调用、可内联的短语句。 +- 选择粗体的原因: + 1. **AI 输出偏好**:模型天然爱用 `**` 强调「重要操作」;把粗体定为可执行,降低「模型写了强调却被当成返回」的错配。 + 2. **行间显眼**:在长段落里,粗体比斜体更容易被扫到。 +- 粗体代码段内的调用 **允许不写 `>`**:`**加一函数 37**` 与 `> 加一函数 37` 语义等价(见 §6)。 +- **`>` 保留为可选调用面**(blockquote 风格、独立行、兼容 v0.2 迁移与 AI 已学会的形态)。 + +### P3 — 斜体即返回(Italic-as-return) + +- **`*…*` = 返回值**(架构级),与粗体代码形成对立、易读的一对: + - 做了什么 → 粗体 + - 结果是什么 → 斜体 +- **空返回 / 无值收束**(已决议,见 §7.2):推荐 `---` / `***`;显式 `*None*` / `*无*`;整行 `**` 为空斜体;`****` 兼容。 +- **输出仍不是返回**:打印继续用内置 `print` / `打印`(副作用函数),不把粗体或斜体当成「打印到终端」的语法。 + +### P4 — 形参由体推断(Body-inferred params) + +- **不再要求**作者手写 `` + `名` `` 形参表(v0.3 默认关闭;过渡期可兼容,见 §8)。 +- 函数体内: + - **只声明、未赋默认** → **必选形参**(调用时必须提供)。 + - **声明同时赋值**(含默认值字面量)→ **可选形参**(带默认值)。 +- 推断顺序与绑定规则见 §8;与位置/具名实参规则对齐 [call-arguments.md](call-arguments.md) 的精神(可修订附录)。 + +### P5 — 标记仍承载控制流(不变) + +- **不引入** `if` / `else` / `while` / `for` / `def` / `return` 关键字。 +- `#` = 对象/类型,`##`+ = 函数/方法([objects.md](objects.md) 不变)。 +- 分支仍用 `1.` `2.` …;循环仍用 `-`;结构行不必再包粗体(见 §5)。 + +### P6 — 其它「代码即文档」补强(本版一并采纳) + +| 思路 | 说明 | +|------|------| +| **渐进披露** | 读者可只读叙述;运行时只执行标记与推断出的声明。同一文件服务人与机器。 | +| **最小仪式** | 能从正文看出的签名,就不在函数头重复写一遍。 | +| **双调用面** | 独立行 `>` 适合「步骤清单」;行间 `**f …**` 适合「嵌在句子里的动作」。 | +| **标识符视觉统一** | 叙述、代码、形参一律优先 `` `名` ``;粗体/斜体内部允许裸名(与 v0.2 斜体/粗体内规则同类)。 | +| **段落仍可整段注释** | 不含任何可执行标记、且无「声明性 `` `名` ``」义务的纯说明段,行为与注释相同(见 §4 消歧)。 | +| **迁移可观测** | `--dump-lines` / `--dump-ast` 必须能区分「叙述中的声明」与「粗体代码」与「斜体返回」。 | + +--- + +## 3. 与 v0.2 对照(角色对调摘要) + +| 概念 | v0.2 | v0.3 | +|------|------|------| +| 程序语句 / 代码段 | `*…*` | `**…**` | +| 返回值 | `**…**` | `*…*` | +| 独立调用 | 必须 `>` | `>` **或** `**callee …**` | +| 形参 | 标题下 `` + `名` `` | **体推断**(`+` 过渡兼容) | +| 叙述中的变量 | 一般为注释,不可声明 | `` `名` `` 可声明/引用 | +| 无标记纯文字 | 成段注释 | 仍为叙述;**若含声明性反引号则参与绑定图**(见 §4) | + +这是一次 **架构级标记对调**,不是局部糖。金样例、教程、Skill、扩展库需按路线图分波迁移。 + +--- + +## 4. 叙述、声明与注释 + +### 4.1 三层模型(修订) + +| 层 | 形态 | 角色 | +|----|------|------| +| **叙述面** | 普通 Markdown 段落、列表说明 | 给人读;其中的 `` `名` `` 可进入**绑定图** | +| **可执行面** | 结构标记(`#` `>` `+` `-` `1.` 表…)+ **`**代码**`** + **`*返回*`** | 求值 | +| **外联面** | ` ```lang ` | FFI(不变) | + +### 4.2 变量在叙述中的出现 + +语法:Markdown **行内代码** `` `标识符` ``。 + +| 出现形态 | 语义 | +|----------|------| +| 全文(当前函数/对象作用域)**首次**出现 `` `n` ``,且此前/同句无对 `n` 的赋值 | **声明变量**(进入绑定图;是否升为形参见 §8) | +| 已声明之后再次 `` `n` `` | **引用**(不生成新绑定) | +| 粗体内 `**n = …**` / `**n=n+1**` | **赋值**(若首次赋值且未见声明,则声明+赋值一并发生) | +| 叙述中 `` `n`=1 ``(反引号名紧贴 `=`,无粗体) | **带初值的声明**(形参默认或局部初值;见 §8) | + +推荐作者写法(与动机示例一致): + +```markdown +对于输入变量`n`,我们执行操作**n=n+1**接着返回*n*。 +``` + +- `` `n` `` → 声明变量;因随后在代码中**读取**未先由局部独力定义 → 升为必选形参(§8) +- `**n=n+1**` → 代码段(赋值) +- `*n*` → 返回 + +### 4.3 何为「纯注释」 + +满足下列**全部**条件的段落,不产生绑定、不求值: + +1. 不含结构标记行; +2. 不含 `**…**` / 作为返回的 `*…*`(见 §7); +3. 不含任何 `` `标识符` ``。 + +仍建议:**叙述段与独立结构代码行之间空一行**,降低人读与差分时的视觉粘连(解析器在 v0.3 下不再依赖「空行分段注释升级」作为唯一边界,但空行仍是作者卫生习惯)。 + +### 4.4 提及性反引号:一律视作变量(已决议) + +**不另设「仅提及、不声明」语法。** 叙述里凡出现合法标识符 code span `` `名` ``,一律按 **变量** 处理(首次 = 声明,其后 = 引用)。 + +| 情况 | 处理 | +|------|------| +| 谈到某名但可执行代码**从未读写**它 | 仍是绑定图中的变量;**对求值无影响**(死绑定) | +| 与其它语言对照 | 类似 Python 写了未用局部、JS 未用 `let`——默认可忽略;实现可对「从未读写」发**可选 lint**,**不得**因此报错或拒绝运行 | +| 是否变成函数形参 | **否**(仅声明、从未在可执行面被读取)——见 §8.2「升参条件」 | +| 是否需要 `` 提及`n` `` 等前缀 | **不需要**;避免第二套反引号方言 | + +例(合法、无副作用): + +```markdown +## 说明性函数 + +本文顺便提到`Markdown`与`GFM`,但真正的输入只有`题干`。 +**print text=题干** +--- +``` + +- `` `Markdown` `` / `` `GFM` `` → 变量声明,未使用 → 不进形参表、不改行为 +- `` `题干` `` → 声明且在粗体中读取 → 必选形参 + +**否决**:为「提及」单独做转义/前缀(曾列于开放点);若将来作者强烈需要「叙述中的等宽字但不进绑定图」,另开增强案,不阻塞 v0.3 核心。 + +### 4.5 成段规则相对 v0.2 的变化 + +v0.2:「段首无标记 → 整段注释,续行永不升级」。 +v0.3: + +- 叙述段落**可以**内含可执行粗体/斜体返回;解析器做**段内扫描**,抽出 `` `名` ``、`**…**`、`*…*`。 +- 独立结构行(行首 `#` `>` `-` `1.` `|` 等)仍整行分类为代码。 +- **否决维持**:「整行无标记 = 默认可执行代码」。无标记且无反引号声明的文字永不单独变成语句。 + +--- + +## 5. 映射总表(v0.3) + +| 标记 | 语义 | +|------|------| +| `#` … `######` | `#` = 对象/类型;`##`+ = 函数/方法(同 [objects.md](objects.md)) | +| 叙述中 `` `名` `` | 声明或引用(§4) | +| `**…**` | **代码段**(赋值、表达式、调用) | +| `*…*` | **返回值**(含显式空值,见 §7.2) | +| `>` 行 | **调用**(可选面,与粗体内调用等价) | +| `` + `名` `` | **过渡兼容**:显式形参;新代码不推荐 | +| 体内 `1.` `2.` … | 分支 | +| 体内 `-` | 循环 | +| `N. *` | else 臂(此处 `*` 仍是「空条件」标记,**不是**返回值;见 §7.3) | +| GFM 表格 | 集合(不变) | +| ` ```lang ` | 外联(不变) | +| 函数体内 `---` / `***` | **无值收束**(对齐其它语言的「空 return」,见 §7.2) | +| 整行恰 `**` 或 `****` / `*None*` / `*无*` | **空返回**(见 §7.2) | + +### 结构行与粗体 + +行首已是结构标记的构造(`#` `>` `+` `-` `|`、`1.`)**不必**再包 `**…**`。 +粗体用于:**嵌在叙述中的代码**,以及「我想把这一小段标成可执行」的行间片段。 + +--- + +## 6. 调用 + +### 6.1 两种表面形式 + +```markdown +> 加一函数 37 + +**加一函数 37** +``` + +二者均解析为对 `加一函数` 的调用,实参位置绑定(或具名 `n=37`)。 + +| 形式 | 典型用途 | +|------|----------| +| `> …` | 步骤列表、独立可执行行、与 v0.2/AI 习惯兼容 | +| `**…**` | 嵌在句子中:「或者可以直接这么调用**加一函数 37**」 | + +### 6.2 粗体内调用的判别 + +粗体内容在去掉外层 `**` 后,按下列优先级分类: + +1. 含 `=` 且左侧为可赋值目标(标识符 / 脚注左值等)→ **赋值语句**(可含右侧调用)。 +2. 否则,若首词为已知函数/方法/内置/导入成员(Pass 名表可见)→ **调用**。 +3. 否则 → **表达式语句**(求值后丢弃,或在语句位置非法则诊断)。 + +示例: + +| 粗体内容 | 分类 | +|----------|------| +| `n=n+1` | 赋值 | +| `加一函数 37` | 调用 | +| `加一函数 n=37` | 调用(具名) | +| `n + 1` | 表达式(单独出现时;作返回应写 `*n + 1*`) | +| `print text=hi` / `打印 内容=你好` | 调用(内置) | + +### 6.3 方法调用 + +- 独立行:`` > `对象`.方法 … ``(兼容)或 `> 对象.方法 …`(若接收者规则允许)。 +- 粗体内:`**对象.方法 …**` / `**p = page.主体装配 组件=home**`。 +- 粗体/斜体内裸名 = 变量(延续 v0.2「段内统一命名空间」精神)。 + +### 6.4 实参 + +具名 + 位置混用规则继承 [call-arguments.md](call-arguments.md);v0.3 仅把「形参列表来源」从 `+` 行改为**推断签名**(§8)。独立 `>` 行上裸词仍为文本字面量;粗体内调用的裸词为变量(与 v0.2「段内调用」一致)。 + +--- + +## 7. 返回 + +### 7.1 斜体返回 + +```markdown +*n* +*n + 1* +*"ok"* +``` + +斜体内部值语法与 v0.2 粗体返回内部相同(裸词 = 变量;文本须引号)。 + +### 7.2 空返回与收束(已决议) + +Marqdo **不引入** `return` 关键字;「无值结束」用标记表达。对照常见语言: + +| 语言 | 无值 / 空返回 | Marqdo v0.3 对应 | +|------|----------------|------------------| +| Python | `return` / `return None` | 收束线 / 显式 `*None*`·`*无*` | +| Go | 无结果函数里的 `return` | 收束线 `---` / `***` | +| Rust | `()` 或函数末尾隐式 unit | 收束线;或显式空值返回 | +| JavaScript | `return;` → `undefined` | 收束线 → 运行时 `None` | +| Marqdo v0.2 | `****`(空粗体)或 `---` | 见下「兼容」 | + +#### 形式层级(推荐自上而下) + +| 优先级 | 形式 | 语义 | 说明 | +|--------|------|------|------| +| **1. 推荐收束** | 函数体顶层**整行**仅为 `---` 或 `***` | 结束本函数体;返回槽为空,运行时得 `None` | 对齐 Go/Rust「无值 return」;Markdown 分割线,**与粗体零冲突**;副作用函数首选 | +| **2. 显式空值** | `*None*` 或 `*无*`(整段或行内返回位) | 返回 `None` 并结束函数体 | 对齐 Python `return None`;人读最清楚 | +| **3. 空斜体标记** | **整行** trim 后恰为两个星号:`**` | 同上:空返回 `None` 并结束体 | 词法钉死:`^\s*\*\*\s*$` → **空斜体返回**,**不得**当成粗体开闭;禁止写成 `* *`(中间空白) | +| **4. 兼容 v0.2** | 整行 `****`(四个星号) | 同空返回 | 迁移期识别;实现可 warning:建议改为 `---` 或 `*None*` | + +```markdown +## 只打印 +**print text=hi** +--- + +## 显式空 +**print text=hi** +*None* + +## 空斜体行(允许,次选) +**print text=hi** +** +``` + +#### 词法消歧(空斜体 vs 粗体) + +1. **整行恰好 `**`(两个 `*`)** → 空返回(规则 3),不是未闭合粗体。 +2. **粗体代码**至少包住一个非空内容:`**x**`、`**n=1**`;不允许「空粗体代码段」作为语句。 +3. **四个星号整行 `****`** → 兼容空返回(规则 4),不解释为「空粗体代码」。 +4. 行内出现的 `**…**`(两侧还有叙述文字)按正常粗体代码扫描,不走「整行空返回」。 + +#### 与「有返回值」的关系 + +- 需要把值交回调用方 → 用非空斜体:`*n*`、`*n + 1*`。 +- 只做副作用、不要值 → 优先 `---` / `***`(不必再写空斜体)。 +- 同一函数路径上:先出现非空 `*…*` 返回即结束该路径;收束线用于「无斜体返回」的路径。 + +### 7.3 与 else 臂 `N. *` 的消歧 + +有序列表臂头 `2. *` 中的 `*` 表示 **else**,不是返回。判别:行匹配 `^\s*\d+\.\s+\*\s*$`(可带尾注)→ 分支 else;不进入返回扫描。 + +### 7.4 输出 + +```markdown +**print text=Hello** +> print text=Hello +``` + +打印是调用,不是返回。禁止把 `*Hello*` / `**Hello**` 解释为「打印 Hello」(延续 v0.2 决议精神,仅对调标记)。 + +--- + +## 8. 形参推断 + +### 8.1 目标签名 + +对每个 `## 函数`(及方法),在 Pass1 收集体之后得到: + +```text +params: Vec<{ name, default: Option, span }> +``` + +### 8.2 收集规则(函数作用域) + +扫描该函数标题之下、下一同级/更高级标题之前的所有节点,维护**绑定图**与**形参表**(二者分离): + +#### A. 绑定图(所有变量) + +1. **声明事件**:叙述或代码中的首次 `` `名` ``,或粗体内首次对 `名` 的赋值左值。 +2. **默认/初值事件**:叙述 `` `名`=默认表达式 ``;或符合 §8.3 的「形参默认」赋值。 +3. **排除出绑定图**(不建变量): + - 循环变量 `` - [项](集合) `` 中的 `项`(循环自有绑定); + - `self` / `自`(方法自动注入)。 + +凡进入绑定图的名字都是**变量**——包括「只在叙述里出现、可执行代码从未读写」的名字(§4.4)。未使用 → **不报错**。 + +#### B. 升为形参的条件(升参) + +名字已在绑定图中,且满足下列之一,才进入 `params`: + +| 升参种类 | 条件 | +|----------|------| +| **必选形参** | 在可执行面(`**…**` / `*…*` / `>` / 结构语句)中存在对 `名` 的**读取**,且该读取无法单靠「不依赖外部输入的局部赋值」满足——典型:先声明、后 `n=n+1` / `*n*` / `**print text=n**` 等读到未先行赋成纯局部常量 | +| **可选形参** | 有默认/初值事件(`` `名`=… `` 或 §8.3 默认赋值),供调用方覆盖 | + +**不升参**:仅叙述声明、可执行面零读取(死绑定)→ 留在绑定图,**不进** `params`,调用签名不变。 + +**顺序**:按升参名字的**首次声明事件**在源码中的出现序。 + +**仍排除**:分支/块内纯局部(金样例钉启发式);显式 `+` 合并见 §8.4。 + +### 8.3 「形参默认」与「函数体赋值」的区分 + +```markdown +## 问候 +对`谁`打招呼,默认`礼貌`=False。 + +**print text=谁** +``` + +- `` `谁` `` → 必选 +- `` `礼貌`=False `` → 可选,默认 `False` +- 体里的 `**print …**` 不是给 `谁` 赋默认值 + +```markdown +## 加一函数 +输入`n`。**n=n+1**返回*n*。 +``` + +- `` `n` `` 先声明 → 必选 +- `**n=n+1**` 是**体语句**(对已声明形参赋值),**不是**默认值 + +判别启发式(实现契约): + +- 若赋值右值**依赖同名左值**(如 `n=n+1`)→ 体语句。 +- 若赋值出现在「该名被当作输入读取」之前,且右值不依赖未绑定的同名 → 可作为默认值候选。 +- 叙述形 `` `名`=字面量 `` 优先视为默认值声明。 + +### 8.4 显式 `+` 形参(过渡) + +- 若函数标题下仍有 `` + `名` `` 行:与推断结果**合并**;冲突时 **显式 `+` 胜出**并诊断警告。 +- 迁移完成后(路线图 M4)可改为:存在 `+` 则关闭推断,或直接废弃 `+`。 + +### 8.5 调用绑定 + +与现有一致:具名优先,位置按「尚未绑定的形参」从左到右填充。缺必选形参 → 语义错误。 + +--- + +## 9. 完整示例(规范金样意向) + +### 9.1 加一(动机例) + +```markdown +## 加一函数 + +对于输入变量`n`,我们执行操作**n=n+1**接着返回*n*。 + +# main + +我要调用加一函数可以采用这样的办法: + +> 加一函数 37 + +或者可以直接这么调用**加一函数 37** +``` + +期望: + +- 签名:`加一函数(n)` +- `# main` 两次调用均返回 `38`(第二次若未绑定到打印,至少 AST/求值结果为 38;可用 `**print text=…**` 观测)。 + +### 9.2 带默认值 + +```markdown +## 问候 + +向`谁`问好;`礼貌`=False 时用短句。 + +1. 礼貌 + **print text=您好,** + **print text=谁** +2. * + **print text=嗨,** + **print text=谁** + +--- + +# main + +**问候 谁=Marqdo 礼貌=True** +> 问候 Marqdo +``` + +### 9.3 对象方法(不变骨架) + +```markdown +# 计数器 + ## 加 + 将`self`的`值`增加`delta`(`delta`=1)。 + **值 = 值 + delta** + *self* + +# main +*c = > 计数器* +**c.加 3** +``` + +(方法形参推断含 `delta`;`self` 自动。) + +--- + +## 10. AST / 管线变更要点(设计约束) + +详细里程碑见 [markup-v0.3.md](../roadmap/markup-v0.3.md)。此处只钉**语义 → 树**的约束,供实现对照: + +### 10.1 行分类(lex / line-class) + +新增或调整类别: + +| 类别 | 说明 | +|------|------| +| `Prose` | 叙述行;需**内联扫描** | +| `BoldCode` | 整行或片段 `**…**` | +| `ItalicReturn` | 整行或片段 `*…*`(非 else 臂) | +| `CallLine` | `>` 调用(保留) | +| … | 原有 Heading / List / Table / Fence / Hr | + +**内联扫描**产出 `InlineBit`:`Text` | `IdentDecl/Ref` | `BoldCode` | `ItalicReturn`。 + +### 10.2 AST 节点调整(建议) + +```text +Param { name, default?, inferred: bool, span } // inferred=true 表示来自体推断 + +Stmt:: + Assign { … } // 多由 BoldCode 解析 + Call { … } // CallLine 或 BoldCode 判别为调用 + Return { value } // 由 ItalicReturn 解析(原由 Bold) + ExprStmt { … } // 可选:纯表达式粗体 + Prose { bits } // 可选:保留叙述结构供 view/catalog;求值阶段只消费 Decl + +FnDef.params: + 由 InferParams(body + prose bits) 填充,再合并显式 + +``` + +`Stmt::Return` 的**语法来源**从粗体改为斜体;dump 文本应写 `return←italic`。 + +### 10.3 Pass1 / Pass2 + +- Pass1:收集 `#`/`##` 结构;建绑定图;跑 **ParamInfer(升参)**;登记名表。 +- Pass2:粗体内调用名解析;叙述 Decl 不重复建参。 +- 诊断:**必选缺失**、`+` 与推断冲突、空返回词法歧义(非整行 `**` 的残缺粗体)。 +- Lint(可选、默认关或降级为 hint):绑定图中「从未读写」的死变量——**不得**当错误。 + +### 10.4 双后端 + +树遍历与字节码均消费同一 AST;字节码发射仅跟随 `Stmt`/`Expr` 变化,不感知 Markdown 标记。 + +--- + +## 11. 破坏性切换(无双模式) + +**产品决定(2026-09-13):** 直接以 v0.3 为唯一运行时映射;**不**保留 `--markup v0.2` / 双 edition。旧语法金样例与库文件在迁移完成前可能失败——可接受。 + +| 阶段 | 行为 | +|------|------| +| 现在 | 解析器切到 v0.3;`tests/markup-v03/` 为门禁 | +| 随后 | 批量改写 `tests/structure|keywords`、`lib/`、`ext/`、Skill、`public/` | +| 文档 | `markdown-mapping.md` 改为指向本文;ADR 0005 → Accepted | + +**机械改写:** + +- 语句 `*a = 1*` → `**a = 1**` +- 返回 `**x**` → `*x*` +- 粗体内文本字面量须引号:`**print text="hi"**`(裸词 = 变量) +- 调用可保留 `>` 或改为粗体 +- `` + `n` `` 可删,改为叙述 `` `n` `` + 升参 + +--- + +## 12. 开放问题 / 已决议 + +| # | 议题 | 状态 | 决议摘要 | +|---|------|------|----------| +| 1 | 空返回词法 | **已决议** | §7.2:推荐 `---`/`***`;显式 `*None*`/`*无*`;整行 `**`;兼容 `****` | +| 2 | 提及性反引号 | **已决议** | §4.4:一律视作变量;未使用不报错、不升参;不设提及前缀 | +| 3 | 粗体内调用 vs 赋值 | 建议 | 以 `=` 左值合法性优先 | +| 4 | `` `n`+1 `` 误声明 | 建议 | 仅完整单个 code span `` `ident` `` 触发声明 | +| 5 | 叙述强调斜体 vs 返回 | 建议 | 函数体内合法返回表达式才当返回;否则当文字 | +| 6 | 一行多 `**…**` | **建议采纳** | 允许,按出现序执行(M0 钉死为是) | +| 7 | view 展示 prose Decl | 建议 | Variables 列绑定图 + 标注是否已升参 | + +--- + +## 13. 非目标 + +- 不把整篇无标记 Markdown 变成可执行程序。 +- 不引入 `def` / `return` 关键字(空返回用标记,见 §7.2)。 +- 不改变 `#` / `##` 对象体系与 ext 插件 ABI。 +- 不在本文阶段修改解释器代码(见路线图)。 +- 不为「提及」另发明一套反引号方言(§4.4)。 + +--- + +## 14. 验收标准(设计完成 ≠ 实现完成) + +设计稿验收: + +- [x] 哲学 P1–P6 成文 +- [x] 与 v0.2 对照表 +- [x] 形参推断规则可实现(含升参 vs 死绑定) +- [x] 动机示例在语义上闭合 +- [x] AST/管线约束与路线图挂接 +- [x] ADR 记录决策意向 +- [x] **空返回**对照其它语言并钉死词法 +- [x] **提及/未使用变量**政策钉死 + +实现验收(后续): + +- [x] 金样例夹具 `tests/markup-v03/`(11 个 · `gold.rs` 暂 ignore) +- 动机示例金样例通过(去掉 ignore) +- `--dump-ast` 可见 inferred params 与死绑定(若 dump) +- 空返回四种形式金样例通过 +- 旧 v0.2 套件在旗标下行为不变,直到默认切换 + +--- + +## 15. 修订历史 + +| 日期 | 说明 | +|------|------| +| 2026-09-13 | 初稿:叙述统一、粗体代码、斜体返回、形参体推断;Proposed | +| 2026-09-13 | 决议空返回(§7.2)与提及性反引号(§4.4);形参改为「升参」与绑定图分离(§8.2) | diff --git a/doc/design/markdown-mapping.md b/doc/design/markdown-mapping.md index 245b6c7..9db4704 100644 --- a/doc/design/markdown-mapping.md +++ b/doc/design/markdown-mapping.md @@ -2,9 +2,10 @@ | | | |---|---| -| 状态 | 已定论(修订:形参 `+`、分支 `1.`、同级再 `1.` 为新分支、标识符反引号、`-` 专用于循环) | +| 状态 | **历史文档(v0.2 · 已废止为运行时)** — 现行见 **[markdown-mapping-v0.3.md](markdown-mapping-v0.3.md)** | | 日期 | 2026-08-07 | | 取代 | v0.1 中「函数头 `-` 形参 / 裸名形参与遍历变量 / `+` 分支」 | +| 被取代 | **[markdown-mapping-v0.3.md](markdown-mapping-v0.3.md)**(粗体即代码 · 斜体即返回 · 无双模式兼容) | | 相关 | [objects.md](objects.md) · [code-vs-comment.md](code-vs-comment.md) · [return-hr-and-code-surface.md](return-hr-and-code-surface.md) · [module-namespace.md](module-namespace.md) | Markdown **标记即语法**。输出**不是**语言架构原语,而是内置函数 **`print`**(英文;见 [keywords.md](keywords.md))。 diff --git a/doc/design/return-hr-and-code-surface.md b/doc/design/return-hr-and-code-surface.md index 04f2a95..b6b4619 100644 --- a/doc/design/return-hr-and-code-surface.md +++ b/doc/design/return-hr-and-code-surface.md @@ -2,12 +2,13 @@ | | | |---|---| -| 状态 | 已决议(并入 mapping v0.1 + keywords;2026-08-04 修订函数收束) | +| 状态 | **v0.2 已决议**(现行实现);**v0.3 拟对调 `*` / `**` 角色**(见下) | | 日期 | 2026-08-04 | +| 修订 | 2026-09-13:挂接 [markdown-mapping-v0.3.md](markdown-mapping-v0.3.md) | --- -## 决议 +## 决议(v0.2 · 现行) 1. **`*…*` = 程序语句**。 2. **`**…**` = 返回值**(架构级);空粗体 `****` / `** **` = 空返回(`None`)并结束函数体。 @@ -17,3 +18,20 @@ 6. **否决**:无标记行 = 默认代码。 详见 [keywords.md](keywords.md)、[markdown-mapping.md](markdown-mapping.md)、[code-vs-comment.md](code-vs-comment.md)。 + +--- + +## v0.3 意向(Proposed · 未实现) + +产品方重新审视后,拟在 [ADR 0005](../adr/0005-prose-unified-markup.md) 下**对调**架构标记,并放宽叙述面: + +| 概念 | v0.2 | v0.3 草案 | +|------|------|-----------| +| 代码段 / 语句 | `*…*` | `**…**` | +| 返回值 | `**…**` | `*…*` | +| 空返回 | `****` / 空粗体;或 `---` | **推荐 `---`/`***`**;`*None*`/`*无*`;整行 `**`;兼容 `****` | +| 输出 | 仍为 `print` / `打印` | 不变 | +| 无标记 = 默认代码 | 否决 | **仍否决** | +| 叙述中 `` `名` `` | 通常无绑定义 | 一律变量;未使用 OK;升参需可执行面读取 | + +完整规则与迁移见 [markdown-mapping-v0.3.md](markdown-mapping-v0.3.md)。**本决议文件在默认切换完成前仍描述 v0.2。** diff --git a/doc/roadmap/markup-v0.3.md b/doc/roadmap/markup-v0.3.md new file mode 100644 index 0000000..1d6d5ff --- /dev/null +++ b/doc/roadmap/markup-v0.3.md @@ -0,0 +1,106 @@ +# 路线图:Markup 映射 v0.3(叙述统一) + +| | | +|---|---| +| 状态 | **Active(v0.3 默认 · 无双模式;markup-v03 金样绿)** | +| 日期 | 2026-09-13 | +| 设计 | [markdown-mapping-v0.3.md](../design/markdown-mapping-v0.3.md) | +| ADR | [0005-prose-unified-markup.md](../adr/0005-prose-unified-markup.md) | +| 依赖 | 现有管线 [interpreter.md](interpreter.md) · [pipeline-debug.md](../design/pipeline-debug.md) | + +--- + +## 目标 + +把 v0.3 宪法落到词法 → AST → 语义 → 双后端,使动机示例(加一函数)成为金样例,并安全迁移存量代码。 + +--- + +## 里程碑 + +### M0 — 设计冻结与双模式骨架(文档 ✅ / 代码 ⏳) + +- [x] 设计文档 + ADR Proposed + 本路线图 +- [x] **钉死**:空返回词法(设计 §7.2);提及/未使用变量(§4.4);升参 vs 绑定图(§8.2) +- [x] **钉死**:一行多 `**…**` 按序执行(设计 §12 #6) +- [x] **不做双模式** — 直接 v0.3 默认 + +**出门:** 设计评审通过;旗标可切换;无行为默认变化。 + +### M1 — 内联扫描与 AST + +- [x] 金样例目录 `tests/markup-v03/`(夹具 + `gold.rs` `#[ignore]`;见目录 README) +- [x] `Prose` 行内联扫描:`` `ident` `` / `**…**` / `*…*` +- [x] `Stmt::Return` ← italic;`Stmt` ← bold Assign/Call +- [x] `Param.inferred` + 升参 +- [x] `tests/markup-v03/` 金样通过(默认运行时) + +**出门:** `cargo test markup_v03`(无 ignore)绿。 + +### M2 — 形参推断 + +- [ ] `InferParams`:首次 `` `名` `` = 必选;`` `名`=默认 `` = 可选 +- [ ] 体赋值 `n=n+1` 不误判为默认 +- [ ] 与显式 `+` 合并规则 + 警告 +- [ ] 方法 `self`/`自` 排除 +- [ ] 金样例:默认实参、位置/具名调用、粗体内调用 + +**出门:** 推断签名与 `+` 兼容套件绿。 + +### M3 — 调用面与消歧 + +- [ ] `**callee args**` ≡ `> callee args` +- [ ] else 臂 `N. *` 与返回斜体消歧 +- [ ] 一行多 `**…**` 按序执行 +- [ ] 金样例:`---` / `*None*` / 整行 `**` / 兼容 `****`;叙述死绑定不升参 +- [ ] 诊断:必选缺失、未知 callee;空返回残缺粗体;死变量仅可选 lint + +**出门:** `tests/markup-v03/*` 覆盖设计 §9 示例。 + +### M4 — 双后端与工具 + +- [ ] 字节码发射跟随新 Stmt 源 +- [ ] `view` / Variables:显示推断形参与 prose Decl +- [ ] (可选)`marqdo migrate markup-v03` 机械改写提示/工具 + +**出门:** tree 与 bytecode 后端对 `markup-v03` 金样一致。 + +### M5 — 默认切换与存量迁移 + +- [ ] 默认 `MarkupEdition::V03` +- [ ] 迁移 `tests/**`、`lib/**`、`ext/**`、`public/**`、教程 +- [ ] 更新 `.cursor/skills/marqdo/SKILL.md` 硬规则 +- [ ] 修订 [markdown-mapping.md](../design/markdown-mapping.md) 为 v0.3 正式正文(或声明由 v0.3 文件接任) +- [ ] ADR 0005 → **Accepted** +- [ ] CHANGELOG / 发版说明(破坏性:标记对调) + +**出门:** 全量 gold 默认绿;v0.2 仅 `--markup v0.2` 保留一个过渡版本周期。 + +--- + +## 非目标(本路线) + +- 不改插件 ABI / Go libweb +- 不引入 `def`/`return` 关键字 +- M0–M4 不强制改生产 `.mq.md` + +--- + +## 风险 + +| 风险 | 缓解 | +|------|------| +| 标记对调导致海量假失败 | 双模式 + 分目录金样;默认晚切换 | +| 形参推断误伤局部变量 | 金样例钉启发式;允许过渡期写 `+` | +| 空返回 vs `**` 词法 | §7.2 已钉:整行 `**` = 空返回;推荐优先 `---` | +| 叙述反引号误升参 | §8.2 升参需可执行面读取;死绑定不进 params | +| Skill/AI 仍按 v0.2 生成 | M5 同步 Skill;过渡期文档标明版本 | + +--- + +## 修订历史 + +| 日期 | 说明 | +|------|------| +| 2026-09-13 | 初稿与设计/ADR 同步 | +| 2026-09-13 | 空返回与提及性反引号决议合入;M0 文档项勾选 | diff --git a/lib/browser.mq.md b/lib/browser.mq.md index 65979ed..b4284b6 100644 --- a/lib/browser.mq.md +++ b/lib/browser.mq.md @@ -12,8 +12,8 @@ import table:lib/table.mq.md Build set_text effect map for the official bridge. -*`m` = > table.put in=None at=sel value=text* -**> table.put in=None at="set_text" value=m** +**`m` = > table.put in=None at=sel value=text** +*> table.put in=None at="set_text" value=m* ## set_html + `sel` @@ -21,8 +21,8 @@ Build set_text effect map for the official bridge. Build set_html effect map. -*`m` = > table.put in=None at=sel value=html* -**> table.put in=None at="set_html" value=m** +**`m` = > table.put in=None at=sel value=html** +*> table.put in=None at="set_html" value=m* ## set_value + `sel` @@ -30,8 +30,8 @@ Build set_html effect map. Build set_value effect map. -*`m` = > table.put in=None at=sel value=value* -**> table.put in=None at="set_value" value=m** +**`m` = > table.put in=None at=sel value=value** +*> table.put in=None at="set_value" value=m* ## set_class + `sel` @@ -39,8 +39,8 @@ Build set_value effect map. Build set_class effect map. -*`m` = > table.put in=None at=sel value=class* -**> table.put in=None at="set_class" value=m** +**`m` = > table.put in=None at=sel value=class** +*> table.put in=None at="set_class" value=m* ## set_attr + `sel` @@ -48,8 +48,8 @@ Build set_class effect map. Build set_attr effect map; attrs is usually a small map of attribute names to values. -*`m` = > table.put in=None at=sel value=attrs* -**> table.put in=None at="set_attr" value=m** +**`m` = > table.put in=None at=sel value=attrs** +*> table.put in=None at="set_attr" value=m* ## wrap + `key` @@ -57,7 +57,7 @@ Build set_attr effect map; attrs is usually a small map of attribute names to va Single-key effect map wrapper. -**> table.put in=None at=key value=value** +*> table.put in=None at=key value=value* ## merge + `a` @@ -65,7 +65,7 @@ Single-key effect map wrapper. Merge two effect maps; right-hand keys win. -**> table.merge a=`a` b=`b`** +*> table.merge a=`a` b=`b`* ## canvas + `sel` @@ -80,7 +80,7 @@ Build canvas effect; commands is usually an @ GFM table. |-----|-------|----------| | `sel` | `clear` | `commands` | -**> table.put in=None at="canvas" value=spec** +*> table.put in=None at="canvas" value=spec* ## audio + `op`="play" @@ -92,17 +92,17 @@ Build canvas effect; commands is usually an @ GFM table. Build audio effect for the bridge. -*`spec` = > table.put in=None at="op" value=op* -*`spec` = > table.put in=`spec` at="id" value=id* +**`spec` = > table.put in=None at="op" value=op** +**`spec` = > table.put in=`spec` at="id" value=id** 1. `src` != "" - *`spec` = > table.put in=`spec` at="src" value=src* + **`spec` = > table.put in=`spec` at="src" value=src** 1. `freq` != None - *`spec` = > table.put in=`spec` at="freq" value=freq* + **`spec` = > table.put in=`spec` at="freq" value=freq** 1. `ms` != None - *`spec` = > table.put in=`spec` at="ms" value=ms* + **`spec` = > table.put in=`spec` at="ms" value=ms** 1. `sel` != "" - *`spec` = > table.put in=`spec` at="sel" value=sel* -**> table.put in=None at="audio" value=spec** + **`spec` = > table.put in=`spec` at="sel" value=sel** +*> table.put in=None at="audio" value=spec* ## read_file + `sel` @@ -117,26 +117,26 @@ Build read_file effect. |-----|----|------| | `sel` | `as` | `then` | -**> table.put in=None at="read_file" value=spec** +*> table.put in=None at="read_file" value=spec* ## observe + `specs` Build observe effect; specs is one map or an @ list of maps. -**> table.put in=None at="observe" value=specs** +*> table.put in=None at="observe" value=specs* ## unobserve + `specs` Build unobserve effect; specs is a map or @ list with id. -**> table.put in=None at="unobserve" value=specs** +*> table.put in=None at="unobserve" value=specs* ## focus + `sel` -**> table.put in=None at="focus" value=sel** +*> table.put in=None at="focus" value=sel* ## navigate + `url` @@ -148,12 +148,12 @@ Build unobserve effect; specs is a map or @ list with id. |-----|---------| | `url` | `replace` | -**> table.put in=None at="navigate" value=spec** +*> table.put in=None at="navigate" value=spec* ## storage + `spec` -**> table.put in=None at="storage" value=spec** +*> table.put in=None at="storage" value=spec* ## interval + `ms` @@ -166,13 +166,13 @@ Build unobserve effect; specs is a map or @ list with id. |----|------|----| | `ms` | `then` | `id` | -**> table.put in=None at="interval" value=spec** +*> table.put in=None at="interval" value=spec* ## clear_interval + `id`="default" -*`spec` = > table.put in=None at="id" value=id* -**> table.put in=None at="clear_interval" value=spec** +**`spec` = > table.put in=None at="id" value=id** +*> table.put in=None at="clear_interval" value=spec* ## fetch + `url` @@ -185,7 +185,7 @@ Build unobserve effect; specs is a map or @ list with id. |-----|------|--------| | `url` | `then` | `method` | -**> table.put in=None at="fetch" value=spec** +*> table.put in=None at="fetch" value=spec* ## fetch_all + `requests` @@ -197,7 +197,7 @@ Build unobserve effect; specs is a map or @ list with id. |----------|------| | `requests` | `then` | -**> table.put in=None at="fetch_all" value=spec** +*> table.put in=None at="fetch_all" value=spec* ## after + `ms` @@ -209,18 +209,18 @@ Build unobserve effect; specs is a map or @ list with id. |----|------| | `ms` | `then` | -**> table.put in=None at="after" value=spec** +*> table.put in=None at="after" value=spec* ## ws + `spec` -**> table.put in=None at="ws" value=spec** +*> table.put in=None at="ws" value=spec* ## clipboard + `text` -*`spec` = > table.put in=None at="text" value=text* -**> table.put in=None at="clipboard" value=spec** +**`spec` = > table.put in=None at="text" value=text** +*> table.put in=None at="clipboard" value=spec* ## download + `body` @@ -233,4 +233,4 @@ Build unobserve effect; specs is a map or @ list with id. |------|----------|------| | `body` | `filename` | `mime` | -**> table.put in=None at="download" value=spec** +*> table.put in=None at="download" value=spec* diff --git a/lib/cli.mq.md b/lib/cli.mq.md index 192f347..12bd419 100644 --- a/lib/cli.mq.md +++ b/lib/cli.mq.md @@ -8,4 +8,4 @@ description: Parse argv flags (Mid M5). --key value / --key=value / --flag; posi Parse `--key value` / `--key=value` / `--flag`. A bare `--flag` must not be followed by a non-option token if you need it as boolean (put flags last, or use `--flag=true`). Positionals land under `_`. -**> host_cli_parse args=`args`** +*> host_cli_parse args=`args`* diff --git a/lib/csv.mq.md b/lib/csv.mq.md index 357e9e0..753da3d 100644 --- a/lib/csv.mq.md +++ b/lib/csv.mq.md @@ -6,9 +6,9 @@ description: RFC4180-ish CSV parse/stringify (Mid M4). First row = headers → l ## parse + `text` -**> host_csv_parse text=`text`** +*> host_csv_parse text=`text`* ## stringify + `rows` -**> host_csv_stringify rows=`rows`** +*> host_csv_stringify rows=`rows`* diff --git a/lib/datetime.mq.md b/lib/datetime.mq.md index 2f24885..5d2d11d 100644 --- a/lib/datetime.mq.md +++ b/lib/datetime.mq.md @@ -7,18 +7,18 @@ description: Calendar moments as maps {unix, zone, iso} (Mid2 M7). Fixed offsets Current UTC moment map. -**> host_datetime_now** +*> host_datetime_now* ## from_unix + `unix` + `zone`=None -**> host_datetime_from_unix unix=`unix` zone=`zone`** +*> host_datetime_from_unix unix=`unix` zone=`zone`* ## to_unix + `dt` -**> host_datetime_to_unix dt=`dt`** +*> host_datetime_to_unix dt=`dt`* ## parse + `text` @@ -26,7 +26,7 @@ Current UTC moment map. RFC3339 / `YYYY-MM-DD[ HH:MM:SS]` by default; `pattern=` is strftime or `rfc3339`. -**> host_datetime_parse text=`text` pattern=`pattern`** +*> host_datetime_parse text=`text` pattern=`pattern`* ## format + `dt` @@ -34,7 +34,7 @@ RFC3339 / `YYYY-MM-DD[ HH:MM:SS]` by default; `pattern=` is strftime or `rfc3339 Styles: `rfc3339` (default), `date`, `time`, or a strftime pattern. -**> host_datetime_format dt=`dt` style=`style`** +*> host_datetime_format dt=`dt` style=`style`* ## add + `dt` @@ -43,7 +43,7 @@ Styles: `rfc3339` (default), `date`, `time`, or a strftime pattern. + `minutes`=None + `seconds`=None -**> host_datetime_add dt=`dt` days=`days` hours=`hours` minutes=`minutes` seconds=`seconds`** +*> host_datetime_add dt=`dt` days=`days` hours=`hours` minutes=`minutes` seconds=`seconds`* ## in_zone + `dt` @@ -51,4 +51,4 @@ Styles: `rfc3339` (default), `date`, `time`, or a strftime pattern. Re-express the same instant in `+08:00` / `UTC` / fixed aliases like `Asia/Shanghai`. -**> host_datetime_in_zone dt=`dt` zone=`zone`** +*> host_datetime_in_zone dt=`dt` zone=`zone`* diff --git a/lib/encoding.mq.md b/lib/encoding.mq.md index 47338e8..ef63c43 100644 --- a/lib/encoding.mq.md +++ b/lib/encoding.mq.md @@ -6,31 +6,31 @@ description: Base64, hex, and base32 encode/decode (Mid M1 + Mid2 M8). UTF-8 tex ## base64_encode + `text` -**> host_encoding_base64_encode text=`text`** +*> host_encoding_base64_encode text=`text`* ## base64_decode + `text` -**> host_encoding_base64_decode text=`text`** +*> host_encoding_base64_decode text=`text`* ## hex_encode + `text` -**> host_encoding_hex_encode text=`text`** +*> host_encoding_hex_encode text=`text`* ## hex_decode + `text` -**> host_encoding_hex_decode text=`text`** +*> host_encoding_hex_decode text=`text`* ## base32_encode + `text` RFC 4648 alphabet; padding with `=`. -**> host_encoding_base32_encode text=`text`** +*> host_encoding_base32_encode text=`text`* ## base32_decode + `text` -**> host_encoding_base32_decode text=`text`** +*> host_encoding_base32_decode text=`text`* diff --git a/lib/foreign.mq.md b/lib/foreign.mq.md index 2963c79..1fea9ab 100644 --- a/lib/foreign.mq.md +++ b/lib/foreign.mq.md @@ -7,21 +7,21 @@ description: Run bound code fences and inline sources via local interpreters + `lang` + `cmd` -**> host_foreign_set_cmd lang=`lang` cmd=`cmd`** +*> host_foreign_set_cmd lang=`lang` cmd=`cmd`* ## run + `code` + `stdin`=None -**> host_foreign_run code=`code` stdin=`stdin`** +*> host_foreign_run code=`code` stdin=`stdin`* ## run_lang + `lang` + `source` + `stdin`=None -**> host_foreign_run_lang lang=`lang` source=`source` stdin=`stdin`** +*> host_foreign_run_lang lang=`lang` source=`source` stdin=`stdin`* ## langs -**> host_foreign_langs** +*> host_foreign_langs* diff --git a/lib/fs.mq.md b/lib/fs.mq.md index 09d2e1c..2ae87e6 100644 --- a/lib/fs.mq.md +++ b/lib/fs.mq.md @@ -6,67 +6,67 @@ description: English filesystem wrappers ## read_text + `path` -**> host_read_text path=`path`** +*> host_read_text path=`path`* ## write_text + `path` + `text` -**> host_write_text path=`path` text=`text`** +*> host_write_text path=`path` text=`text`* ## append_text + `path` + `text` -**> host_append_text path=`path` text=`text`** +*> host_append_text path=`path` text=`text`* ## exists + `path` -**> host_exists path=`path`** +*> host_exists path=`path`* ## list_dir + `path` -**> host_list_dir path=`path`** +*> host_list_dir path=`path`* ## make_dir + `path` -**> host_make_dir path=`path`** +*> host_make_dir path=`path`* ## make_dirs + `path` Create directories recursively (`mkdir -p`). -**> host_make_dirs path=`path`** +*> host_make_dirs path=`path`* ## remove + `path` -**> host_remove path=`path`** +*> host_remove path=`path`* ## remove_tree + `path` Remove a directory recursively. Errors if `path` is a file. -**> host_remove_tree path=`path`** +*> host_remove_tree path=`path`* ## stat + `path` Returns `{size, mtime_unix, is_file, is_dir}`. -**> host_stat path=`path`** +*> host_stat path=`path`* ## walk + `path` Depth-first listing of relative paths under `path` (forward slashes). -**> host_walk path=`path`** +*> host_walk path=`path`* ## copy_file + `src` @@ -74,7 +74,7 @@ Depth-first listing of relative paths under `path` (forward slashes). Copy a file (overwrites `dest` if it exists). Paths are sandboxed like other fs ops. -**> host_copy_file src=`src` dest=`dest`** +*> host_copy_file src=`src` dest=`dest`* ## move + `src` @@ -82,14 +82,14 @@ Copy a file (overwrites `dest` if it exists). Paths are sandboxed like other fs Rename / move within the sandbox. -**> host_move src=`src` dest=`dest`** +*> host_move src=`src` dest=`dest`* ## make_temp + `prefix`=None Create an empty temp file under the program directory; return its relative path. -**> host_make_temp prefix=`prefix`** +*> host_make_temp prefix=`prefix`* ## text_patch + `path` @@ -98,7 +98,7 @@ Create an empty temp file under the program directory; return its relative path. Exact FIND→REPLACE once in a UTF-8 text file. `find` must match exactly once. -**> host_text_patch path=`path` find=`find` replace=`replace`** +*> host_text_patch path=`path` find=`find` replace=`replace`* ## apply_patch_blocks + `path` @@ -107,6 +107,6 @@ Exact FIND→REPLACE once in a UTF-8 text file. `find` must match exactly once. Apply plan-style triple-angle FIND/REPLACE blocks from `text` to `path`. Also accepts fenced find/replace pairs and minimal Begin Patch hunks. -When `soft=True`, **only** “FIND not found” returns `0` (run continues). Empty FIND, multi-match, parse errors, and whole-file FIND still abort — whole-file rewrite is forbidden. +When `soft=True`, *only* “FIND not found” returns `0` (run continues). Empty FIND, multi-match, parse errors, and whole-file FIND still abort — whole-file rewrite is forbidden. -**> host_apply_patch_blocks path=`path` text=`text` soft=`soft`** +*> host_apply_patch_blocks path=`path` text=`text` soft=`soft`* diff --git a/lib/hash.mq.md b/lib/hash.mq.md index 3dfe7d8..f15d61e 100644 --- a/lib/hash.mq.md +++ b/lib/hash.mq.md @@ -6,20 +6,20 @@ description: Digests and HMAC (Mid M3). Integrity / cache keys — not password ## sha256 + `text` -**> host_hash_sha256 text=`text`** +*> host_hash_sha256 text=`text`* ## sha1 + `text` -**> host_hash_sha1 text=`text`** +*> host_hash_sha1 text=`text`* ## md5 + `text` -**> host_hash_md5 text=`text`** +*> host_hash_md5 text=`text`* ## hmac_sha256 + `key` + `text` -**> host_hash_hmac_sha256 key=`key` text=`text`** +*> host_hash_hmac_sha256 key=`key` text=`text`* diff --git a/lib/html.mq.md b/lib/html.mq.md index 95a1665..f6cd902 100644 --- a/lib/html.mq.md +++ b/lib/html.mq.md @@ -6,9 +6,9 @@ description: HTML escape / unescape (Mid2 M8). XSS floor for string assembly. ## escape + `text` -**> host_html_escape text=`text`** +*> host_html_escape text=`text`* ## unescape + `text` -**> host_html_unescape text=`text`** +*> host_html_unescape text=`text`* diff --git a/lib/json.mq.md b/lib/json.mq.md index e68e3b9..a5e12fe 100644 --- a/lib/json.mq.md +++ b/lib/json.mq.md @@ -6,39 +6,39 @@ description: JSON parse/stringify (shared EN/ZH import) ## parse + `text` -**> host_json_parse text=`text`** +*> host_json_parse text=`text`* ## stringify + `value` + `indent`=None -**> host_json_stringify value=`value` indent=`indent`** +*> host_json_stringify value=`value` indent=`indent`* ## get + `value` + `key` -**> host_json_get value=`value` key=`key`** +*> host_json_get value=`value` key=`key`* ## keys + `value` -**> host_json_keys value=`value`** +*> host_json_keys value=`value`* ## quote + `text` -**> host_json_quote text=`text`** +*> host_json_quote text=`text`* ## set + `map` + `key` + `value` -**> host_map_set map=`map` key=`key` value=`value`** +*> host_map_set map=`map` key=`key` value=`value`* ## append + `list` + `item` -**> host_list_append list=`list` item=`item`** +*> host_list_append list=`list` item=`item`* diff --git a/lib/log.mq.md b/lib/log.mq.md index bf028e6..05be585 100644 --- a/lib/log.mq.md +++ b/lib/log.mq.md @@ -8,44 +8,44 @@ description: Level-filtered one-line logs (Mid M6 + Mid2 M10 fields). Default le level is debug / info / warn / error. -**> host_log_set_level level=`level`** +*> host_log_set_level level=`level`* ## debug + `text` + `fields`=None -*line = > host_log_line level="debug" text=`text` fields=`fields`* +**line = > host_log_line level="debug" text=`text` fields=`fields`** 1. `line` > print text=`line` -2. * +2. ** **** ## info + `text` + `fields`=None -*line = > host_log_line level="info" text=`text` fields=`fields`* +**line = > host_log_line level="info" text=`text` fields=`fields`** 1. `line` > print text=`line` -2. * +2. ** **** ## warn + `text` + `fields`=None -*line = > host_log_line level="warn" text=`text` fields=`fields`* +**line = > host_log_line level="warn" text=`text` fields=`fields`** 1. `line` > print text=`line` -2. * +2. ** **** ## error + `text` + `fields`=None -*line = > host_log_line level="error" text=`text` fields=`fields`* +**line = > host_log_line level="error" text=`text` fields=`fields`** 1. `line` > print text=`line` -2. * +2. ** **** diff --git a/lib/math.mq.md b/lib/math.mq.md index d27327c..9e309c3 100644 --- a/lib/math.mq.md +++ b/lib/math.mq.md @@ -5,173 +5,173 @@ description: High-school math — num, random, formula, plot ## pi -**> host_pi** +*> host_pi* ## e -**> host_e** +*> host_e* ## num + `value` -**> host_num value=`value`** +*> host_num value=`value`* ## add + `a` + `b` -**> host_math_add a=`a` b=`b`** +*> host_math_add a=`a` b=`b`* ## sub + `a` + `b` -**> host_math_sub a=`a` b=`b`** +*> host_math_sub a=`a` b=`b`* ## mul + `a` + `b` -**> host_math_mul a=`a` b=`b`** +*> host_math_mul a=`a` b=`b`* ## div + `a` + `b` -**> host_math_div a=`a` b=`b`** +*> host_math_div a=`a` b=`b`* ## pow + `a` + `b` -**> host_math_pow a=`a` b=`b`** +*> host_math_pow a=`a` b=`b`* ## neg + `value` -**> host_math_neg value=`value`** +*> host_math_neg value=`value`* ## sin + `value` -**> host_math_sin value=`value`** +*> host_math_sin value=`value`* ## cos + `value` -**> host_math_cos value=`value`** +*> host_math_cos value=`value`* ## tan + `value` -**> host_math_tan value=`value`** +*> host_math_tan value=`value`* ## asin + `value` -**> host_math_asin value=`value`** +*> host_math_asin value=`value`* ## acos + `value` -**> host_math_acos value=`value`** +*> host_math_acos value=`value`* ## atan + `value` -**> host_math_atan value=`value`** +*> host_math_atan value=`value`* ## sqrt + `value` -**> host_math_sqrt value=`value`** +*> host_math_sqrt value=`value`* ## abs + `value` -**> host_math_abs value=`value`** +*> host_math_abs value=`value`* ## ln + `value` -**> host_math_ln value=`value`** +*> host_math_ln value=`value`* ## exp + `value` -**> host_math_exp value=`value`** +*> host_math_exp value=`value`* ## floor + `value` -**> host_math_floor value=`value`** +*> host_math_floor value=`value`* ## ceil + `value` -**> host_math_ceil value=`value`** +*> host_math_ceil value=`value`* ## min + `a` + `b` -**> host_math_min a=`a` b=`b`** +*> host_math_min a=`a` b=`b`* ## max + `a` + `b` -**> host_math_max a=`a` b=`b`** +*> host_math_max a=`a` b=`b`* ## random -**> host_random** +*> host_random* ## random_int + `min` + `max` -**> host_random_int min=`min` max=`max`** +*> host_random_int min=`min` max=`max`* ## seed + `value` -**> host_seed value=`value`** +*> host_seed value=`value`* ## formula + `text` -**> host_formula value=`text`** +*> host_formula value=`text`* ## simplify + `formula` -**> host_simplify value=`formula`** +*> host_simplify value=`formula`* ## expand + `formula` -**> host_expand value=`formula`** +*> host_expand value=`formula`* ## diff + `formula` + `var` -**> host_diff formula=`formula` var=`var`** +*> host_diff formula=`formula` var=`var`* ## subs + `formula` + `var` + `value` -**> host_subs formula=`formula` var=`var` value=`value`** +*> host_subs formula=`formula` var=`var` value=`value`* ## eval + `formula` + `var` + `value` -**> host_eval formula=`formula` var=`var` value=`value`** +*> host_eval formula=`formula` var=`var` value=`value`* ## solve + `formula` @@ -179,7 +179,7 @@ description: High-school math — num, random, formula, plot + `min`=None + `max`=None -**> host_solve formula=`formula` var=`var` min=`min` max=`max`** +*> host_solve formula=`formula` var=`var` min=`min` max=`max`* ## plot + `formula` @@ -191,7 +191,7 @@ description: High-school math — num, random, formula, plot + `derivative`=None + `grid`=None -**> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`** +*> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`* ## plot_points + `xs` @@ -199,7 +199,7 @@ description: High-school math — num, random, formula, plot + `path`=None + `grid`=None -**> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`** +*> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`* ## plot_conic + `kind` @@ -210,4 +210,4 @@ description: High-school math — num, random, formula, plot + `path`=None + `grid`=None -**> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`** +*> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`* diff --git a/lib/net.mq.md b/lib/net.mq.md index f78aa73..86d1b72 100644 --- a/lib/net.mq.md +++ b/lib/net.mq.md @@ -9,7 +9,7 @@ description: English HTTP(S) wrappers. Optional headers / content_type via host HTTPS supported. Optional named arg `headers=` (map). -**> host_http_get url=`url` headers=`headers`** +*> host_http_get url=`url` headers=`headers`* ## http_post + `url` @@ -19,7 +19,7 @@ HTTPS supported. Optional named arg `headers=` (map). Default content type is JSON. Optional `content_type=` / `headers=` (map). -**> host_http_post url=`url` body=`body` content_type=`content_type` headers=`headers`** +*> host_http_post url=`url` body=`body` content_type=`content_type` headers=`headers`* ## http_post_sse + `url` @@ -30,7 +30,7 @@ Default content type is JSON. Optional `content_type=` / `headers=` (map). POST and consume OpenAI-compatible SSE. Returns `{status, events}` where `events` is a list of `{type, …}` maps (`delta` / `done` / `error`). Optional `echo=True` prints delta text to stdout as chunks arrive. -**> host_http_post_sse url=`url` body=`body` content_type=`content_type` headers=`headers` echo=`echo`** +*> host_http_post_sse url=`url` body=`body` content_type=`content_type` headers=`headers` echo=`echo`* ## openai_sse_parse + `text` @@ -38,7 +38,7 @@ POST and consume OpenAI-compatible SSE. Returns `{status, events}` where `events Offline: parse an OpenAI chat SSE body into the same event list (no network). -**> host_openai_sse_parse text=`text` echo=`echo`** +*> host_openai_sse_parse text=`text` echo=`echo`* ## http_request + `method` @@ -49,12 +49,12 @@ Offline: parse an OpenAI chat SSE body into the same event list (no network). Optional `body=` / `content_type=` / `headers=`. -**> host_http_request method=`method` url=`url` body=`body` content_type=`content_type` headers=`headers`** +*> host_http_request method=`method` url=`url` body=`body` content_type=`content_type` headers=`headers`* ## url_encode + `text` -**> host_url_encode text=`text`** +*> host_url_encode text=`text`* ## cookie_parse + `text` @@ -62,7 +62,7 @@ Optional `body=` / `content_type=` / `headers=`. Parse a `Cookie` request header (default) or one or more `Set-Cookie` response headers (`is_response=True`) into a list of `{name, value, path, domain, expires, max_age, secure, http_only, same_site}`. -**> host_cookie_parse text=`text` is_response=`is_response`** +*> host_cookie_parse text=`text` is_response=`is_response`* ## multipart_parse + `body` @@ -70,11 +70,11 @@ Parse a `Cookie` request header (default) or one or more `Set-Cookie` response h Parse a `multipart/form-data` request body (given its `boundary`) into a list of `{name, filename?, content_type?, value}` parts. -**> host_multipart_parse body=`body` boundary=`boundary`** +*> host_multipart_parse body=`body` boundary=`boundary`* ## markdown_parse + `text` Parse Markdown / GFM into HTML (pure transform, no network I/O). -**> host_markdown_parse text=`text`** +*> host_markdown_parse text=`text`* diff --git a/lib/path.mq.md b/lib/path.mq.md index 681b85c..bc56c8c 100644 --- a/lib/path.mq.md +++ b/lib/path.mq.md @@ -7,34 +7,34 @@ description: Path algebra (Mid M2). No I/O; OS separators. + `a` + `b` -**> host_path_join a=`a` b=`b`** +*> host_path_join a=`a` b=`b`* ## split + `path` -**> host_path_split path=`path`** +*> host_path_split path=`path`* ## file_name + `path` -**> host_path_file_name path=`path`** +*> host_path_file_name path=`path`* ## parent + `path` -**> host_path_parent path=`path`** +*> host_path_parent path=`path`* ## extension + `path` -**> host_path_extension path=`path`** +*> host_path_extension path=`path`* ## normalize + `path` -**> host_path_normalize path=`path`** +*> host_path_normalize path=`path`* ## is_absolute + `path` -**> host_path_is_absolute path=`path`** +*> host_path_is_absolute path=`path`* diff --git a/lib/plugin.mq.md b/lib/plugin.mq.md index 40aa267..842802a 100644 --- a/lib/plugin.mq.md +++ b/lib/plugin.mq.md @@ -6,19 +6,19 @@ description: Load optional native ABI plugins (.dll / .so / .dylib) ## load + `path` -**> host_plugin_load path=`path`** +*> host_plugin_load path=`path`* ## unload -**> host_plugin_unload** +*> host_plugin_unload* ## list -**> host_plugin_list** +*> host_plugin_list* ## native_path + `name` Resolve installed / local native plugin path (e.g. `agent`). -**> host_ext_native_path name=`name`** +*> host_ext_native_path name=`name`* diff --git a/lib/re.mq.md b/lib/re.mq.md index b449e90..a873462 100644 --- a/lib/re.mq.md +++ b/lib/re.mq.md @@ -7,19 +7,19 @@ description: Regular expressions (Mid M1). Unicode; no backreferences. + `text` + `pattern` -**> host_re_is_match text=`text` pattern=`pattern`** +*> host_re_is_match text=`text` pattern=`pattern`* ## find + `text` + `pattern` -**> host_re_find text=`text` pattern=`pattern`** +*> host_re_find text=`text` pattern=`pattern`* ## find_all + `text` + `pattern` -**> host_re_find_all text=`text` pattern=`pattern`** +*> host_re_find_all text=`text` pattern=`pattern`* ## replace + `text` @@ -29,10 +29,10 @@ description: Regular expressions (Mid M1). Unicode; no backreferences. Optional `count=` limits replacements (`None` = all). -**> host_re_replace text=`text` pattern=`pattern` with=`with` count=`count`** +*> host_re_replace text=`text` pattern=`pattern` with=`with` count=`count`* ## split + `text` + `pattern` -**> host_re_split text=`text` pattern=`pattern`** +*> host_re_split text=`text` pattern=`pattern`* diff --git a/lib/secrets.mq.md b/lib/secrets.mq.md index 55792ad..15c9f87 100644 --- a/lib/secrets.mq.md +++ b/lib/secrets.mq.md @@ -8,11 +8,11 @@ description: Cryptographic tokens (Mid M3). Do not use math.random for secrets. Byte length `n` (default 16). Returns lowercase hex of length `2*n`. -**> host_secrets_token_hex n=`n`** +*> host_secrets_token_hex n=`n`* ## token_urlsafe + `n`=None Byte length `n` (default 16). URL-safe Base64 without padding. -**> host_secrets_token_urlsafe n=`n`** +*> host_secrets_token_urlsafe n=`n`* diff --git a/lib/stats.mq.md b/lib/stats.mq.md index c61d5e0..19ed906 100644 --- a/lib/stats.mq.md +++ b/lib/stats.mq.md @@ -6,16 +6,16 @@ description: Thin mean / median / sample stdev (Mid2 M10). Not a dataframe libra ## mean + `list` -**> host_stats_mean list=`list`** +*> host_stats_mean list=`list`* ## median + `list` -**> host_stats_median list=`list`** +*> host_stats_median list=`list`* ## stdev + `list` Sample standard deviation; needs at least two values. -**> host_stats_stdev list=`list`** +*> host_stats_stdev list=`list`* diff --git a/lib/subtask.mq.md b/lib/subtask.mq.md index b95b304..5ab59f3 100644 --- a/lib/subtask.mq.md +++ b/lib/subtask.mq.md @@ -18,23 +18,23 @@ Set `quiet=False` to inherit parent stdout/stderr. File `wait` returns `{code, value}` plus optional `stdout`/`stderr` tails when quiet-captured. `value` is the child's `# main` return (not stdout). -**> host_subtask_spawn path=`path` fn=`fn` args=`args` code=`code` lang=`lang` source=`source` stdin=`stdin` quiet=`quiet`** +*> host_subtask_spawn path=`path` fn=`fn` args=`args` code=`code` lang=`lang` source=`source` stdin=`stdin` quiet=`quiet`* ## poll + `id` -**> host_subtask_poll id=`id`** +*> host_subtask_poll id=`id`* ## wait + `id` -**> host_subtask_join id=`id`** +*> host_subtask_join id=`id`* ## kill + `id` -**> host_subtask_kill id=`id`** +*> host_subtask_kill id=`id`* ## wait_all -**> host_subtask_wait_all** +*> host_subtask_wait_all* diff --git a/lib/sys.mq.md b/lib/sys.mq.md index 9a8fabe..ce71f30 100644 --- a/lib/sys.mq.md +++ b/lib/sys.mq.md @@ -6,33 +6,33 @@ description: English system wrappers (load_dotenv accepts optional path via host ## env_get + `name` -**> host_env_get name=`name`** +*> host_env_get name=`name`* ## env_set + `name` + `value` -**> host_env_set name=`name` value=`value`** +*> host_env_set name=`name` value=`value`* ## load_dotenv + `path`=None Load `.env` (optional named arg `path=`). Existing process env is not overridden. -**> host_dotenv_load path=`path`** +*> host_dotenv_load path=`path`* ## args -**> host_args** +*> host_args* ## cwd -**> host_cwd** +*> host_cwd* ## exit + `code` -**> host_exit code=`code`** +*> host_exit code=`code`* ## exec + `cmd` @@ -43,13 +43,13 @@ Run a process. Default return is the exit code (int). With `capture=True`, return a map `{code, stdout, stderr}` (stdout/stderr may be truncated for huge output). -Inside `*…*` prefer bare `args=args` (variable); `` args=`args` `` is also accepted. +Inside `**…**` prefer bare `args=args` (variable); `` args=`args` `` is also accepted. -**> host_exec cmd=`cmd` args=`args` capture=`capture`** +*> host_exec cmd=`cmd` args=`args` capture=`capture`* ## stream_publish + `event` Publish a stream event map onto the process EventBus (`marqdo view` SSE). No-op when nothing is subscribed. -**> host_stream_publish event=`event`** +*> host_stream_publish event=`event`* diff --git a/lib/table.mq.md b/lib/table.mq.md index f36ede6..31d754c 100644 --- a/lib/table.mq.md +++ b/lib/table.mq.md @@ -10,19 +10,19 @@ description: >- + `at` + `value` -Directly update one element. `at=` is a text key, a **1-based** list index, or a list path of keys/indices (same nesting as footnotes). +Directly update one element. `at=` is a text key, a *1-based* list index, or a list path of keys/indices (same nesting as footnotes). -**> host_collection_put in=`in` at=`at` value=`value`** +*> host_collection_put in=`in` at=`at` value=`value`* ## len + `xs` -**> len `xs`** +*> len `xs`* ## rows + `xs` -**> len `xs`** +*> len `xs`* ## at + `xs` @@ -30,31 +30,31 @@ Directly update one element. `at=` is a text key, a **1-based** list index, or a Index is zero-based (same as builtin `at`). Out of range → `None`. -**> at value=`xs` index=`i`** +*> at value=`xs` index=`i`* ## row_at + `xs` + `i` -**> at value=`xs` index=`i`** +*> at value=`xs` index=`i`* ## append + `list` + `item` -**> host_list_append list=`list` item=`item`** +*> host_list_append list=`list` item=`item`* ## prepend + `list` + `item` -**> host_list_prepend list=`list` item=`item`** +*> host_list_prepend list=`list` item=`item`* ## concat + `a` + `b` -**> host_list_concat a=`a` b=`b`** +*> host_list_concat a=`a` b=`b`* ## insert + `list` @@ -63,7 +63,7 @@ Index is zero-based (same as builtin `at`). Out of range → `None`. Index is zero-based (may insert at `len` to append). -**> host_list_insert list=`list` index=`index` item=`item`** +*> host_list_insert list=`list` index=`index` item=`item`* ## set_at + `list` @@ -72,34 +72,34 @@ Index is zero-based (may insert at `len` to append). Zero-based replace. Prefer `put` with 1-based index for author-facing edits. -**> host_list_set_at list=`list` index=`index` item=`item`** +*> host_list_set_at list=`list` index=`index` item=`item`* ## remove_at + `list` + `index` -**> host_list_remove_at list=`list` index=`index`** +*> host_list_remove_at list=`list` index=`index`* ## pop + `list` Drop the last item (errors if empty). Use `last` first when you need the removed value. -*`n` = > len `list`* +**`n` = > len `list`** 1. `n` > 0 - **> host_list_remove_at list=`list` index=`n` - 1** + *> host_list_remove_at list=`list` index=`n` - 1* 2. * - **> host_list_remove_at list=`list` index=0** + *> host_list_remove_at list=`list` index=0* ## first + `list` -**> host_list_first list=`list`** +*> host_list_first list=`list`* ## last + `list` -**> host_list_last list=`list`** +*> host_list_last list=`list`* ## slice + `list` @@ -108,13 +108,13 @@ Drop the last item (errors if empty). Use `last` first when you need the removed Zero-based half-open range from `start` to `end`. -**> host_list_slice list=`list` start=`start` end=`end`** +*> host_list_slice list=`list` start=`start` end=`end`* ## contains + `list` + `item` -**> host_list_contains list=`list` item=`item`** +*> host_list_contains list=`list` item=`item`* ## index_of + `list` @@ -122,19 +122,19 @@ Zero-based half-open range from `start` to `end`. Zero-based index or `None`. -**> host_list_index_of list=`list` item=`item`** +*> host_list_index_of list=`list` item=`item`* ## reverse + `list` -**> host_list_reverse list=`list`** +*> host_list_reverse list=`list`* ## sort + `list` Ascending sort (int/num/text preferred). -**> host_list_sort list=`list`** +*> host_list_sort list=`list`* ## sort_by + `list` @@ -142,20 +142,20 @@ Ascending sort (int/num/text preferred). Sort a list of maps by `key`. -**> host_list_sort_by list=`list` key=`key`** +*> host_list_sort_by list=`list` key=`key`* ## unique + `list` Stable unique (first wins). -**> host_list_unique list=`list`** +*> host_list_unique list=`list`* ## chunk + `list` + `size` -**> host_list_chunk list=`list` size=`size`** +*> host_list_chunk list=`list` size=`size`* ## zip + `a` @@ -163,21 +163,21 @@ Stable unique (first wins). Pairs until the shorter list ends. -**> host_list_zip a=`a` b=`b`** +*> host_list_zip a=`a` b=`b`* ## flatten + `list` One-level flatten. -**> host_list_flatten list=`list`** +*> host_list_flatten list=`list`* ## clear + `value` Empty list or empty map (by type). -**> host_collection_clear value=`value`** +*> host_collection_clear value=`value`* ## get + `map` @@ -185,7 +185,7 @@ Empty list or empty map (by type). Missing key → `None`. -**> host_map_get map=`map` key=`key`** +*> host_map_get map=`map` key=`key`* ## set + `map` @@ -194,36 +194,36 @@ Missing key → `None`. Shallow map update. Prefer `put` for nested paths. -**> host_map_set map=`map` key=`key` value=`value`** +*> host_map_set map=`map` key=`key` value=`value`* ## delete + `map` + `key` -**> host_map_delete map=`map` key=`key`** +*> host_map_delete map=`map` key=`key`* ## has + `map` + `key` -**> host_map_has map=`map` key=`key`** +*> host_map_has map=`map` key=`key`* ## keys + `map` -**> host_map_keys map=`map`** +*> host_map_keys map=`map`* ## values + `map` -**> host_map_values map=`map`** +*> host_map_values map=`map`* ## items + `map` Rows shaped as key/value maps. -**> host_map_items map=`map`** +*> host_map_items map=`map`* ## merge + `a` @@ -231,17 +231,17 @@ Rows shaped as key/value maps. Right-hand keys win. -**> host_map_merge a=`a` b=`b`** +*> host_map_merge a=`a` b=`b`* ## size + `map` -**> host_map_size map=`map`** +*> host_map_size map=`map`* ## empty_list -**> host_list_concat a=None b=None** +*> host_list_concat a=None b=None* ## empty_map -**> host_map_merge a=None b=None** +*> host_map_merge a=None b=None* diff --git a/lib/text.mq.md b/lib/text.mq.md index 17b4b9c..f6865ed 100644 --- a/lib/text.mq.md +++ b/lib/text.mq.md @@ -6,37 +6,37 @@ description: Text helpers (Mid M4 thicken). Literal replace — use lib/re for r ## str_trim + `s` -**> trim `s`** +*> trim `s`* ## str_split + `s` + `sep` -**> split value=`s` sep=`sep`** +*> split value=`s` sep=`sep`* ## str_join + `xs` + `sep` -**> join value=`xs` sep=`sep`** +*> join value=`xs` sep=`sep`* ## contains + `text` + `sub` -**> host_text_contains text=`text` sub=`sub`** +*> host_text_contains text=`text` sub=`sub`* ## starts_with + `text` + `prefix` -**> host_text_starts_with text=`text` prefix=`prefix`** +*> host_text_starts_with text=`text` prefix=`prefix`* ## ends_with + `text` + `suffix` -**> host_text_ends_with text=`text` suffix=`suffix`** +*> host_text_ends_with text=`text` suffix=`suffix`* ## replace + `text` @@ -46,23 +46,23 @@ description: Text helpers (Mid M4 thicken). Literal replace — use lib/re for r Literal substring replace (`count` optional). -**> host_text_replace text=`text` old=`old` new=`new` count=`count`** +*> host_text_replace text=`text` old=`old` new=`new` count=`count`* ## to_upper + `text` -**> host_text_to_upper text=`text`** +*> host_text_to_upper text=`text`* ## to_lower + `text` -**> host_text_to_lower text=`text`** +*> host_text_to_lower text=`text`* ## repeat + `text` + `n` -**> host_text_repeat text=`text` n=`n`** +*> host_text_repeat text=`text` n=`n`* ## pad + `text` @@ -72,4 +72,4 @@ Literal substring replace (`count` optional). align: left (default), right, or center. -**> host_text_pad text=`text` width=`width` fill=`fill` align=`align`** +*> host_text_pad text=`text` width=`width` fill=`fill` align=`align`* diff --git a/lib/time.mq.md b/lib/time.mq.md index 9507403..4ea25dc 100644 --- a/lib/time.mq.md +++ b/lib/time.mq.md @@ -5,25 +5,25 @@ description: English time wrappers ## now_unix -**> host_now_unix** +*> host_now_unix* ## now_ms -**> host_now_ms** +*> host_now_ms* ## format + `unix` + `pattern` -**> host_format_time unix=`unix` pattern=`pattern`** +*> host_format_time unix=`unix` pattern=`pattern`* ## sleep_ms + `ms` -**> host_sleep_ms ms=`ms`** +*> host_sleep_ms ms=`ms`* ## parse + `text` + `pattern` -**> host_parse_time text=`text` pattern=`pattern`** +*> host_parse_time text=`text` pattern=`pattern`* diff --git a/lib/toml.mq.md b/lib/toml.mq.md index 5e72408..8d88735 100644 --- a/lib/toml.mq.md +++ b/lib/toml.mq.md @@ -6,4 +6,4 @@ description: Read-only TOML subset parse (Mid2 M8). Tables, scalars, arrays; no ## parse + `text` -**> host_toml_parse text=`text`** +*> host_toml_parse text=`text`* diff --git a/lib/url.mq.md b/lib/url.mq.md index 26112f1..0398a44 100644 --- a/lib/url.mq.md +++ b/lib/url.mq.md @@ -8,16 +8,16 @@ description: Parse URLs and query strings (Mid2 M7). Segment encoding stays in n Returns `{scheme, userinfo, host, port, path, query, fragment}`. -**> host_url_parse text=`text`** +*> host_url_parse text=`text`* ## query_parse + `text` Parse `a=1&b=2` into a map; repeated keys become a list. -**> host_url_query_parse text=`text`** +*> host_url_query_parse text=`text`* ## query_stringify + `map` -**> host_url_query_stringify map=`map`** +*> host_url_query_stringify map=`map`* diff --git a/lib/uuid.mq.md b/lib/uuid.mq.md index a75af06..826b113 100644 --- a/lib/uuid.mq.md +++ b/lib/uuid.mq.md @@ -5,4 +5,4 @@ description: UUID v4 (Mid M6). Cryptographic random via getrandom. ## v4 -**> host_uuid_v4** +*> host_uuid_v4* diff --git a/lib/writeback.mq.md b/lib/writeback.mq.md index 0b7ea9f..f2a36a0 100644 --- a/lib/writeback.mq.md +++ b/lib/writeback.mq.md @@ -9,9 +9,9 @@ description: Persist run output in .mq.md (Jupyter-style writeback) + `key`=None + `line`=None -Write `value` to `` in the entry file. Default: insert or replace the block immediately below the call; `at_end=true` replaces the unkeyed EOF block. With `key=` (e.g. `ok` / `error`), replace or create that **named** slot only — slots do not overwrite each other. Optional `line=` anchors the block under that source line (needed when writing from a subtask). +Write `value` to `` in the entry file. Default: insert or replace the block immediately below the call; `at_end=true` replaces the unkeyed EOF block. With `key=` (e.g. `ok` / `error`), replace or create that *named* slot only — slots do not overwrite each other. Optional `line=` anchors the block under that source line (needed when writing from a subtask). -**> host_writeback_record value=`value` at_end=`at_end` key=`key` line=`line`** +*> host_writeback_record value=`value` at_end=`at_end` key=`key` line=`line`* ## get + `at_end`=False @@ -20,7 +20,7 @@ Write `value` to `` in the entry file. Default: insert or Read persisted output for the current call site (adjacent unkeyed block), the unkeyed EOF block when `at_end=true`, or a named slot when `key=` is set. -**> host_writeback_get at_end=`at_end` key=`key` line=`line`** +*> host_writeback_get at_end=`at_end` key=`key` line=`line`* ## clear + `at_end`=False @@ -29,7 +29,7 @@ Read persisted output for the current call site (adjacent unkeyed block), the un Remove the adjacent, EOF, or named output block. -**> host_writeback_clear at_end=`at_end` key=`key` line=`line`** +*> host_writeback_clear at_end=`at_end` key=`key` line=`line`* ## ensure + `key` @@ -38,17 +38,17 @@ Remove the adjacent, EOF, or named output block. Create a named slot with `placeholder` if missing. Never overwrites an existing slot body. -**> host_writeback_ensure key=`key` placeholder=`placeholder` line=`line`** +*> host_writeback_ensure key=`key` placeholder=`placeholder` line=`line`* ## list List all output blocks in the entry file (includes `key` when named). -**> host_writeback_list** +*> host_writeback_list* ## scan_path + `path` List `` slots in any file (workbook inspection). -**> host_writeback_scan_path path=`path`** +*> host_writeback_scan_path path=`path`* diff --git a/lib/命令行.mq.md b/lib/命令行.mq.md index 6390eb7..e5718e1 100644 --- a/lib/命令行.mq.md +++ b/lib/命令行.mq.md @@ -8,4 +8,4 @@ description: 解析命令行参数(中层 M5)。--键 值 / --键=值 / -- 省略 `参数` 时用进程 argv(系统.参数表)。 -**> host_cli_parse args=`参数`** +*> host_cli_parse args=`参数`* diff --git a/lib/哈希.mq.md b/lib/哈希.mq.md index 4c23af7..1ea3b13 100644 --- a/lib/哈希.mq.md +++ b/lib/哈希.mq.md @@ -6,20 +6,20 @@ description: 摘要与 HMAC(中层 M3)。完整性 / 缓存键 — 非密码 ## 哈希256 + `内容` -**> host_hash_sha256 text=`内容`** +*> host_hash_sha256 text=`内容`* ## 哈希1 + `内容` -**> host_hash_sha1 text=`内容`** +*> host_hash_sha1 text=`内容`* ## md5 + `内容` -**> host_hash_md5 text=`内容`** +*> host_hash_md5 text=`内容`* ## 密钥哈希256 + `密钥` + `内容` -**> host_hash_hmac_sha256 key=`密钥` text=`内容`** +*> host_hash_hmac_sha256 key=`密钥` text=`内容`* diff --git a/lib/地址.mq.md b/lib/地址.mq.md index bea37cd..aeb42e4 100644 --- a/lib/地址.mq.md +++ b/lib/地址.mq.md @@ -6,14 +6,14 @@ description: 解析 URL 与查询串(中层 Mid2 M7)。单段编码仍用 ` ## 解析 + `内容` -**> host_url_parse text=`内容`** +*> host_url_parse text=`内容`* ## 查询解析 + `内容` -**> host_url_query_parse text=`内容`** +*> host_url_query_parse text=`内容`* ## 查询串化 + `表` -**> host_url_query_stringify map=`表`** +*> host_url_query_stringify map=`表`* diff --git a/lib/外联.mq.md b/lib/外联.mq.md index c039f98..512c605 100644 --- a/lib/外联.mq.md +++ b/lib/外联.mq.md @@ -7,21 +7,21 @@ description: 通过本机解释器运行绑定的代码围栏与内联源码 + `语言` + `命令` -**> host_foreign_set_cmd lang=`语言` cmd=`命令`** +*> host_foreign_set_cmd lang=`语言` cmd=`命令`* ## 运行 + `代码` + `标准输入`=None -**> host_foreign_run code=`代码` stdin=`标准输入`** +*> host_foreign_run code=`代码` stdin=`标准输入`* ## 按语言运行 + `语言` + `源码` + `标准输入`=None -**> host_foreign_run_lang lang=`语言` source=`源码` stdin=`标准输入`** +*> host_foreign_run_lang lang=`语言` source=`源码` stdin=`标准输入`* ## 语言表 -**> host_foreign_langs** +*> host_foreign_langs* diff --git a/lib/子任务.mq.md b/lib/子任务.mq.md index 8621e1f..9aaa453 100644 --- a/lib/子任务.mq.md +++ b/lib/子任务.mq.md @@ -17,23 +17,23 @@ description: 并发子任务 — 文件、函数或外联代码 `静默=假` 时继承父进程终端输出。 文件 `等待` 返回 `{code, value}`,静默捕获时另含截断的 `stdout`/`stderr`;`value` 为子 `# main` 返回值。 -**> host_subtask_spawn path=`路径` fn=`函数` args=`参数` code=`代码` lang=`语言` source=`源码` stdin=`输入` quiet=`静默`** +*> host_subtask_spawn path=`路径` fn=`函数` args=`参数` code=`代码` lang=`语言` source=`源码` stdin=`输入` quiet=`静默`* ## 探测 + `id` -**> host_subtask_poll id=`id`** +*> host_subtask_poll id=`id`* ## 等待 + `id` -**> host_subtask_join id=`id`** +*> host_subtask_join id=`id`* ## 终止 + `id` -**> host_subtask_kill id=`id`** +*> host_subtask_kill id=`id`* ## 等待全部 -**> host_subtask_wait_all** +*> host_subtask_wait_all* diff --git a/lib/插件.mq.md b/lib/插件.mq.md index 9b74ab8..164ea9e 100644 --- a/lib/插件.mq.md +++ b/lib/插件.mq.md @@ -6,19 +6,19 @@ description: 加载可选原生 ABI 插件(.dll / .so / .dylib) ## 加载 + `路径` -**> host_plugin_load path=`路径`** +*> host_plugin_load path=`路径`* ## 卸载 -**> host_plugin_unload** +*> host_plugin_unload* ## 列出 -**> host_plugin_list** +*> host_plugin_list* ## 原生路径 + `名` 解析已安装或本地原生插件路径(如 `agent`)。 -**> host_ext_native_path name=`名`** +*> host_ext_native_path name=`名`* diff --git a/lib/数学.mq.md b/lib/数学.mq.md index fd5b477..53fc216 100644 --- a/lib/数学.mq.md +++ b/lib/数学.mq.md @@ -5,173 +5,173 @@ description: 高中数学 — 数值、随机、公式、作图 ## 圆周率 -**> host_pi** +*> host_pi* ## 自然底数 -**> host_e** +*> host_e* ## 数 + `value` -**> host_num value=`value`** +*> host_num value=`value`* ## 加 + `a` + `b` -**> host_math_add a=`a` b=`b`** +*> host_math_add a=`a` b=`b`* ## 减 + `a` + `b` -**> host_math_sub a=`a` b=`b`** +*> host_math_sub a=`a` b=`b`* ## 乘 + `a` + `b` -**> host_math_mul a=`a` b=`b`** +*> host_math_mul a=`a` b=`b`* ## 除 + `a` + `b` -**> host_math_div a=`a` b=`b`** +*> host_math_div a=`a` b=`b`* ## 幂 + `a` + `b` -**> host_math_pow a=`a` b=`b`** +*> host_math_pow a=`a` b=`b`* ## 负 + `value` -**> host_math_neg value=`value`** +*> host_math_neg value=`value`* ## 正弦 + `value` -**> host_math_sin value=`value`** +*> host_math_sin value=`value`* ## 余弦 + `value` -**> host_math_cos value=`value`** +*> host_math_cos value=`value`* ## 正切 + `value` -**> host_math_tan value=`value`** +*> host_math_tan value=`value`* ## 反正弦 + `value` -**> host_math_asin value=`value`** +*> host_math_asin value=`value`* ## 反余弦 + `value` -**> host_math_acos value=`value`** +*> host_math_acos value=`value`* ## 反正切 + `value` -**> host_math_atan value=`value`** +*> host_math_atan value=`value`* ## 平方根 + `value` -**> host_math_sqrt value=`value`** +*> host_math_sqrt value=`value`* ## 绝对值 + `value` -**> host_math_abs value=`value`** +*> host_math_abs value=`value`* ## 对数 + `value` -**> host_math_ln value=`value`** +*> host_math_ln value=`value`* ## 指数 + `value` -**> host_math_exp value=`value`** +*> host_math_exp value=`value`* ## 向下取整 + `value` -**> host_math_floor value=`value`** +*> host_math_floor value=`value`* ## 向上取整 + `value` -**> host_math_ceil value=`value`** +*> host_math_ceil value=`value`* ## 最小 + `a` + `b` -**> host_math_min a=`a` b=`b`** +*> host_math_min a=`a` b=`b`* ## 最大 + `a` + `b` -**> host_math_max a=`a` b=`b`** +*> host_math_max a=`a` b=`b`* ## 随机 -**> host_random** +*> host_random* ## 随机整数 + `min` + `max` -**> host_random_int min=`min` max=`max`** +*> host_random_int min=`min` max=`max`* ## 设种子 + `value` -**> host_seed value=`value`** +*> host_seed value=`value`* ## 公式 + `text` -**> host_formula value=`text`** +*> host_formula value=`text`* ## 化简 + `formula` -**> host_simplify value=`formula`** +*> host_simplify value=`formula`* ## 展开 + `formula` -**> host_expand value=`formula`** +*> host_expand value=`formula`* ## 求导 + `formula` + `var` -**> host_diff formula=`formula` var=`var`** +*> host_diff formula=`formula` var=`var`* ## 代入 + `formula` + `var` + `value` -**> host_subs formula=`formula` var=`var` value=`value`** +*> host_subs formula=`formula` var=`var` value=`value`* ## 求值 + `formula` + `var` + `value` -**> host_eval formula=`formula` var=`var` value=`value`** +*> host_eval formula=`formula` var=`var` value=`value`* ## 求解 + `formula` @@ -179,7 +179,7 @@ description: 高中数学 — 数值、随机、公式、作图 + `min`=None + `max`=None -**> host_solve formula=`formula` var=`var` min=`min` max=`max`** +*> host_solve formula=`formula` var=`var` min=`min` max=`max`* ## 绘图 + `formula` @@ -191,7 +191,7 @@ description: 高中数学 — 数值、随机、公式、作图 + `derivative`=None + `grid`=None -**> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`** +*> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`* ## 绘点列 + `xs` @@ -199,7 +199,7 @@ description: 高中数学 — 数值、随机、公式、作图 + `path`=None + `grid`=None -**> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`** +*> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`* ## 绘圆锥 + `kind` @@ -210,4 +210,4 @@ description: 高中数学 — 数值、随机、公式、作图 + `path`=None + `grid`=None -**> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`** +*> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`* diff --git a/lib/文件.mq.md b/lib/文件.mq.md index a06916d..01c9042 100644 --- a/lib/文件.mq.md +++ b/lib/文件.mq.md @@ -6,67 +6,67 @@ description: 中文文件系统包装 ## 读文本 + `路径` -**> host_read_text path=`路径`** +*> host_read_text path=`路径`* ## 写文本 + `路径` + `内容` -**> host_write_text path=`路径` text=`内容`** +*> host_write_text path=`路径` text=`内容`* ## 追加文本 + `路径` + `内容` -**> host_append_text path=`路径` text=`内容`** +*> host_append_text path=`路径` text=`内容`* ## 存在 + `路径` -**> host_exists path=`路径`** +*> host_exists path=`路径`* ## 列目录 + `路径` -**> host_list_dir path=`路径`** +*> host_list_dir path=`路径`* ## 建目录 + `路径` -**> host_make_dir path=`路径`** +*> host_make_dir path=`路径`* ## 建目录树 + `路径` 递归创建目录(等同 `mkdir -p`)。 -**> host_make_dirs path=`路径`** +*> host_make_dirs path=`路径`* ## 删除 + `路径` -**> host_remove path=`路径`** +*> host_remove path=`路径`* ## 删目录树 + `路径` 递归删除目录;若路径是文件则报错。 -**> host_remove_tree path=`路径`** +*> host_remove_tree path=`路径`* ## 状态 + `路径` 返回 `{size, mtime_unix, is_file, is_dir}`。 -**> host_stat path=`路径`** +*> host_stat path=`路径`* ## 遍历 + `路径` 深度优先列出相对路径(正斜杠)。 -**> host_walk path=`路径`** +*> host_walk path=`路径`* ## 复制文件 + `源` @@ -74,7 +74,7 @@ description: 中文文件系统包装 复制文件(目标已存在则覆盖)。路径沙箱同其他文件操作。 -**> host_copy_file src=`源` dest=`目标`** +*> host_copy_file src=`源` dest=`目标`* ## 移动 + `源` @@ -82,14 +82,14 @@ description: 中文文件系统包装 在沙箱内重命名 / 移动。 -**> host_move src=`源` dest=`目标`** +*> host_move src=`源` dest=`目标`* ## 建临时 + `前缀`=None 在程序目录下创建空临时文件,返回相对路径。 -**> host_make_temp prefix=`前缀`** +*> host_make_temp prefix=`前缀`* ## 文本补丁 + `路径` @@ -98,7 +98,7 @@ description: 中文文件系统包装 对 UTF-8 文本文件做精确 FIND→REPLACE(`查找` 必须唯一匹配一次)。 -**> host_text_patch path=`路径` find=`查找` replace=`替换`** +*> host_text_patch path=`路径` find=`查找` replace=`替换`* ## 应用补丁块 + `路径` @@ -107,4 +107,4 @@ description: 中文文件系统包装 解析规划回复中的 FIND/REPLACE 块并应用到 `路径`。`软失败=真` 时仅「找不到 FIND」返回 0;空 FIND、多匹配、整文件重写仍报错。 -**> host_apply_patch_blocks path=`路径` text=`文本` soft=`软失败`** +*> host_apply_patch_blocks path=`路径` text=`文本` soft=`软失败`* diff --git a/lib/文本.mq.md b/lib/文本.mq.md index 299b2e7..d593580 100644 --- a/lib/文本.mq.md +++ b/lib/文本.mq.md @@ -6,37 +6,37 @@ description: 文本库加厚(中层 M4)。字面替换 — 正则请用 lib/ ## 去空白 + `s` -**> trim `s`** +*> trim `s`* ## 拆分 + `s` + `sep` -**> split value=`s` sep=`sep`** +*> split value=`s` sep=`sep`* ## 拼接 + `xs` + `sep` -**> join value=`xs` sep=`sep`** +*> join value=`xs` sep=`sep`* ## 包含 + `内容` + `子串` -**> host_text_contains text=`内容` sub=`子串`** +*> host_text_contains text=`内容` sub=`子串`* ## 开头是 + `内容` + `前缀` -**> host_text_starts_with text=`内容` prefix=`前缀`** +*> host_text_starts_with text=`内容` prefix=`前缀`* ## 结尾是 + `内容` + `后缀` -**> host_text_ends_with text=`内容` suffix=`后缀`** +*> host_text_ends_with text=`内容` suffix=`后缀`* ## 替换 + `内容` @@ -46,23 +46,23 @@ description: 文本库加厚(中层 M4)。字面替换 — 正则请用 lib/ 字面子串替换(可选 `次数`)。 -**> host_text_replace text=`内容` old=`旧` new=`新` count=`次数`** +*> host_text_replace text=`内容` old=`旧` new=`新` count=`次数`* ## 大写 + `内容` -**> host_text_to_upper text=`内容`** +*> host_text_to_upper text=`内容`* ## 小写 + `内容` -**> host_text_to_lower text=`内容`** +*> host_text_to_lower text=`内容`* ## 重复 + `内容` + `次数` -**> host_text_repeat text=`内容` n=`次数`** +*> host_text_repeat text=`内容` n=`次数`* ## 填充 + `内容` @@ -72,4 +72,4 @@ description: 文本库加厚(中层 M4)。字面替换 — 正则请用 lib/ 对齐:left(默认)/ right / center。 -**> host_text_pad text=`内容` width=`宽度` fill=`填充符` align=`对齐`** +*> host_text_pad text=`内容` width=`宽度` fill=`填充符` align=`对齐`* diff --git a/lib/日志.mq.md b/lib/日志.mq.md index 7cb6b91..8ddb288 100644 --- a/lib/日志.mq.md +++ b/lib/日志.mq.md @@ -8,44 +8,44 @@ description: 按级别过滤的一行日志(中层 M6 + Mid2 M10 字段)。 级别:debug / info / warn / error(或 调试/信息/警告/错误)。 -**> host_log_set_level level=`级别`** +*> host_log_set_level level=`级别`* ## 调试 + `内容` + `字段`=None -*line = > host_log_line level="debug" text=`内容` fields=`字段`* +**line = > host_log_line level="debug" text=`内容` fields=`字段`** 1. `line` > 打印 内容=`line` -2. * +2. ** **** ## 信息 + `内容` + `字段`=None -*line = > host_log_line level="info" text=`内容` fields=`字段`* +**line = > host_log_line level="info" text=`内容` fields=`字段`** 1. `line` > 打印 内容=`line` -2. * +2. ** **** ## 警告 + `内容` + `字段`=None -*line = > host_log_line level="warn" text=`内容` fields=`字段`* +**line = > host_log_line level="warn" text=`内容` fields=`字段`** 1. `line` > 打印 内容=`line` -2. * +2. ** **** ## 错误 + `内容` + `字段`=None -*line = > host_log_line level="error" text=`内容` fields=`字段`* +**line = > host_log_line level="error" text=`内容` fields=`字段`** 1. `line` > 打印 内容=`line` -2. * +2. ** **** diff --git a/lib/日期时间.mq.md b/lib/日期时间.mq.md index ea3fde7..4fab040 100644 --- a/lib/日期时间.mq.md +++ b/lib/日期时间.mq.md @@ -5,30 +5,30 @@ description: 日历时刻 map `{unix, zone, iso}`(中层 Mid2 M7)。固定 ## 现在 -**> host_datetime_now** +*> host_datetime_now* ## 自戳 + `秒` + `区`=None -**> host_datetime_from_unix unix=`秒` zone=`区`** +*> host_datetime_from_unix unix=`秒` zone=`区`* ## 成戳 + `时刻` -**> host_datetime_to_unix dt=`时刻`** +*> host_datetime_to_unix dt=`时刻`* ## 解析 + `内容` + `格式`=None -**> host_datetime_parse text=`内容` pattern=`格式`** +*> host_datetime_parse text=`内容` pattern=`格式`* ## 格式化 + `时刻` + `样式`=None -**> host_datetime_format dt=`时刻` style=`样式`** +*> host_datetime_format dt=`时刻` style=`样式`* ## 加 + `时刻` @@ -37,10 +37,10 @@ description: 日历时刻 map `{unix, zone, iso}`(中层 Mid2 M7)。固定 + `分钟`=None + `秒数`=None -**> host_datetime_add dt=`时刻` days=`天` hours=`小时` minutes=`分钟` seconds=`秒数`** +*> host_datetime_add dt=`时刻` days=`天` hours=`小时` minutes=`分钟` seconds=`秒数`* ## 时区 + `时刻` + `区` -**> host_datetime_in_zone dt=`时刻` zone=`区`** +*> host_datetime_in_zone dt=`时刻` zone=`区`* diff --git a/lib/时间.mq.md b/lib/时间.mq.md index c75ddf3..80ea0df 100644 --- a/lib/时间.mq.md +++ b/lib/时间.mq.md @@ -5,25 +5,25 @@ description: 中文时间包装 ## 此刻秒 -**> host_now_unix** +*> host_now_unix* ## 此刻毫秒 -**> host_now_ms** +*> host_now_ms* ## 格式化 + `秒` + `格式` -**> host_format_time unix=`秒` pattern=`格式`** +*> host_format_time unix=`秒` pattern=`格式`* ## 睡眠毫秒 + `毫秒` -**> host_sleep_ms ms=`毫秒`** +*> host_sleep_ms ms=`毫秒`* ## 解析时间 + `内容` + `格式` -**> host_parse_time text=`内容` pattern=`格式`** +*> host_parse_time text=`内容` pattern=`格式`* diff --git a/lib/机密.mq.md b/lib/机密.mq.md index 946b086..dc04941 100644 --- a/lib/机密.mq.md +++ b/lib/机密.mq.md @@ -8,11 +8,11 @@ description: 安全随机令牌(中层 M3)。勿用 math.random 生成令牌 字节长度(默认 16),返回长度为 `2*字节数` 的小写 hex。 -**> host_secrets_token_hex n=`字节数`** +*> host_secrets_token_hex n=`字节数`* ## 网址安全令牌 + `字节数`=None 字节长度(默认 16),URL-safe Base64(无填充)。 -**> host_secrets_token_urlsafe n=`字节数`** +*> host_secrets_token_urlsafe n=`字节数`* diff --git a/lib/标识.mq.md b/lib/标识.mq.md index 7f003a1..0bffce4 100644 --- a/lib/标识.mq.md +++ b/lib/标识.mq.md @@ -5,4 +5,4 @@ description: UUID 版本 4(中层 M6)。经 getrandom 安全随机。 ## 版本4 -**> host_uuid_v4** +*> host_uuid_v4* diff --git a/lib/正则.mq.md b/lib/正则.mq.md index 5cb56f8..0472793 100644 --- a/lib/正则.mq.md +++ b/lib/正则.mq.md @@ -7,19 +7,19 @@ description: 正则表达式(中层 M1)。Unicode;无回溯引用。 + `内容` + `模式` -**> host_re_is_match text=`内容` pattern=`模式`** +*> host_re_is_match text=`内容` pattern=`模式`* ## 查找 + `内容` + `模式` -**> host_re_find text=`内容` pattern=`模式`** +*> host_re_find text=`内容` pattern=`模式`* ## 查找全部 + `内容` + `模式` -**> host_re_find_all text=`内容` pattern=`模式`** +*> host_re_find_all text=`内容` pattern=`模式`* ## 替换 + `内容` @@ -29,10 +29,10 @@ description: 正则表达式(中层 M1)。Unicode;无回溯引用。 可选 `次数=` 限制替换次数(缺省 = 全部)。 -**> host_re_replace text=`内容` pattern=`模式` with=`为` count=`次数`** +*> host_re_replace text=`内容` pattern=`模式` with=`为` count=`次数`* ## 拆分 + `内容` + `模式` -**> host_re_split text=`内容` pattern=`模式`** +*> host_re_split text=`内容` pattern=`模式`* diff --git a/lib/浏览器.mq.md b/lib/浏览器.mq.md index c89b8e6..4bcd333 100644 --- a/lib/浏览器.mq.md +++ b/lib/浏览器.mq.md @@ -11,8 +11,8 @@ import table:lib/table.mq.md 构造 set_text 效应。 -*`m` = > table.put in=None at=选择器 value=文本* -**> table.put in=None at="set_text" value=m** +**`m` = > table.put in=None at=选择器 value=文本** +*> table.put in=None at="set_text" value=m* ## 设HTML + `选择器` @@ -20,8 +20,8 @@ import table:lib/table.mq.md 构造 set_html 效应。 -*`m` = > table.put in=None at=选择器 value=html* -**> table.put in=None at="set_html" value=m** +**`m` = > table.put in=None at=选择器 value=html** +*> table.put in=None at="set_html" value=m* ## 设值 + `选择器` @@ -29,8 +29,8 @@ import table:lib/table.mq.md 构造 set_value 效应。 -*`m` = > table.put in=None at=选择器 value=值* -**> table.put in=None at="set_value" value=m** +**`m` = > table.put in=None at=选择器 value=值** +*> table.put in=None at="set_value" value=m* ## 设类 + `选择器` @@ -38,8 +38,8 @@ import table:lib/table.mq.md 构造 set_class 效应。 -*`m` = > table.put in=None at=选择器 value=类* -**> table.put in=None at="set_class" value=m** +**`m` = > table.put in=None at=选择器 value=类** +*> table.put in=None at="set_class" value=m* ## 设属性 + `选择器` @@ -47,8 +47,8 @@ import table:lib/table.mq.md 构造 set_attr 效应。 -*`m` = > table.put in=None at=选择器 value=属性* -**> table.put in=None at="set_attr" value=m** +**`m` = > table.put in=None at=选择器 value=属性** +*> table.put in=None at="set_attr" value=m* ## 包装 + `键` @@ -56,7 +56,7 @@ import table:lib/table.mq.md 单键效应包装。 -**> table.put in=None at=键 value=值** +*> table.put in=None at=键 value=值* ## 合并 + `甲` @@ -64,7 +64,7 @@ import table:lib/table.mq.md 合并两张效应表,右侧优先。 -**> table.merge a=`甲` b=`乙`** +*> table.merge a=`甲` b=`乙`* ## 画布 + `选择器` @@ -79,7 +79,7 @@ import table:lib/table.mq.md |-----|-------|----------| | `选择器` | `清空` | `命令` | -**> table.put in=None at="canvas" value=spec** +*> table.put in=None at="canvas" value=spec* ## 音频 + `操作`="play" @@ -91,17 +91,17 @@ import table:lib/table.mq.md 构造 audio 效应。 -*`spec` = > table.put in=None at="op" value=操作* -*`spec` = > table.put in=`spec` at="id" value=id* +**`spec` = > table.put in=None at="op" value=操作** +**`spec` = > table.put in=`spec` at="id" value=id** 1. `源` != "" - *`spec` = > table.put in=`spec` at="src" value=源* + **`spec` = > table.put in=`spec` at="src" value=源** 1. `频率` != None - *`spec` = > table.put in=`spec` at="freq" value=频率* + **`spec` = > table.put in=`spec` at="freq" value=频率** 1. `毫秒` != None - *`spec` = > table.put in=`spec` at="ms" value=毫秒* + **`spec` = > table.put in=`spec` at="ms" value=毫秒** 1. `选择器` != "" - *`spec` = > table.put in=`spec` at="sel" value=选择器* -**> table.put in=None at="audio" value=spec** + **`spec` = > table.put in=`spec` at="sel" value=选择器** +*> table.put in=None at="audio" value=spec* ## 读文件 + `选择器` @@ -116,26 +116,26 @@ import table:lib/table.mq.md |-----|----|------| | `选择器` | `格式` | `然后` | -**> table.put in=None at="read_file" value=spec** +*> table.put in=None at="read_file" value=spec* ## 观察 + `规格` 构造 observe 效应。 -**> table.put in=None at="observe" value=规格** +*> table.put in=None at="observe" value=规格* ## 取消观察 + `规格` 构造 unobserve 效应。 -**> table.put in=None at="unobserve" value=规格** +*> table.put in=None at="unobserve" value=规格* ## 聚焦 + `选择器` -**> table.put in=None at="focus" value=选择器** +*> table.put in=None at="focus" value=选择器* ## 导航 + `url` @@ -147,12 +147,12 @@ import table:lib/table.mq.md |-----|---------| | `url` | `替换` | -**> table.put in=None at="navigate" value=spec** +*> table.put in=None at="navigate" value=spec* ## 存储 + `规格` -**> table.put in=None at="storage" value=规格** +*> table.put in=None at="storage" value=规格* ## 定时 + `毫秒` @@ -165,13 +165,13 @@ import table:lib/table.mq.md |----|------|----| | `毫秒` | `然后` | `id` | -**> table.put in=None at="interval" value=spec** +*> table.put in=None at="interval" value=spec* ## 清定时 + `id`="default" -*`spec` = > table.put in=None at="id" value=id* -**> table.put in=None at="clear_interval" value=spec** +**`spec` = > table.put in=None at="id" value=id** +*> table.put in=None at="clear_interval" value=spec* ## 拉取 + `url` @@ -184,7 +184,7 @@ import table:lib/table.mq.md |-----|------|--------| | `url` | `然后` | `方法` | -**> table.put in=None at="fetch" value=spec** +*> table.put in=None at="fetch" value=spec* ## 拉取全部 + `请求` @@ -196,7 +196,7 @@ import table:lib/table.mq.md |----------|------| | `请求` | `然后` | -**> table.put in=None at="fetch_all" value=spec** +*> table.put in=None at="fetch_all" value=spec* ## 延后 + `毫秒` @@ -208,18 +208,18 @@ import table:lib/table.mq.md |----|------| | `毫秒` | `然后` | -**> table.put in=None at="after" value=spec** +*> table.put in=None at="after" value=spec* ## 套接字 + `规格` -**> table.put in=None at="ws" value=规格** +*> table.put in=None at="ws" value=规格* ## 剪贴板 + `文本` -*`spec` = > table.put in=None at="text" value=文本* -**> table.put in=None at="clipboard" value=spec** +**`spec` = > table.put in=None at="text" value=文本** +*> table.put in=None at="clipboard" value=spec* ## 下载 + `正文` @@ -232,4 +232,4 @@ import table:lib/table.mq.md |------|----------|------| | `正文` | `文件名` | `mime` | -**> table.put in=None at="download" value=spec** +*> table.put in=None at="download" value=spec* diff --git a/lib/系统.mq.md b/lib/系统.mq.md index 74c3675..9ba067c 100644 --- a/lib/系统.mq.md +++ b/lib/系统.mq.md @@ -6,33 +6,33 @@ description: 中文系统包装(加载环境 可选 路径=) ## 取环境 + `名` -**> host_env_get name=`名`** +*> host_env_get name=`名`* ## 设环境 + `名` + `值` -**> host_env_set name=`名` value=`值`** +*> host_env_set name=`名` value=`值`* ## 加载环境 + `路径`=None 加载 `.env`(可选具名实参 `路径=`)。不覆盖已有进程环境变量。 -**> host_dotenv_load path=`路径`** +*> host_dotenv_load path=`路径`* ## 参数表 -**> host_args** +*> host_args* ## 工作目录 -**> host_cwd** +*> host_cwd* ## 退出 + `码` -**> host_exit code=`码`** +*> host_exit code=`码`* ## 执行 + `命令` @@ -43,13 +43,13 @@ description: 中文系统包装(加载环境 可选 路径=) `捕获=True` 时返回映射 `{code, stdout, stderr}`(过大输出可能截断)。 -在 `*…*` 内优先写裸变量 `参数=参数`;`` 参数=`参数` `` 亦可。 +在 `**…**` 内优先写裸变量 `参数=参数`;`` 参数=`参数` `` 亦可。 -**> host_exec cmd=`命令` args=`参数` capture=`捕获`** +*> host_exec cmd=`命令` args=`参数` capture=`捕获`* ## 发布流事件 + `事件` 向进程内 EventBus 发布流事件(供 `marqdo view` SSE)。无订阅者时为空操作。 -**> host_stream_publish event=`事件`** +*> host_stream_publish event=`事件`* diff --git a/lib/统计.mq.md b/lib/统计.mq.md index d69929f..5681a7f 100644 --- a/lib/统计.mq.md +++ b/lib/统计.mq.md @@ -6,16 +6,16 @@ description: 薄均值 / 中位数 / 样本标准差(中层 Mid2 M10)。非 ## 均值 + `列表` -**> host_stats_mean list=`列表`** +*> host_stats_mean list=`列表`* ## 中位数 + `列表` -**> host_stats_median list=`列表`** +*> host_stats_median list=`列表`* ## 标准差 + `列表` 样本标准差;至少两个值。 -**> host_stats_stdev list=`列表`** +*> host_stats_stdev list=`列表`* diff --git a/lib/编码.mq.md b/lib/编码.mq.md index c3ecaa1..395c9aa 100644 --- a/lib/编码.mq.md +++ b/lib/编码.mq.md @@ -6,29 +6,29 @@ description: Base64、十六进制与基32编解码(中层 M1 + Mid2 M8)。U ## 基64编码 + `内容` -**> host_encoding_base64_encode text=`内容`** +*> host_encoding_base64_encode text=`内容`* ## 基64解码 + `内容` -**> host_encoding_base64_decode text=`内容`** +*> host_encoding_base64_decode text=`内容`* ## 十六进制编码 + `内容` -**> host_encoding_hex_encode text=`内容`** +*> host_encoding_hex_encode text=`内容`* ## 十六进制解码 + `内容` -**> host_encoding_hex_decode text=`内容`** +*> host_encoding_hex_decode text=`内容`* ## 基32编码 + `内容` -**> host_encoding_base32_encode text=`内容`** +*> host_encoding_base32_encode text=`内容`* ## 基32解码 + `内容` -**> host_encoding_base32_decode text=`内容`** +*> host_encoding_base32_decode text=`内容`* diff --git a/lib/网络.mq.md b/lib/网络.mq.md index e68e1cf..05f715d 100644 --- a/lib/网络.mq.md +++ b/lib/网络.mq.md @@ -9,7 +9,7 @@ description: 中文 HTTP(S) 包装。可选 headers / content_type 经宿主别 支持 HTTPS。可选具名实参 `headers=`(映射)。 -**> host_http_get url=`地址` headers=`headers`** +*> host_http_get url=`地址` headers=`headers`* ## 提交 + `地址` @@ -19,7 +19,7 @@ description: 中文 HTTP(S) 包装。可选 headers / content_type 经宿主别 默认 Content-Type 为 JSON。可选 `content_type=` / `headers=`。 -**> host_http_post url=`地址` body=`内容` content_type=`content_type` headers=`headers`** +*> host_http_post url=`地址` body=`内容` content_type=`content_type` headers=`headers`* ## 提交流式 + `地址` @@ -30,7 +30,7 @@ description: 中文 HTTP(S) 包装。可选 headers / content_type 经宿主别 POST 并消费 OpenAI 兼容 SSE。返回 `{status, events}`(`delta` / `done` / `error`)。`打印增量=真` 时边读边打印增量文本。 -**> host_http_post_sse url=`地址` body=`内容` content_type=`content_type` headers=`headers` echo=`打印增量`** +*> host_http_post_sse url=`地址` body=`内容` content_type=`content_type` headers=`headers` echo=`打印增量`* ## 解析流式 + `内容` @@ -38,7 +38,7 @@ POST 并消费 OpenAI 兼容 SSE。返回 `{status, events}`(`delta` / `done` 离线解析 OpenAI 聊天 SSE 正文为事件列表(不联网)。 -**> host_openai_sse_parse text=`内容` echo=`打印增量`** +*> host_openai_sse_parse text=`内容` echo=`打印增量`* ## 请求 + `方法` @@ -49,12 +49,12 @@ POST 并消费 OpenAI 兼容 SSE。返回 `{status, events}`(`delta` / `done` 可选 `body=` / `content_type=` / `headers=`。 -**> host_http_request method=`方法` url=`地址` body=`body` content_type=`content_type` headers=`headers`** +*> host_http_request method=`方法` url=`地址` body=`body` content_type=`content_type` headers=`headers`* ## 编码地址 + `内容` -**> host_url_encode text=`内容`** +*> host_url_encode text=`内容`* ## 解析Cookie + `内容` @@ -62,7 +62,7 @@ POST 并消费 OpenAI 兼容 SSE。返回 `{status, events}`(`delta` / `done` 解析 `Cookie` 请求头(默认)或一个/多个 `Set-Cookie` 响应头(`是响应头=真`)为 `{name, value, path, domain, expires, max_age, secure, http_only, same_site}` 列表。 -**> host_cookie_parse text=`内容` is_response=`是响应头`** +*> host_cookie_parse text=`内容` is_response=`是响应头`* ## 解析多部分 + `正文` @@ -70,11 +70,11 @@ POST 并消费 OpenAI 兼容 SSE。返回 `{status, events}`(`delta` / `done` 解析 `multipart/form-data` 请求体(给定 `boundary`)为 `{name, filename?, content_type?, value}` 部件列表。 -**> host_multipart_parse body=`正文` boundary=`边界`** +*> host_multipart_parse body=`正文` boundary=`边界`* ## 解析Markdown + `文本` 将 Markdown / GFM 解析为 HTML(纯转换,无网络 I/O)。 -**> host_markdown_parse text=`文本`** +*> host_markdown_parse text=`文本`* diff --git a/lib/自写回.mq.md b/lib/自写回.mq.md index 1d40170..7d908ff 100644 --- a/lib/自写回.mq.md +++ b/lib/自写回.mq.md @@ -11,7 +11,7 @@ description: 将运行结果写回 .mq.md(Jupyter 式自写回) 在入口文件中写入 ``。默认在调用行下方插入或替换;`末尾=true` 时替换无键末尾块。带 `键=`(如 `ok` / `error` / `成功` / `失败`)时只更新该命名槽,互不覆盖。可选 `行=` 锚定到指定源码行(子任务写回时需要)。 -**> host_writeback_record value=`值` at_end=`末尾` key=`键` line=`行`** +*> host_writeback_record value=`值` at_end=`末尾` key=`键` line=`行`* ## 取 + `末尾`=False @@ -20,7 +20,7 @@ description: 将运行结果写回 .mq.md(Jupyter 式自写回) 读取当前调用处紧邻无键块、无键末尾块,或命名槽。 -**> host_writeback_get at_end=`末尾` key=`键` line=`行`** +*> host_writeback_get at_end=`末尾` key=`键` line=`行`* ## 清除 + `末尾`=False @@ -29,7 +29,7 @@ description: 将运行结果写回 .mq.md(Jupyter 式自写回) 删除紧邻块、末尾块或命名槽。 -**> host_writeback_clear at_end=`末尾` key=`键` line=`行`** +*> host_writeback_clear at_end=`末尾` key=`键` line=`行`* ## 确保 + `键` @@ -38,15 +38,15 @@ description: 将运行结果写回 .mq.md(Jupyter 式自写回) 若命名槽不存在则创建并写入占位;已存在则不改动。 -**> host_writeback_ensure key=`键` placeholder=`占位` line=`行`** +*> host_writeback_ensure key=`键` placeholder=`占位` line=`行`* ## 列出 -**> host_writeback_list** +*> host_writeback_list* ## 扫描路径 + `路径` 扫描任意文件中的 `` 槽(工作簿观察)。 -**> host_writeback_scan_path path=`路径`** +*> host_writeback_scan_path path=`路径`* diff --git a/lib/表.mq.md b/lib/表.mq.md index 9f2574a..c320b04 100644 --- a/lib/表.mq.md +++ b/lib/表.mq.md @@ -10,19 +10,19 @@ description: >- + `于` + `值` -直接改某一元。`于=` 为文本键、**1-based** 下标,或键/下标组成的路径列表(与脚注嵌套同构)。 +直接改某一元。`于=` 为文本键、*1-based* 下标,或键/下标组成的路径列表(与脚注嵌套同构)。 -**> host_collection_put in=`入` at=`于` value=`值`** +*> host_collection_put in=`入` at=`于` value=`值`* ## 长度 + `xs` -**> len `xs`** +*> len `xs`* ## 行数 + `xs` -**> len `xs`** +*> len `xs`* ## 取 + `xs` @@ -30,31 +30,31 @@ description: >- 下标从零起(与内置 `at` 相同)。越界 → `None`。 -**> at value=`xs` index=`i`** +*> at value=`xs` index=`i`* ## 取行 + `xs` + `i` -**> at value=`xs` index=`i`** +*> at value=`xs` index=`i`* ## 追加 + `list` + `item` -**> host_list_append list=`list` item=`item`** +*> host_list_append list=`list` item=`item`* ## 前插 + `list` + `item` -**> host_list_prepend list=`list` item=`item`** +*> host_list_prepend list=`list` item=`item`* ## 拼接 + `a` + `b` -**> host_list_concat a=`a` b=`b`** +*> host_list_concat a=`a` b=`b`* ## 插入 + `list` @@ -63,7 +63,7 @@ description: >- 下标从零起。 -**> host_list_insert list=`list` index=`index` item=`item`** +*> host_list_insert list=`list` index=`index` item=`item`* ## 改位 + `list` @@ -72,34 +72,34 @@ description: >- 从零起替换;日常嵌套改写请用「改」。 -**> host_list_set_at list=`list` index=`index` item=`item`** +*> host_list_set_at list=`list` index=`index` item=`item`* ## 删位 + `list` + `index` -**> host_list_remove_at list=`list` index=`index`** +*> host_list_remove_at list=`list` index=`index`* ## 弹出 + `list` 去掉末项(空表报错)。需要末值时先「末」。 -*`n` = > len `list`* +**`n` = > len `list`** 1. `n` > 0 - **> host_list_remove_at list=`list` index=`n` - 1** + *> host_list_remove_at list=`list` index=`n` - 1* 2. * - **> host_list_remove_at list=`list` index=0** + *> host_list_remove_at list=`list` index=0* ## 首 + `list` -**> host_list_first list=`list`** +*> host_list_first list=`list`* ## 末 + `list` -**> host_list_last list=`list`** +*> host_list_last list=`list`* ## 切片 + `list` @@ -108,13 +108,13 @@ description: >- 从零起的半开区间,从 `start` 到 `end`。 -**> host_list_slice list=`list` start=`start` end=`end`** +*> host_list_slice list=`list` start=`start` end=`end`* ## 含有 + `list` + `item` -**> host_list_contains list=`list` item=`item`** +*> host_list_contains list=`list` item=`item`* ## 下标 + `list` @@ -122,19 +122,19 @@ description: >- 从零起的下标;没有 → `None`。 -**> host_list_index_of list=`list` item=`item`** +*> host_list_index_of list=`list` item=`item`* ## 反转 + `list` -**> host_list_reverse list=`list`** +*> host_list_reverse list=`list`* ## 排序 + `list` 升序(优先 int/num/text)。 -**> host_list_sort list=`list`** +*> host_list_sort list=`list`* ## 按键排序 + `list` @@ -142,20 +142,20 @@ description: >- 对 map 列表按键排序。 -**> host_list_sort_by list=`list` key=`key`** +*> host_list_sort_by list=`list` key=`key`* ## 去重 + `list` 保序去重(保留首次)。 -**> host_list_unique list=`list`** +*> host_list_unique list=`list`* ## 分块 + `list` + `size` -**> host_list_chunk list=`list` size=`size`** +*> host_list_chunk list=`list` size=`size`* ## 拉链 + `a` @@ -163,19 +163,19 @@ description: >- 取较短长度配对。 -**> host_list_zip a=`a` b=`b`** +*> host_list_zip a=`a` b=`b`* ## 展平 + `list` 一层展平。 -**> host_list_flatten list=`list`** +*> host_list_flatten list=`list`* ## 清空 + `value` -**> host_collection_clear value=`value`** +*> host_collection_clear value=`value`* ## 取键 + `map` @@ -183,7 +183,7 @@ description: >- 缺键 → `None`。 -**> host_map_get map=`map` key=`key`** +*> host_map_get map=`map` key=`key`* ## 设 + `map` @@ -192,36 +192,36 @@ description: >- 浅层设键;嵌套请用「改」。 -**> host_map_set map=`map` key=`key` value=`value`** +*> host_map_set map=`map` key=`key` value=`value`* ## 删键 + `map` + `key` -**> host_map_delete map=`map` key=`key`** +*> host_map_delete map=`map` key=`key`* ## 有键 + `map` + `key` -**> host_map_has map=`map` key=`key`** +*> host_map_has map=`map` key=`key`* ## 键表 + `map` -**> host_map_keys map=`map`** +*> host_map_keys map=`map`* ## 值表 + `map` -**> host_map_values map=`map`** +*> host_map_values map=`map`* ## 项表 + `map` 键值对行表。 -**> host_map_items map=`map`** +*> host_map_items map=`map`* ## 合并 + `a` @@ -229,17 +229,17 @@ description: >- 右侧覆盖左侧。 -**> host_map_merge a=`a` b=`b`** +*> host_map_merge a=`a` b=`b`* ## 键数 + `map` -**> host_map_size map=`map`** +*> host_map_size map=`map`* ## 空表 -**> host_list_concat a=None b=None** +*> host_list_concat a=None b=None* ## 空字典 -**> host_map_merge a=None b=None** +*> host_map_merge a=None b=None* diff --git a/lib/超文本.mq.md b/lib/超文本.mq.md index fa7672d..f855789 100644 --- a/lib/超文本.mq.md +++ b/lib/超文本.mq.md @@ -6,9 +6,9 @@ description: HTML 转义 / 还原(中层 Mid2 M8)。拼装字符串时的 XS ## 转义 + `内容` -**> host_html_escape text=`内容`** +*> host_html_escape text=`内容`* ## 还原 + `内容` -**> host_html_unescape text=`内容`** +*> host_html_unescape text=`内容`* diff --git a/lib/路径.mq.md b/lib/路径.mq.md index bc741af..c31d46a 100644 --- a/lib/路径.mq.md +++ b/lib/路径.mq.md @@ -7,34 +7,34 @@ description: 路径代数(中层 M2)。无 I/O;分隔符随宿主 OS。 + `甲` + `乙` -**> host_path_join a=`甲` b=`乙`** +*> host_path_join a=`甲` b=`乙`* ## 拆分 + `路径` -**> host_path_split path=`路径`** +*> host_path_split path=`路径`* ## 文件名 + `路径` -**> host_path_file_name path=`路径`** +*> host_path_file_name path=`路径`* ## 父目录 + `路径` -**> host_path_parent path=`路径`** +*> host_path_parent path=`路径`* ## 扩展名 + `路径` -**> host_path_extension path=`路径`** +*> host_path_extension path=`路径`* ## 规范化 + `路径` -**> host_path_normalize path=`路径`** +*> host_path_normalize path=`路径`* ## 是绝对 + `路径` -**> host_path_is_absolute path=`路径`** +*> host_path_is_absolute path=`路径`* diff --git a/lib/逗号表.mq.md b/lib/逗号表.mq.md index f8f74e4..3cd8a03 100644 --- a/lib/逗号表.mq.md +++ b/lib/逗号表.mq.md @@ -6,9 +6,9 @@ description: CSV 解析/序列化(中层 M4)。首行为表头 → 映射列 ## 解析 + `内容` -**> host_csv_parse text=`内容`** +*> host_csv_parse text=`内容`* ## 序列化 + `行集` -**> host_csv_stringify rows=`行集`** +*> host_csv_stringify rows=`行集`* diff --git a/lib/配置表.mq.md b/lib/配置表.mq.md index ad54de3..183a0f8 100644 --- a/lib/配置表.mq.md +++ b/lib/配置表.mq.md @@ -6,4 +6,4 @@ description: 只读 TOML 子集解析(中层 Mid2 M8)。表 / 标量 / 数 ## 解析 + `内容` -**> host_toml_parse text=`内容`** +*> host_toml_parse text=`内容`* diff --git a/src/ast.rs b/src/ast.rs index f07713b..9f07578 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -44,6 +44,8 @@ impl Default for Module { pub struct Param { pub name: String, pub default: Option, + /// True when collected by v0.3 body/prose inference (not an explicit `+` line). + pub inferred: bool, } #[derive(Debug, Clone)] diff --git a/src/lex/mod.rs b/src/lex/mod.rs index a50f50d..d679bb0 100644 --- a/src/lex/mod.rs +++ b/src/lex/mod.rs @@ -47,7 +47,8 @@ fn is_code_starter(c: char) -> bool { /// /// Closing `*` / `**` must not be taken from inside `` `…` `` or `"…"` (GAP-06/07 nested markers). fn is_marqdo_star_line(trimmed: &str) -> bool { - if trimmed == "*" || trimmed == "****" { + // Empty italic return (v0.3) or else `*` / empty returns. + if trimmed == "*" || trimmed == "**" || trimmed == "****" { return true; } if trimmed.starts_with("**") { @@ -62,59 +63,19 @@ fn is_marqdo_star_line(trimmed: &str) -> bool { matching_italic_close(trimmed).is_some() } -/// Index of the closing `*` for a single-star statement, skipping strings and backticks. -fn matching_italic_close(trimmed: &str) -> Option { - if trimmed.starts_with("**") { - return None; - } - let bytes = trimmed.as_bytes(); - let mut i = 1usize; // skip opening * - let mut in_bt = false; - let mut in_str = false; - while i < bytes.len() { - let c = bytes[i]; - if in_str { - if c == b'\\' && i + 1 < bytes.len() { - i += 2; - continue; - } - if c == b'"' { - in_str = false; - } - i += 1; - continue; - } - if in_bt { - if c == b'`' { - in_bt = false; - } - i += 1; - continue; - } - match c { - b'`' => { - in_bt = true; - i += 1; - } - b'"' => { - in_str = true; - i += 1; - } - b'*' => { - // Closing * must be the last non-ws on the line. - if trimmed[i + 1..].trim().is_empty() { - return Some(i); - } - i += 1; - } - _ => i += 1, - } - } - None +/// Closing `**` for a bold segment, skipping strings and backticks. +/// Returns the index within `trimmed` of the first `*` of the closing `**`. +/// When `require_eol`, the closing `**` must be the last non-ws on the line (whole-line code). +pub fn matching_bold_close(trimmed: &str) -> Option { + matching_bold_close_opts(trimmed, true) } -/// Closing `**` for a bold return, skipping strings and backticks. -fn matching_bold_close(trimmed: &str) -> Option { +/// Like [`matching_bold_close`] but allows trailing text after the close (inline prose). +pub fn matching_bold_close_inline(trimmed: &str) -> Option { + matching_bold_close_opts(trimmed, false) +} + +fn matching_bold_close_opts(trimmed: &str, require_eol: bool) -> Option { let Some(rest) = trimmed.strip_prefix("**") else { return None; }; @@ -153,8 +114,7 @@ fn matching_bold_close(trimmed: &str) -> Option { } b'*' if bytes[i + 1] == b'*' => { let after = i + 2; - if rest[after..].trim().is_empty() { - // Position relative to full `trimmed` (after opening `**`). + if !require_eol || rest[after..].trim().is_empty() { return Some(2 + i); } i += 2; @@ -162,6 +122,69 @@ fn matching_bold_close(trimmed: &str) -> Option { _ => i += 1, } } + // Empty bold `****` handled by caller; `**` alone has no close inside rest. + if !require_eol && rest.is_empty() { + return None; + } + None +} + +/// Index of the closing `*` for a single-star segment. +pub fn matching_italic_close(trimmed: &str) -> Option { + matching_italic_close_opts(trimmed, true) +} + +/// Italic close allowing trailing prose after the closing `*`. +pub fn matching_italic_close_inline(trimmed: &str) -> Option { + matching_italic_close_opts(trimmed, false) +} + +fn matching_italic_close_opts(trimmed: &str, require_eol: bool) -> Option { + if trimmed.starts_with("**") { + return None; + } + let bytes = trimmed.as_bytes(); + let mut i = 1usize; // skip opening * + let mut in_bt = false; + let mut in_str = false; + while i < bytes.len() { + let c = bytes[i]; + if in_str { + if c == b'\\' && i + 1 < bytes.len() { + i += 2; + continue; + } + if c == b'"' { + in_str = false; + } + i += 1; + continue; + } + if in_bt { + if c == b'`' { + in_bt = false; + } + i += 1; + continue; + } + match c { + b'`' => { + in_bt = true; + i += 1; + } + b'"' => { + in_str = true; + i += 1; + } + b'*' => { + if !require_eol || trimmed[i + 1..].trim().is_empty() { + return Some(i); + } + i += 1; + } + _ => i += 1, + } + } None } diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 5b77191..d91b9b6 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -1,20 +1,23 @@ //! Line-oriented recursive descent → AST (no Bison). mod expr; +mod prose; pub use expr::{ parse_call_after_gt, parse_call_arg_value, parse_expr, parse_expr_prefer_var, parse_value_or_interp, }; +pub use prose::{scan_prose_line, ProseBit}; use anyhow::{bail, Result}; use crate::ast::{ - BranchArm, Expr, Function, Import, Literal, Module, Stmt, Use, + BranchArm, Expr, Function, Import, Literal, Module, Param, Stmt, Use, }; use crate::diagnostics::{bail_at, Diagnostic, Span}; use crate::lex::{classify_source, ClassifiedLine, LineKind}; use crate::parse::expr::parse_call_after_gt as call_after_gt; +use crate::parse::expr::parse_call_tail; use crate::parse::expr::parse_expr as parse_expr_str; /// Parse full source (with optional frontmatter) into a module AST. @@ -75,11 +78,25 @@ impl<'a> Cursor<'a> { Some(l) } - /// Skip blank + comment; return true if a line remains. + /// Skip blank + writeback; stop on Code **or** Comment that has v0.3 inline bits. fn skip_noise(&mut self) -> bool { while let Some(l) = self.peek() { match l.kind { - LineKind::Blank | LineKind::Comment | LineKind::Writeback => { + LineKind::Blank | LineKind::Writeback => { + self.i += 1; + } + LineKind::Comment => { + let bits = scan_prose_line(l.text.trim_end_matches(['\r', '\n'])); + if bits.iter().any(|b| { + matches!( + b, + ProseBit::BoldCode { .. } + | ProseBit::ItalicReturn { .. } + | ProseBit::Decl { .. } + ) + }) { + return true; + } self.i += 1; } LineKind::Code => return true, @@ -88,6 +105,25 @@ impl<'a> Cursor<'a> { false } + /// True if peek is a Comment line with executable/decl prose bits. + fn peek_is_prose(&self) -> bool { + let Some(l) = self.peek() else { + return false; + }; + if l.kind != LineKind::Comment { + return false; + } + let bits = scan_prose_line(l.text.trim_end_matches(['\r', '\n'])); + bits.iter().any(|b| { + matches!( + b, + ProseBit::BoldCode { .. } + | ProseBit::ItalicReturn { .. } + | ProseBit::Decl { .. } + ) + }) + } + fn parse_frontmatter(&mut self) -> Result<(Vec, Vec)> { let mut imports = Vec::new(); let mut uses = Vec::new(); @@ -166,8 +202,10 @@ impl<'a> Cursor<'a> { children: Vec::new(), base, }; + // Prose decls pending promotion (name → optional default text). + let mut prose_decls: Vec<(String, Option)> = Vec::new(); - // Parameter zone: indented `- name` pure identifiers. + // Parameter zone: explicit `+` lines (legacy / optional). while self.skip_noise() { let Some(l) = self.peek() else { break }; let trimmed = l.text.trim(); @@ -179,8 +217,10 @@ impl<'a> Cursor<'a> { } break; } + if self.peek_is_prose() { + break; + } if let Some(param) = parse_param_line(trimmed) { - // Only accept as param before any body stmt (params first). if fun.body.is_empty() { fun.params.push(param); self.bump(); @@ -190,13 +230,13 @@ impl<'a> Cursor<'a> { break; } - // Body until next heading at level <= ours, or explicit end (--- / *** / empty **). + // Body until next heading at level <= ours, or explicit end. while self.skip_noise() { let Some(l) = self.peek() else { break }; let trimmed = l.text.trim(); - // Empty bold return ends the function body. - if is_empty_bold_return(trimmed) { + // Empty return: whole-line `**`, `****`, `** **` + if is_empty_return_marker(trimmed) { let span = Span { line: l.line_no, col: 1, @@ -224,7 +264,32 @@ impl<'a> Cursor<'a> { break; } - // Nested params mid-body shouldn't happen; treat `-` as control flow. + if self.peek_is_prose() { + let line = self.bump().unwrap(); + let span = Span { + line: line.line_no, + col: 1, + }; + let bits = scan_prose_line(line.text.trim_end_matches(['\r', '\n'])); + for bit in bits { + match bit { + ProseBit::Decl { name, default, .. } => { + if !prose_decls.iter().any(|(n, _)| n == &name) { + prose_decls.push((name, default)); + } + } + ProseBit::BoldCode { inner, .. } => { + fun.body + .push(self.stmt_from_bold_inner(&inner, span.clone())?); + } + ProseBit::ItalicReturn { inner, .. } => { + fun.body.push(stmt_from_italic_return(&inner, span.clone())?); + } + } + } + continue; + } + if is_ordered_branch(trimmed) { fun.body.push(self.parse_branch()?); continue; @@ -237,6 +302,7 @@ impl<'a> Cursor<'a> { fun.body.push(self.parse_simple_stmt()?); } + merge_inferred_params(&mut fun, &prose_decls)?; Ok(fun) } @@ -259,21 +325,24 @@ impl<'a> Cursor<'a> { ); } - // Bold return **…** (empty inner → None) - if trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4 { - let inner = &trimmed[2..trimmed.len() - 2]; - let value = if inner.trim().is_empty() { - Expr::Literal(Literal::None) - } else { - parse_expr_prefer_var(inner)? - }; - return Ok(Stmt::Return { value, span }); + // v0.3: whole-line empty return `**` / `****` + if is_empty_return_marker(trimmed) { + return Ok(Stmt::Return { + value: Expr::Literal(Literal::None), + span, + }); } - // Italic statement *…* + // v0.3: **…** = code segment (assign / call / expr) + if trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4 { + let inner = &trimmed[2..trimmed.len() - 2]; + return self.stmt_from_bold_inner(inner, span); + } + + // v0.3: *…* = return if trimmed.starts_with('*') && trimmed.ends_with('*') && !trimmed.starts_with("**") { let inner = &trimmed[1..trimmed.len() - 1]; - return self.parse_italic_assign(inner, span); + return stmt_from_italic_return(inner, span); } // Call > @@ -282,19 +351,90 @@ impl<'a> Cursor<'a> { return Ok(Stmt::Call { call, span }); } - // Bare assign `` `x` = … `` possibly followed by formula fence or table + // Bare assign `` `x` = … `` if trimmed.starts_with('`') { if let Some(stmt) = self.parse_backtick_assign(trimmed, span.clone())? { return Ok(stmt); } } + // Mid-line prose on a Code-classified line: scan inlines + let bits = scan_prose_line(line.text.trim_end_matches(['\r', '\n'])); + if bits.iter().any(|b| { + matches!( + b, + ProseBit::BoldCode { .. } | ProseBit::ItalicReturn { .. } + ) + }) { + // Expand to multiple stmts — caller only expects one; push extras via... + // For whole-line Code that's actually "先写**…**再写**…**", classify is Comment + // and handled in prose path. If we get here, emit first executable bit only + // and require callers to use prose path for multi — but multi-bold is Comment. + let mut stmts = Vec::new(); + for bit in bits { + match bit { + ProseBit::BoldCode { inner, .. } => { + stmts.push(self.stmt_from_bold_inner(&inner, span.clone())?); + } + ProseBit::ItalicReturn { inner, .. } => { + stmts.push(stmt_from_italic_return(&inner, span.clone())?); + } + ProseBit::Decl { .. } => {} + } + } + if stmts.len() == 1 { + return Ok(stmts.pop().unwrap()); + } + if stmts.len() > 1 { + // Represent as a synthetic block: execute by chaining — use first and + // stash is awkward. Prefer: return error asking for prose classification. + // Simpler: fold into a Branch with one arm? No. + // Use Stmt::Call sequence — add by making parse_function handle this. + bail!("{span}: multiple inline code segments on one code line; use narrative line"); + } + } + Err(Diagnostic::new(None, span, format!("unrecognized statement: {trimmed}")).into()) } + /// Parse bold-code inner into Assign / Call. + fn stmt_from_bold_inner(&mut self, inner: &str, span: Span) -> Result { + let inner = inner.trim(); + if inner.is_empty() { + return Ok(Stmt::Return { + value: Expr::Literal(Literal::None), + span, + }); + } + if let Some((name, rhs)) = split_assign_inner(inner) { + if crate::aliases::is_reserved_keyword(&name) { + bail!("{span}: `{name}` is a reserved keyword"); + } + let (value, end_line) = self.resolve_assign_rhs(&rhs, span, true)?; + return Ok(Stmt::Assign { + name, + value, + span, + end_line, + }); + } + // Call without `>`: `print text="hi"` / `加一函数 37` + let multi = inner.split_whitespace().count() >= 2 || inner.contains('='); + if multi { + let call = parse_call_tail(inner, true) + .map(|(c, _)| c) + .map_err(|e| anyhow::anyhow!("{span}: bold code: {e}"))?; + return Ok(Stmt::Call { call, span }); + } + // Single token: treat as expression discarded via assign to `_`? Prefer error. + bail!("{span}: bold code must be assignment or call (got `{inner}`)"); + } + + #[allow(dead_code)] fn parse_italic_assign(&mut self, inner: &str, span: Span) -> Result { + // Kept for unit tests migrating; v0.3 uses bold for assign. let Some((name, rhs)) = split_assign_inner(inner) else { - bail!("{span}: italic statement must be an assignment (name = …)"); + bail!("{span}: assignment must be name = …"); }; if crate::aliases::is_reserved_keyword(&name) { bail!("{span}: `{name}` is a reserved keyword"); @@ -370,6 +510,21 @@ impl<'a> Cursor<'a> { span.line, )); } + // v0.3 prefer_var RHS: expression first (`p + qn`), else bare call (`加一 37`). + if prefer_var { + if let Ok(e) = parse_expr_prefer_var(rhs) { + return Ok((e, span.line)); + } + let multi = rhs.split_whitespace().count() >= 2 || rhs.contains('='); + if multi { + if let Ok((call, consumed)) = parse_call_tail(rhs, true) { + let rest = rhs.get(consumed..).unwrap_or("").trim(); + if rest.is_empty() { + return Ok((Expr::Call(call), span.line)); + } + } + } + } let value = if prefer_var { parse_expr_prefer_var(rhs)? } else { @@ -802,7 +957,11 @@ fn parse_param_line(trimmed: &str) -> Option { } else { return None; }; - Some(Param { name, default }) + Some(Param { + name, + default, + inferred: false, + }) } fn parse_foreach_ident(s: &str) -> Option { @@ -1034,13 +1193,21 @@ fn is_frame(trimmed: &str) -> bool { if trimmed.len() < 3 { return false; } - // Empty bold return `****` is handled separately; frames are --- or *** (etc.). - if is_empty_bold_return(trimmed) { + // Empty returns `**` / `****` are not frames. + if is_empty_return_marker(trimmed) { return false; } trimmed.chars().all(|c| c == '-') || trimmed.chars().all(|c| c == '*') } +/// `****` or `**` + whitespace only + `**`, or whole-line `**` (v0.3 empty italic). +fn is_empty_return_marker(trimmed: &str) -> bool { + if trimmed == "**" { + return true; + } + is_empty_bold_return(trimmed) +} + /// `****` or `**` + whitespace only + `**`. fn is_empty_bold_return(trimmed: &str) -> bool { if !(trimmed.starts_with("**") && trimmed.ends_with("**") && trimmed.len() >= 4) { @@ -1049,6 +1216,148 @@ fn is_empty_bold_return(trimmed: &str) -> bool { trimmed[2..trimmed.len() - 2].trim().is_empty() } +fn stmt_from_italic_return(inner: &str, span: Span) -> Result { + let inner = inner.trim(); + let value = if inner.is_empty() + || inner == "None" + || inner == "无" + || inner == "空" + { + Expr::Literal(Literal::None) + } else { + parse_expr_prefer_var(inner)? + }; + Ok(Stmt::Return { value, span }) +} + +/// Merge prose decls into params: promote names that are read in the body (or have defaults). +fn merge_inferred_params( + fun: &mut Function, + prose_decls: &[(String, Option)], +) -> Result<()> { + use std::collections::HashSet; + + let mut read_names = HashSet::new(); + let mut assigned_names = HashSet::new(); + collect_reads_assigns(&fun.body, &mut read_names, &mut assigned_names); + + for (name, default_txt) in prose_decls { + if name == "self" || name == "自" { + continue; + } + if fun.params.iter().any(|p| &p.name == name) { + continue; + } + let has_default = default_txt.is_some(); + let is_read = read_names.contains(name); + // Elevate: defaulted always; or read in executable body (required input). + if !has_default && !is_read { + continue; // dead bind + } + let default = if let Some(txt) = default_txt { + Some(parse_expr_prefer_var(txt).or_else(|_| parse_value_or_interp(txt))?) + } else { + None + }; + fun.params.push(Param { + name: name.clone(), + default, + inferred: true, + }); + } + Ok(()) +} + +fn collect_reads_assigns( + stmts: &[Stmt], + reads: &mut std::collections::HashSet, + assigns: &mut std::collections::HashSet, +) { + for s in stmts { + match s { + Stmt::Assign { name, value, .. } => { + assigns.insert(name.clone()); + collect_reads_expr(value, reads); + } + Stmt::Return { value, .. } => collect_reads_expr(value, reads), + Stmt::Call { call, .. } => collect_reads_call(call, reads), + Stmt::Branch { arms, .. } => { + for a in arms { + if let Some(c) = &a.condition { + collect_reads_expr(c, reads); + } + collect_reads_assigns(&a.body, reads, assigns); + } + } + Stmt::While { + condition, body, .. + } => { + collect_reads_expr(condition, reads); + collect_reads_assigns(body, reads, assigns); + } + Stmt::ForEach { + collection, body, .. + } => { + reads.insert(collection.clone()); + collect_reads_assigns(body, reads, assigns); + } + } + } +} + +fn collect_reads_call(call: &crate::ast::CallExpr, reads: &mut std::collections::HashSet) { + if let Some(recv) = &call.receiver { + reads.insert(recv.clone()); + } + // Callee name itself is not a variable read. + for a in &call.args { + match a { + crate::ast::Arg::Positional(e) | crate::ast::Arg::Named { value: e, .. } => { + collect_reads_expr(e, reads); + } + } + } +} + +fn collect_reads_expr(expr: &Expr, reads: &mut std::collections::HashSet) { + match expr { + Expr::Var(n) => { + reads.insert(n.clone()); + } + Expr::Call(c) => collect_reads_call(c, reads), + Expr::Binary { left, right, .. } => { + collect_reads_expr(left, reads); + collect_reads_expr(right, reads); + } + Expr::Unary { expr, .. } => collect_reads_expr(expr, reads), + Expr::Index { base, .. } => collect_reads_expr(base, reads), + Expr::List(xs) => { + for x in xs { + collect_reads_expr(x, reads); + } + } + Expr::Map(entries) => { + for (_, v) in entries { + collect_reads_expr(v, reads); + } + } + Expr::Interp(parts) => { + for p in parts { + match p { + crate::ast::InterpPart::Var(n) => { + reads.insert(n.clone()); + } + crate::ast::InterpPart::Index { base, .. } => { + reads.insert(base.clone()); + } + crate::ast::InterpPart::Lit(_) => {} + } + } + } + Expr::Literal(_) | Expr::Formula(_) | Expr::Code(_) => {} + } +} + fn is_ordered_branch(trimmed: &str) -> bool { strip_ordered(trimmed).is_some() } @@ -1242,8 +1551,8 @@ mod tests { } #[test] - fn parse_italic_bare_lhs_prefer_var() { - let src = "# main\n\n*answer = 1*\n**answer**\n"; + fn parse_bold_assign_italic_return() { + let src = "# main\n\n**answer = 1**\n*answer*\n"; let m = parse_source(src).unwrap(); match &m.functions[0].body[0] { Stmt::Assign { name, value, .. } => { @@ -1260,6 +1569,16 @@ mod tests { } } + #[test] + fn parse_prose_inc() { + let src = "## 加一\n\n输入`n`。**n=n+1**返回*n*。\n\n# main\n\n**r = 加一 1**\n**print text=r**\n"; + let m = parse_source(src).unwrap(); + let add = m.functions.iter().find(|f| f.name == "加一").unwrap(); + assert_eq!(add.params.len(), 1); + assert_eq!(add.params[0].name, "n"); + assert!(add.params[0].inferred); + } + #[test] fn parse_branch_rejects_plus_arm() { let src = "# main\n\n+ `x` > 0\n > print text=ok\n"; diff --git a/src/parse/prose.rs b/src/parse/prose.rs new file mode 100644 index 0000000..fa70958 --- /dev/null +++ b/src/parse/prose.rs @@ -0,0 +1,150 @@ +//! Inline prose scan for Markup v0.3 (叙述中的 `` `名` `` / `**代码**` / `*返回*`). + +use crate::lex::{matching_bold_close_inline, matching_italic_close_inline}; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ProseBit { + /// `` `ident` `` or `` `ident`=default `` (default string is raw RHS text). + Decl { + name: String, + default: Option, + /// Byte offset in the line (for diagnostics). + at: usize, + }, + /// Inner text of `**…**` (code segment). + BoldCode { inner: String, at: usize }, + /// Inner text of `*…*` (return), when not starting a bold. + ItalicReturn { inner: String, at: usize }, +} + +/// Scan a narrative (or mixed) line for v0.3 inline bits, left to right. +pub fn scan_prose_line(line: &str) -> Vec { + let bytes = line.as_bytes(); + let mut i = 0usize; + let mut out = Vec::new(); + while i < bytes.len() { + let c = bytes[i]; + if c == b'`' { + if let Some((bit, next)) = scan_backtick_decl(line, i) { + out.push(bit); + i = next; + continue; + } + i += 1; + continue; + } + if c == b'*' && i + 1 < bytes.len() && bytes[i + 1] == b'*' { + let rest = &line[i..]; + if let Some(close_rel) = matching_bold_close_inline(rest) { + // close_rel is index within `rest` of first `*` of closing `**` + let inner = rest[2..close_rel].to_string(); + out.push(ProseBit::BoldCode { + inner, + at: i, + }); + i += close_rel + 2; + continue; + } + i += 1; + continue; + } + if c == b'*' { + let rest = &line[i..]; + if rest.starts_with("**") { + i += 1; + continue; + } + if let Some(close_rel) = matching_italic_close_inline(rest) { + let inner = rest[1..close_rel].to_string(); + out.push(ProseBit::ItalicReturn { + inner, + at: i, + }); + i += close_rel + 1; + continue; + } + } + i += 1; + } + out +} + +fn scan_backtick_decl(line: &str, start: usize) -> Option<(ProseBit, usize)> { + let rest = &line[start + 1..]; + let end = rest.find('`')?; + let name = rest[..end].to_string(); + if name.is_empty() || name.chars().any(|c| c.is_whitespace()) { + return None; + } + let after_tick = start + 1 + end + 1; + let after = line.get(after_tick..)?; + // `` `名`=默认 `` — optional default glued after closing tick + if let Some(stripped) = after.strip_prefix('=') { + // default runs until whitespace or CJK punctuation-ish break for prose + let def_end = stripped + .find(|c: char| { + c.is_whitespace() + || matches!(c, ',' | '。' | ';' | '、' | ',' | ';' | '*' | '`') + }) + .unwrap_or(stripped.len()); + let default = stripped[..def_end].to_string(); + let next = after_tick + 1 + def_end; + return Some(( + ProseBit::Decl { + name, + default: Some(default), + at: start, + }, + next, + )); + } + Some(( + ProseBit::Decl { + name, + default: None, + at: start, + }, + after_tick, + )) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn scan_inc_prose_line() { + let line = "对于输入变量`n`,我们执行操作**n=n+1**接着返回*n*。"; + let bits = scan_prose_line(line); + assert_eq!(bits.len(), 3); + match &bits[0] { + ProseBit::Decl { name, default, .. } => { + assert_eq!(name, "n"); + assert!(default.is_none()); + } + _ => panic!("{:?}", bits[0]), + } + match &bits[1] { + ProseBit::BoldCode { inner, .. } => assert_eq!(inner, "n=n+1"), + _ => panic!("{:?}", bits[1]), + } + match &bits[2] { + ProseBit::ItalicReturn { inner, .. } => assert_eq!(inner, "n"), + _ => panic!("{:?}", bits[2]), + } + } + + #[test] + fn scan_default_decl() { + let line = "默认`礼貌`=False。"; + let bits = scan_prose_line(line); + assert_eq!(bits.len(), 1); + match &bits[0] { + ProseBit::Decl { name, default, .. } => { + assert_eq!(name, "礼貌"); + assert_eq!(default.as_deref(), Some("False")); + } + _ => panic!("{:?}", bits[0]), + } + } +} diff --git a/tests/README.md b/tests/README.md index f629c04..65600df 100644 --- a/tests/README.md +++ b/tests/README.md @@ -6,6 +6,7 @@ |------|------| | [`structure/`](structure/) | 函数、调用、分支、循环、表、导入、位置实参 | | [`keywords/`](keywords/) | `print`、布尔与 `and`/`or`/`not` | +| [`markup-v03/`](markup-v03/) | **Markup v0.3 草案金样例**(`#[ignore]` 至旗标落地;见目录 README) | | [`errors/`](errors/) | 期望失败(诊断文案) | | [`gold.rs`](gold.rs) | 集成测试:跑上述夹具并比对 stdout / stderr | diff --git a/tests/gold.rs b/tests/gold.rs index fe9d866..f957c1b 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -3708,3 +3708,69 @@ fn tempfile_dir(prefix: &str) -> std::path::PathBuf { std::fs::create_dir_all(&dir).unwrap(); dir } + +// --------------------------------------------------------------------------- +// Markup mapping v0.3 — fixtures under tests/markup-v03/ +// --------------------------------------------------------------------------- + +fn assert_out_v03(path: &str, expect: &str) { + assert_out(path, expect); +} + +#[test] +fn markup_v03_inc_prose() { + assert_out_v03("tests/markup-v03/inc-prose.mq.md", "38"); +} + +#[test] +fn markup_v03_bold_call() { + assert_out_v03("tests/markup-v03/bold-call.mq.md", "38"); +} + +#[test] +fn markup_v03_dual_call() { + assert_out_v03("tests/markup-v03/dual-call.mq.md", "38\n38"); +} + +#[test] +fn markup_v03_greet_default() { + assert_out_v03( + "tests/markup-v03/greet-default.mq.md", + "您好,\nMarqdo\n嗨,\nWorld", + ); +} + +#[test] +fn markup_v03_dead_bind() { + assert_out_v03("tests/markup-v03/dead-bind.mq.md", "你好"); +} + +#[test] +fn markup_v03_empty_return_hr() { + assert_out_v03("tests/markup-v03/empty-return-hr.mq.md", "hi\ndone"); +} + +#[test] +fn markup_v03_empty_return_none() { + assert_out_v03("tests/markup-v03/empty-return-none.mq.md", "hi\ndone"); +} + +#[test] +fn markup_v03_empty_return_stars() { + assert_out_v03("tests/markup-v03/empty-return-stars.mq.md", "hi\ndone"); +} + +#[test] +fn markup_v03_empty_return_compat() { + assert_out_v03("tests/markup-v03/empty-return-compat.mq.md", "hi\ndone"); +} + +#[test] +fn markup_v03_multi_bold() { + assert_out_v03("tests/markup-v03/multi-bold.mq.md", "a\nb"); +} + +#[test] +fn markup_v03_print_bold() { + assert_out_v03("tests/markup-v03/print-bold.mq.md", "Hello"); +} diff --git a/tests/keywords/bool-logic.mq.md b/tests/keywords/bool-logic.mq.md index a23146d..87d509d 100644 --- a/tests/keywords/bool-logic.mq.md +++ b/tests/keywords/bool-logic.mq.md @@ -4,15 +4,15 @@ title: 布尔与逻辑关键字 # main -*a = True* -*b = False* +**a = True** +**b = False** 1. `a` and not `b` > print text=ok 2. * > print text=fail -*probe = 1* +**probe = 1** 1. None > print text=none-truthy diff --git a/tests/keywords/input-escape.mq.md b/tests/keywords/input-escape.mq.md index 1276b79..ecea27c 100644 --- a/tests/keywords/input-escape.mq.md +++ b/tests/keywords/input-escape.mq.md @@ -5,6 +5,6 @@ stdin: Ada # main -*name = > input prompt="Name:\n"* +**name = > input prompt="Name:\n"** > print text=Hello `name`! diff --git a/tests/keywords/input.mq.md b/tests/keywords/input.mq.md index 8af5770..e64fcc4 100644 --- a/tests/keywords/input.mq.md +++ b/tests/keywords/input.mq.md @@ -5,6 +5,6 @@ description: Read one stdin line (optional prompt) # main -*name = > input prompt="Name:"* +**name = > input prompt="Name:"** > print text=Hello `name`! diff --git a/tests/keywords/quoted-string.mq.md b/tests/keywords/quoted-string.mq.md index 94afbf8..a018e66 100644 --- a/tests/keywords/quoted-string.mq.md +++ b/tests/keywords/quoted-string.mq.md @@ -4,17 +4,17 @@ title: quoted string literal # main -*s = "a\nb"* +**s = "a\nb"** > print text=`s` -*s2 = "hex \x22 quote\x27 single"* +**s2 = "hex \x22 quote\x27 single"** > print text=`s2` -*s3 = "\u{4e2d}\u{6587}"* +**s3 = "\u{4e2d}\u{6587}"** > print text=`s3` -*s4 = "keep \q verbatim"* +**s4 = "keep \q verbatim"** > print text=`s4` -*s5 = "\x41\x42\x43"* +**s5 = "\x41\x42\x43"** > print text=`s5` \ No newline at end of file diff --git a/tests/keywords/stdlib-more.mq.md b/tests/keywords/stdlib-more.mq.md index 431444b..8208d67 100644 --- a/tests/keywords/stdlib-more.mq.md +++ b/tests/keywords/stdlib-more.mq.md @@ -5,26 +5,26 @@ description: trim split join at type + lib imports # main -*raw = " hi "* +**raw = " hi "** -*t = > trim `raw`* +**t = > trim `raw`** > print text=`t` -*parts = > split value=a,b,c sep=,* +**parts = > split value=a,b,c sep=,** -*n = > len `parts`* +**n = > len `parts`** > print text=`n` -*mid = > at value=`parts` index=1* +**mid = > at value=`parts` index=1** > print text=`mid` -*joined = > join value=`parts` sep=-* +**joined = > join value=`parts` sep=-** > print text=`joined` -*ty = > type `parts`* +**ty = > type `parts`** > print text=`ty` diff --git a/tests/keywords/stdlib.mq.md b/tests/keywords/stdlib.mq.md index bcc1571..fb4af8f 100644 --- a/tests/keywords/stdlib.mq.md +++ b/tests/keywords/stdlib.mq.md @@ -5,9 +5,9 @@ description: Built-in conversions and length # main -*s = "hello"* +**s = "hello"** -*n = > len `s`* +**n = > len `s`** > print text=`n` @@ -19,18 +19,18 @@ description: Built-in conversions and length | b | | c | -*m = > len `xs`* +**m = > len `xs`** > print text=`m` -*t = > str 42* +**t = > str 42** > print text=`t` -*i = > int `t`* +**i = > int `t`** > print text=`i` -*j = > int True* +**j = > int True** > print text=`j` diff --git a/tests/keywords/zh-bool.mq.md b/tests/keywords/zh-bool.mq.md index a02db2a..ea8c0fe 100644 --- a/tests/keywords/zh-bool.mq.md +++ b/tests/keywords/zh-bool.mq.md @@ -4,15 +4,15 @@ title: 中文布尔与逻辑 # main -*a = 真* -*b = 假* +**a = 真** +**b = 假** 1. `a` 且 非 `b` > 打印 内容=ok 2. * > 打印 内容=fail -*probe = 1* +**probe = 1** 1. 空 > 打印 内容=none-truthy diff --git a/tests/keywords/zh-builtins.mq.md b/tests/keywords/zh-builtins.mq.md index 9aaef63..0947a67 100644 --- a/tests/keywords/zh-builtins.mq.md +++ b/tests/keywords/zh-builtins.mq.md @@ -5,14 +5,14 @@ description: 打印 / 长度 / 文本 / 整数(与英文别名等价) # main -*s = "hello"* +**s = "hello"** -*n = > 长度 值=`s`* +**n = > 长度 值=`s`** > 打印 内容=`n` -*t = > 文本 值=7* +**t = > 文本 值=7** -*i = > 整数 值=`t`* +**i = > 整数 值=`t`** > 打印 内容=`i` diff --git a/tests/markup-v03/README.md b/tests/markup-v03/README.md new file mode 100644 index 0000000..b0087e2 --- /dev/null +++ b/tests/markup-v03/README.md @@ -0,0 +1,21 @@ +# Markup v0.3 金样例 + +| | | +|---|---| +| 设计 | [markdown-mapping-v0.3.md](../../doc/design/markdown-mapping-v0.3.md) | +| 路线 | [markup-v0.3.md](../../doc/roadmap/markup-v0.3.md) | +| 状态 | **现行运行时(无 `--markup` 旗标 · 无 v0.2 兼容)** | + +## 约定 + +- 文件使用 **v0.3 表面语法**(粗体代码、斜体返回、叙述 `` `名` `` 声明、形参体推断)。 +- `tests/gold.rs` 中 `markup_v03_*` 为门禁。 + +## 清单 + +见各 `.mq.md` frontmatter;汇总期望以 `gold.rs` 为准。 + +```bash +cargo test --test gold markup_v03 +marqdo run tests/markup-v03/inc-prose.mq.md +``` diff --git a/tests/markup-v03/bold-call.mq.md b/tests/markup-v03/bold-call.mq.md new file mode 100644 index 0000000..67dac6e --- /dev/null +++ b/tests/markup-v03/bold-call.mq.md @@ -0,0 +1,16 @@ +--- +title: v0.3 粗体内调用(无 `>`) +description: `**结果 = 加一函数 37**` 粗体调用(callee 无 `>`) +markup: v0.3 +--- + +## 加一函数 + +输入`n`。**n=n+1**返回*n*。 + +# main + +或者可以直接用粗体调用(不必写 `>`): + +**结果 = 加一函数 37** +**print text=结果** diff --git a/tests/markup-v03/dead-bind.mq.md b/tests/markup-v03/dead-bind.mq.md new file mode 100644 index 0000000..78e3ea5 --- /dev/null +++ b/tests/markup-v03/dead-bind.mq.md @@ -0,0 +1,16 @@ +--- +title: v0.3 死绑定不升参 +description: 叙述提到`Markdown`/`GFM`但不读写;仅`题干`为形参 +markup: v0.3 +--- + +## 回声 + +本文顺便提到`Markdown`与`GFM`,但真正的输入只有`题干`。 + +**print text=题干** +--- + +# main + +> 回声 你好 diff --git a/tests/markup-v03/dual-call.mq.md b/tests/markup-v03/dual-call.mq.md new file mode 100644 index 0000000..d824739 --- /dev/null +++ b/tests/markup-v03/dual-call.mq.md @@ -0,0 +1,16 @@ +--- +title: v0.3 双调用面 +description: 同函数一次 `>`、一次粗体调用 +markup: v0.3 +--- + +## 加一函数 + +输入`n`。**n=n+1**返回*n*。 + +# main + +**a = > 加一函数 37** +**print text=a** +**b = 加一函数 37** +**print text=b** diff --git a/tests/markup-v03/empty-return-compat.mq.md b/tests/markup-v03/empty-return-compat.mq.md new file mode 100644 index 0000000..8d1b68a --- /dev/null +++ b/tests/markup-v03/empty-return-compat.mq.md @@ -0,0 +1,15 @@ +--- +title: v0.3 空返回(`****` 兼容) +description: v0.2 空粗体在 v0.3 仍识别为空返回 +markup: v0.3 +--- + +## 只打印 + +**print text="hi"** +**** + +# main + +> 只打印 +> print text=done diff --git a/tests/markup-v03/empty-return-hr.mq.md b/tests/markup-v03/empty-return-hr.mq.md new file mode 100644 index 0000000..d4e0834 --- /dev/null +++ b/tests/markup-v03/empty-return-hr.mq.md @@ -0,0 +1,15 @@ +--- +title: v0.3 空返回(`---`) +description: 副作用后分割线收束 +markup: v0.3 +--- + +## 只打印 + +**print text="hi"** +--- + +# main + +> 只打印 +> print text=done diff --git a/tests/markup-v03/empty-return-none.mq.md b/tests/markup-v03/empty-return-none.mq.md new file mode 100644 index 0000000..45f6442 --- /dev/null +++ b/tests/markup-v03/empty-return-none.mq.md @@ -0,0 +1,15 @@ +--- +title: v0.3 空返回(`*None*`) +description: 显式空值,对齐 Python return None +markup: v0.3 +--- + +## 只打印 + +**print text="hi"** +*None* + +# main + +> 只打印 +> print text=done diff --git a/tests/markup-v03/empty-return-stars.mq.md b/tests/markup-v03/empty-return-stars.mq.md new file mode 100644 index 0000000..bb60893 --- /dev/null +++ b/tests/markup-v03/empty-return-stars.mq.md @@ -0,0 +1,15 @@ +--- +title: v0.3 空返回(整行 `**`) +description: 空斜体标记;词法须与粗体区分 +markup: v0.3 +--- + +## 只打印 + +**print text="hi"** +** + +# main + +> 只打印 +> print text=done diff --git a/tests/markup-v03/greet-default.mq.md b/tests/markup-v03/greet-default.mq.md new file mode 100644 index 0000000..79398e5 --- /dev/null +++ b/tests/markup-v03/greet-default.mq.md @@ -0,0 +1,23 @@ +--- +title: v0.3 默认形参(叙述 `` `名`=值 ``) +description: 必选`谁` + 可选`礼貌`=False;分支打印 +markup: v0.3 +--- + +## 问候 + +向`谁`问好;默认`礼貌`=False。 + +1. `礼貌` + **print text="您好,"** + **print text=谁** +2. * + **print text="嗨,"** + **print text=谁** + +--- + +# main + +**问候 谁="Marqdo" 礼貌=True** +> 问候 World diff --git a/tests/markup-v03/inc-prose.mq.md b/tests/markup-v03/inc-prose.mq.md new file mode 100644 index 0000000..1234684 --- /dev/null +++ b/tests/markup-v03/inc-prose.mq.md @@ -0,0 +1,16 @@ +--- +title: v0.3 加一(叙述统一动机例) +description: 叙述声明 `n`;粗体赋值;斜体返回;`>` 调用后打印返回值 +markup: v0.3 +--- + +## 加一函数 + +对于输入变量`n`,我们执行操作**n=n+1**接着返回*n*。 + +# main + +我要调用加一函数可以采用这样的办法: + +**结果 = > 加一函数 37** +**print text=结果** diff --git a/tests/markup-v03/multi-bold.mq.md b/tests/markup-v03/multi-bold.mq.md new file mode 100644 index 0000000..a058d70 --- /dev/null +++ b/tests/markup-v03/multi-bold.mq.md @@ -0,0 +1,9 @@ +--- +title: v0.3 一行多粗体 +description: 同一叙述行内多个 `**…**` 按出现序执行 +markup: v0.3 +--- + +# main + +先写**print text="a"**再写**print text="b"**。 diff --git a/tests/markup-v03/print-bold.mq.md b/tests/markup-v03/print-bold.mq.md new file mode 100644 index 0000000..b99e46b --- /dev/null +++ b/tests/markup-v03/print-bold.mq.md @@ -0,0 +1,9 @@ +--- +title: v0.3 粗体内 print +description: 输出是调用不是返回;粗体包裹 print +markup: v0.3 +--- + +# main + +**print text="Hello"** diff --git a/tests/structure/bare-id-italic-bold.mq.md b/tests/structure/bare-id-italic-bold.mq.md index c7cbc4b..d1fb510 100644 --- a/tests/structure/bare-id-italic-bold.mq.md +++ b/tests/structure/bare-id-italic-bold.mq.md @@ -1,37 +1,37 @@ --- title: bare id in italic and bold -description: Inside *…* / **…**, bare ids are variables; strings need quotes. +description: Inside **…** / *…*, bare ids are variables; strings need quotes. --- # main -*answer = 1* -*n = answer + 1* -*ticked = 2* -*s = 'quoted'* +**answer = 1** +**n = answer + 1** +**ticked = 2** +**s = 'quoted'** > print text=`n` > print text=`ticked` > print text=`s` -*a = > ret_var x=7* +**a = > ret_var x=7** > print text=`a` -*b = > ret_str* +**b = > ret_str** > print text=`b` -*c = > ret_single* +**c = > ret_single** > print text=`c` ## ret_var + `x` -**x** +*x* ## ret_str -**"ok"** +*"ok"* ## ret_single -**'hi'** +*'hi'* diff --git a/tests/structure/branch-consecutive.mq.md b/tests/structure/branch-consecutive.mq.md index 4f58de3..dfe22f4 100644 --- a/tests/structure/branch-consecutive.mq.md +++ b/tests/structure/branch-consecutive.mq.md @@ -5,8 +5,8 @@ description: Same-indent `1.` after a completed list is a new Branch, not more a # main -*a = True* -*b = True* +**a = True** +**b = True** 1. `a` > print text=A diff --git a/tests/structure/branch.mq.md b/tests/structure/branch.mq.md index 2e1e022..fb4ce2a 100644 --- a/tests/structure/branch.mq.md +++ b/tests/structure/branch.mq.md @@ -4,7 +4,7 @@ title: 分支示例 # main -*x = 0* +**x = 0** 1. `x` > 0 > print text=正数 diff --git a/tests/structure/collection-cell-expr.mq.md b/tests/structure/collection-cell-expr.mq.md index 997da98..2b07c72 100644 --- a/tests/structure/collection-cell-expr.mq.md +++ b/tests/structure/collection-cell-expr.mq.md @@ -5,8 +5,8 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros # main -*secret = "sk-live"* -*name = "gpt-4o-mini"* +**secret = "sk-live"** +**name = "gpt-4o-mini"** `cfg` = diff --git a/tests/structure/collection-map-list.mq.md b/tests/structure/collection-map-list.mq.md index 54e635e..b1cffda 100644 --- a/tests/structure/collection-map-list.mq.md +++ b/tests/structure/collection-map-list.mq.md @@ -11,14 +11,14 @@ title: 横表多行 → 字典套列表 | 红富士 | 青瓜 | | 嘎啦 | 黄瓜条 | -*第一种苹果 = 货架[^苹果][^1]* +**第一种苹果 = 货架[^苹果][^1]** > print text=`第一种苹果` -*列 = 货架[^苹果]* +**列 = 货架[^苹果]** > print text=`列` -*第二种黄瓜 = 货架[^黄瓜][^2]* +**第二种黄瓜 = 货架[^黄瓜][^2]** > print text=`第二种黄瓜` diff --git a/tests/structure/collection-map.mq.md b/tests/structure/collection-map.mq.md index 1fd5b3c..d59fcd2 100644 --- a/tests/structure/collection-map.mq.md +++ b/tests/structure/collection-map.mq.md @@ -10,15 +10,15 @@ title: 横表单行 → 字典 |------|------|------| | 水果 | 蔬菜 | 数码用品 | -*种 = 分类[^苹果]* +**种 = 分类[^苹果]** > print text=`种` -*种 = 分类[^黄瓜]* +**种 = 分类[^黄瓜]** > print text=`种` -*种 = 分类[^鼠标]* +**种 = 分类[^鼠标]** > print text=`种` diff --git a/tests/structure/collection-records-at.mq.md b/tests/structure/collection-records-at.mq.md index afaa703..f917dc8 100644 --- a/tests/structure/collection-records-at.mq.md +++ b/tests/structure/collection-records-at.mq.md @@ -11,10 +11,10 @@ title: row records with @ marker | 1 | apple | 2 | | 2 | pear | 3 | -*n = orders[^1][^name]* +**n = orders[^1][^name]** > print text=`n` -*q = orders[^2][^qty]* +**q = orders[^2][^qty]** > print text=`q` diff --git a/tests/structure/collection-records.mq.md b/tests/structure/collection-records.mq.md index f130a0d..3ae8c83 100644 --- a/tests/structure/collection-records.mq.md +++ b/tests/structure/collection-records.mq.md @@ -11,15 +11,15 @@ title: 行向记录表(首列 行 / @) | 1 | 苹果 | 2 | | 2 | 梨 | 3 | -*第一 = 订单[^1]* +**第一 = 订单[^1]** > print text=`第一` -*名 = 订单[^1][^品名]* +**名 = 订单[^1][^品名]** > print text=`名` -*量 = 订单[^2][^数量]* +**量 = 订单[^2][^数量]** > print text=`量` diff --git a/tests/structure/footnote-index.mq.md b/tests/structure/footnote-index.mq.md index 0163c54..04d2383 100644 --- a/tests/structure/footnote-index.mq.md +++ b/tests/structure/footnote-index.mq.md @@ -12,14 +12,14 @@ title: 脚注取元(列表下标) | 梨 | | 桃 | -*第一 = 篮子[^1]* +**第一 = 篮子[^1]** > print text=`第一` -*第二 = 篮子[^2]* +**第二 = 篮子[^2]** > print text=`第二` -*第三 = 篮子[^3]* +**第三 = 篮子[^3]** > print text=`第三` diff --git a/tests/structure/footnote-map-digits.mq.md b/tests/structure/footnote-map-digits.mq.md index abb4d32..e081137 100644 --- a/tests/structure/footnote-map-digits.mq.md +++ b/tests/structure/footnote-map-digits.mq.md @@ -11,8 +11,8 @@ description: Pure-digit labels are map keys (text), not list indices. Bare base |----|----| | half | other | -*a = p[^00]* -*b = p[^11]* +**a = p[^00]** +**b = p[^11]** > print text=`a` > print text=`b` diff --git a/tests/structure/gap-star-json-body.mq.md b/tests/structure/gap-star-json-body.mq.md index 239ec63..798bb2c 100644 --- a/tests/structure/gap-star-json-body.mq.md +++ b/tests/structure/gap-star-json-body.mq.md @@ -6,9 +6,9 @@ import json:lib/json.mq.md # main -*a = > case_backtick* -*b = > case_json_array* -*c = > case_recover* +**a = > case_backtick** +**b = > case_json_array** +**c = > case_recover** > print text=`a` > print text=`b` > print text=`c` @@ -21,20 +21,20 @@ import json:lib/json.mq.md |---| | ok | -*code = > len value=`args`* -*y = 1* -**y** +**code = > len value=`args`** +**y = 1** +*y* ## case_json_array -*xs = > json.parse text=["scripts/legacy/web_search.py"]* -*n = > len value=`xs`* -**n** +**xs = > json.parse text=["scripts/legacy/web_search.py"]** +**n = > len value=`xs`** +*n* ## case_recover -故意少写闭合星号,后续语句仍须可执行: +故意少写闭合粗体,后续语句仍须可执行: -*c = > json.parse text=[]` -*z = 7* -**z** +**c = > json.parse text=[] +**z = 7** +*z* diff --git a/tests/structure/hello.mq.md b/tests/structure/hello.mq.md index 6760fa1..8dd4505 100644 --- a/tests/structure/hello.mq.md +++ b/tests/structure/hello.mq.md @@ -1,5 +1,5 @@ # Hello World -本程序调用内置函数 `print` 打印问候。注释里的 **粗体** 与 *斜体* 都不执行。 +本程序调用内置函数 print 打印问候。叙述中不要用星号当强调(粗体/斜体已是可执行标记)。 > print text=Hello World! diff --git a/tests/structure/import-lib.mq.md b/tests/structure/import-lib.mq.md index 871d56f..f933301 100644 --- a/tests/structure/import-lib.mq.md +++ b/tests/structure/import-lib.mq.md @@ -6,7 +6,7 @@ title: import official lib (Chinese) # main -*t = > 文本.去空白 s=" x"* +**t = > 文本.去空白 s=" x"** > 打印 内容=`t` @@ -17,10 +17,10 @@ title: import official lib (Chinese) | a | | b | -*n = > 表.行数 xs=`xs`* +**n = > 表.行数 xs=`xs`** > 打印 内容=`n` -*row = > 表.取行 xs=`xs` i=0* +**row = > 表.取行 xs=`xs` i=0** > 打印 内容=`row` diff --git a/tests/structure/import/main.mq.md b/tests/structure/import/main.mq.md index 1acf95a..d8b92db 100644 --- a/tests/structure/import/main.mq.md +++ b/tests/structure/import/main.mq.md @@ -7,7 +7,7 @@ import utils:utils.mq.md 导入 `utils.mq.md` 后:用返回值绑定,再输出;并直接调用问候。 -*y = > utils.加一 n=41* +**y = > utils.加一 n=41** > print text=`y` diff --git a/tests/structure/import/utils.mq.md b/tests/structure/import/utils.mq.md index 05df8bf..622551d 100644 --- a/tests/structure/import/utils.mq.md +++ b/tests/structure/import/utils.mq.md @@ -6,7 +6,7 @@ description: 供 frontmatter > 导入;返回用粗体;副作用用输出函 ## 加一 + `n` -**n + 1** +*n + 1* ## 问候 + `谁` diff --git a/tests/structure/inherit-explicit-super.mq.md b/tests/structure/inherit-explicit-super.mq.md index 80a3cb2..8270fc2 100644 --- a/tests/structure/inherit-explicit-super.mq.md +++ b/tests/structure/inherit-explicit-super.mq.md @@ -6,23 +6,23 @@ import json:lib/json.mq.md # Parent + `name` -*out = > json.parse text={"role":"parent"}* -*out = > json.set map=`out` key="name" value=`name`* -**out** +**out = > json.parse text={"role":"parent"}** +**out = > json.set map=`out` key="name" value=`name`** +*out* # Child = > Parent + `name` -*self = > Parent name=`name`* -*self = > json.set map=`self` key="role" value="child"* -**self** +**self = > Parent name=`name`** +**self = > json.set map=`self` key="role" value="child"** +*self* # main -*c = > Child name="Ada"* -*ty = > json.get value=`c` key="_type"* -*role = > json.get value=`c` key="role"* -*name = > json.get value=`c` key="name"* +**c = > Child name="Ada"** +**ty = > json.get value=`c` key="_type"** +**role = > json.get value=`c` key="role"** +**name = > json.get value=`c` key="name"** > print text=`ty` > print text=`role` > print text=`name` diff --git a/tests/structure/inherit-override.mq.md b/tests/structure/inherit-override.mq.md index c333b1b..34447a7 100644 --- a/tests/structure/inherit-override.mq.md +++ b/tests/structure/inherit-override.mq.md @@ -7,22 +7,22 @@ title: inherit method override ## hello + `who` -*msg = "Hello, `who`!"* -**msg** +**msg = "Hello, `who`!"** +*msg* # Loud = > Greeter ## hello + `who` -*msg = "HELLO, `who`!"* -**msg** +**msg = "HELLO, `who`!"** +*msg* # main -*g = > Greeter* -*m = > `g`.hello who="world"* +**g = > Greeter** +**m = > `g`.hello who="world"** > print text=`m` -*l = > Loud* -*m2 = > `l`.hello who="world"* +**l = > Loud** +**m2 = > `l`.hello who="world"** > print text=`m2` diff --git a/tests/structure/inherit-parent-method.mq.md b/tests/structure/inherit-parent-method.mq.md index fa1d578..ede704d 100644 --- a/tests/structure/inherit-parent-method.mq.md +++ b/tests/structure/inherit-parent-method.mq.md @@ -8,15 +8,15 @@ import json:lib/json.mq.md ## hello + `who` -*msg = "Hello, `who`!"* -**msg** +**msg = "Hello, `who`!"** +*msg* # Loud = > Greeter # main -*l = > Loud* -*ty = > json.get value=`l` key="_type"* +**l = > Loud** +**ty = > json.get value=`l` key="_type"** > print text=`ty` -*m = > `l`.hello who="world"* +**m = > `l`.hello who="world"** > print text=`m` diff --git a/tests/structure/loop.mq.md b/tests/structure/loop.mq.md index 97e4579..fe33829 100644 --- a/tests/structure/loop.mq.md +++ b/tests/structure/loop.mq.md @@ -6,11 +6,11 @@ title: 循环示例 倒数: -*n = 3* +**n = 3** - `n` > 0 > print text=`n` - *n = n - 1* + **n = n - 1** 遍历篮子: diff --git a/tests/structure/narrative-bold.mq.md b/tests/structure/narrative-bold.mq.md index 47f7b50..bec1a4f 100644 --- a/tests/structure/narrative-bold.mq.md +++ b/tests/structure/narrative-bold.mq.md @@ -1,12 +1,10 @@ --- -title: narrative bold in comment paragraph -description: **强调** mid-line must stay comment, not return syntax +title: narrative without star emphasis +description: v0.3 — do not use * /** for Markdown emphasis; plain prose stays non-executable --- # main -说明如下 - -**强调信息**是什么什么 +说明如下:强调信息是什么什么(叙述勿写星号强调)。 > print text=ok diff --git a/tests/structure/nested-call.mq.md b/tests/structure/nested-call.mq.md index f446f76..00ef44e 100644 --- a/tests/structure/nested-call.mq.md +++ b/tests/structure/nested-call.mq.md @@ -1,11 +1,11 @@ --- title: Hello World -description: Recommended entry — nested fn; print builtin; bold return +description: Nested fn; print builtin; v0.3 italic = return (unused here) --- # main -打印一句问候。`print` 是函数,不是语法架构;粗体只用于返回值。 +打印一句问候。print 是函数,不是语法架构。 > 问候 谁=World diff --git a/tests/structure/ns/helpers.mq.md b/tests/structure/ns/helpers.mq.md index 31c6e5f..2778670 100644 --- a/tests/structure/ns/helpers.mq.md +++ b/tests/structure/ns/helpers.mq.md @@ -9,11 +9,11 @@ Nested free function (not an object method) for `helpers.pack.label`. ### label + `s` -**s** +*s* # Box ## tag + `s` -**s** +*s* diff --git a/tests/structure/ns/path3.mq.md b/tests/structure/ns/path3.mq.md index 780ec0e..29ad30f 100644 --- a/tests/structure/ns/path3.mq.md +++ b/tests/structure/ns/path3.mq.md @@ -5,10 +5,10 @@ import helpers:helpers.mq.md # main -*v = > helpers.pack.label s="ok"* +**v = > helpers.pack.label s="ok"** > print text=`v` -*b = > helpers.Box* +**b = > helpers.Box** > print text=constructed diff --git a/tests/structure/ns/use.mq.md b/tests/structure/ns/use.mq.md index 8a954d5..ccaa0ff 100644 --- a/tests/structure/ns/use.mq.md +++ b/tests/structure/ns/use.mq.md @@ -6,6 +6,6 @@ import trim_text:text.str_trim # main -*t = > trim_text s=" hi"* +**t = > trim_text s=" hi"** > print text=`t` diff --git a/tests/structure/object-handle.mq.md b/tests/structure/object-handle.mq.md index dedff91..aaef7d6 100644 --- a/tests/structure/object-handle.mq.md +++ b/tests/structure/object-handle.mq.md @@ -6,32 +6,32 @@ import json:lib/json.mq.md # counter + `n` -*t = > json.parse text={"p":"{\"n\":","s":"}"}* -*qn = > str `n`* -*p = > json.get value=`t` key="p"* -*s = > json.get value=`t` key="s"* -*raw = p + qn + s* -**> json.parse text=`raw`** +**t = > json.parse text={"p":"{\"n\":","s":"}"}** +**qn = > str `n`** +**p = > json.get value=`t` key="p"** +**s = > json.get value=`t` key="s"** +**raw = p + qn + s** +*> json.parse text=`raw`* ## bump -*n = > json.get value=`self` key="n"* -*n2 = n + 1* -*t = > json.parse text={"p":"{\"n\":","s":"}"}* -*qn = > str `n2`* -*p = > json.get value=`t` key="p"* -*s = > json.get value=`t` key="s"* -*raw = p + qn + s* -*m = > json.parse text=`raw`* -**m** +**n = > json.get value=`self` key="n"** +**n2 = n + 1** +**t = > json.parse text={"p":"{\"n\":","s":"}"}** +**qn = > str `n2`** +**p = > json.get value=`t` key="p"** +**s = > json.get value=`t` key="s"** +**raw = p + qn + s** +**m = > json.parse text=`raw`** +*m* # main -*c = > counter n=3* -*ty = > json.get value=`c` key="_type"* +**c = > counter n=3** +**ty = > json.get value=`c` key="_type"** > print text=`ty` -*n = > json.get value=`c` key="n"* +**n = > json.get value=`c` key="n"** > print text=`n` -*c2 = > `c`.bump* -*n2 = > json.get value=`c2` key="n"* +**c2 = > `c`.bump** +**n2 = > json.get value=`c2` key="n"** > print text=`n2`