diff --git a/CHANGELOG.md b/CHANGELOG.md index 6420964..49b9050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,10 +22,33 @@ Protocol axes (Tool v1, Analysis v2, Trace v2) are versioned separately. stderr preservation, missing emit, timeout, invalid JSON) and architectural coupling gates. +### Added (PR-02) + +- Reader-oriented `DocumentModel` over the frozen `marqdo.md.v1` Comrak profile: + headings, GFM tables/task lists, blockquotes, code fences, math literals, + exact UTF-8 byte spans, source line index. +- Typed `SemanticProjection` with full Analysis v2 validation: schema/product/ + profile checks, project identity, exact `source_digest`, unit/function/ + statement/resource/import/reference/call/diagnostic projection and + per-span UTF-8 boundary validation with explicit warnings. +- One `PresentationModel` + one `ReaderRenderer`; Live and Export share the same + bytes and differ only by `LinkPolicy` and control availability. +- Single `assets/reader.css` + `assets/reader.js` theme (layered tokens, warm + paper, serif prose, gold/olive semantics, source pane, dialogs, responsive, + print, reduced motion) and `src/assets.rs` SHA-256 asset bundle. +- Local Live reader: loopback Host validation, strict request limits, + single-pass percent decoding, safe project paths, CSP/security headers, + read-only `/`, `/file`, `/assets/*`, `/api/document`, `/api/health`. +- `AppContext` degradation: missing core → prose-only with `CORE_UNAVAILABLE`; + failed check → diagnostics + revoked semantics; protocol mismatch → hard error. +- Examples (`welcome`, `mixed-modes`, `control-flow`, `tables-math`, + `diagnostics`) and real Analysis v2 goldens generated from the frozen CLI. +- Tests: rendering contracts, XSS/URL sanitization, Live/Export link parity, + raw HTTP server security tests, asset integrity, architectural gates. + ### Known limitations -- `browse` and `export` currently return `view.unsupported`; they land in - PR-02/PR-03 (reader) and PR-05 (export). -- The single `assets/reader.css` + `assets/reader.js` theme is not present yet. -- `verify` uses a structural binding check; the typed `SemanticProjection` - replaces it in PR-02 with the same external result. +- `export` still returns `view.unsupported` (PR-05); the run control is + explicitly disabled (PR-04) and never fakes execution. +- Variables/memory/proof states remain `UNSUPPORTED`. +- Browser screenshot/geometry acceptance is scheduled for PR-06. diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 6a315c6..bee75b1 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -25,9 +25,9 @@ Beta 版 CLI 必须使用 prerelease 范围(`>=3.0.0-beta.1,<4.0.0`);`>=3. | 能力 | 状态 | |---|---| -| 原始 Markdown 只读浏览(GFM 表/列表/引用/代码围栏/数学文本) | 计划 PR-02 | -| Analysis v2 静态语义(函数/Unit/诊断/引用/资源) | 计划 PR-02 | -| 文档态 / 源码态切换 | 计划 PR-02 | +| 原始 Markdown 只读浏览(GFM 表/列表/引用/代码围栏/数学文本) | **已实现**(PR-02) | +| Analysis v2 静态语义(函数/Unit/诊断/引用/资源) | **已实现**(PR-02) | +| 文档态 / 源码态切换 | **已实现**(PR-02) | | 暖纸 Reader 视觉(单一 CSS/JS) | 计划 PR-03 | | 用户显式触发运行 + Trace v2 事件可视化 | 计划 PR-04 | | Live 本机安全 API | 计划 PR-05 | diff --git a/README.md b/README.md index 5adb194..e87a8a6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Marqdo View 是一个独立的可执行文档阅读器:以**原始 Markdown ## 当前状态 -**开发中,尚未可运行。** PR-00(基线、旧 View 静态取证、视觉/状态设计基准)已完成;后续按 PR-01→PR-06 交付 Tool Protocol v1 安装闭环、只读浏览、Reader 视觉、Trace 可视化、Live/Export 安全与端到端验收。任何未完成能力都必须在 `docs/STATUS.md` 与 CHANGELOG 明确标注,不以占位功能冒充已实现。 +**开发中。** PR-00(基线/取证/设计基准)、PR-01(Tool Protocol v1 + verify)、PR-02(DocumentModel/Analysis v2 只读浏览 + 单一渲染器 + 本机 Live 阅读)已完成。`marqdo view [PATH]` 当前提供本机只读浏览;`export` 与显式运行入口按 PR-05/PR-04 顺序交付。任何未完成能力都在 `docs/STATUS.md` 与 CHANGELOG 明确标注,不以占位功能冒充已实现。 ## 架构约束(摘要) @@ -43,6 +43,13 @@ cargo test --locked cargo build --release --locked ``` +本机浏览(默认只绑定 127.0.0.1,不自动执行): + +```bash +MARQDO_BIN=/absolute/path/to/marqdo cargo run -- examples/welcome --no-open +# 或用已安装 bundle:marqdo view examples/welcome --no-open +``` + 安装到冻结 CLI(开发期): ```bash diff --git a/assets/blossom.webp b/assets/blossom.webp new file mode 100755 index 0000000..35b7b91 Binary files /dev/null and b/assets/blossom.webp differ diff --git a/assets/feather.webp b/assets/feather.webp new file mode 100755 index 0000000..7dd900c Binary files /dev/null and b/assets/feather.webp differ diff --git a/assets/licenses/ASSETS.md b/assets/licenses/ASSETS.md new file mode 100644 index 0000000..3685177 --- /dev/null +++ b/assets/licenses/ASSETS.md @@ -0,0 +1,22 @@ +# Third-party and reused visual assets + +The three visual assets in `assets/` were selected from the legacy `cflmy/marqdo` +repository at commit `1c55baabd570e18b9da8f9057cef2f848e176690`, which is licensed +under the Apache License 2.0. They are reused as static decorative artwork only; +no legacy CSS/JS/code is copied. Source hashes were verified before copying +(see `docs/audits/legacy-render-paths.md` §6). + +| File | Legacy path | SHA-256 | License | +|---|---|---|---| +| `assets/logo.svg` | `src/view/assets/logo.svg` | `52b2338468c62a7da86178ecec86cbb7ea44a996cd1bc4275ebb56f16f2244fe` | Apache-2.0 (legacy marqdo) | +| `assets/blossom.webp` | `src/view/assets/blossom.webp` | `901fd6b37ebb20d1dfc3bf4d265a063308605350fd317e41914fa35b06f46e00` | Apache-2.0 (legacy marqdo) | +| `assets/feather.webp` | `src/view/assets/feather.webp` | `fbd787174be1e8027ae4661b99f7f2cc01b824d8fc875a1d2d39cbd0c052e5de` | Apache-2.0 (legacy marqdo) | + +The legacy `assets/README.md` states the blossom and feather artwork was generated +for the reader redesign (original transparent artwork), and the logo is a +project-native geometric M/book mark. No KaTeX or other vendored third-party +assets are carried into this repository. + +Bundling: `src/assets.rs` embeds these files with SHA-256 digests; Live and +Export serve the exact same bytes (ADR-0002). Replacing an asset requires +updating this file and the hashes asserted by `tests/rendering/asset_tests.rs`. diff --git a/assets/logo.svg b/assets/logo.svg new file mode 100755 index 0000000..a279cb6 --- /dev/null +++ b/assets/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/reader.css b/assets/reader.css new file mode 100644 index 0000000..00c9285 --- /dev/null +++ b/assets/reader.css @@ -0,0 +1,1171 @@ +/* Marqdo View — the single reader theme (ADR-0001/0002). + * + * Order is part of the contract: one token layer, one layout layer, no legacy + * skin files and no high-specificity override chains. */ +@layer reset, tokens, layout, typography, semantics, overlays, interactions, responsive; + +@layer tokens { + .mq-reader { + /* colour tokens (docs/design/visual-tokens.md) */ + --mq-paper: #fcf9f5; + --mq-surface: #fffcf8; + --mq-surface-2: #f7f0e5; + --mq-surface-3: #f1e6d5; + --mq-ink: #29251f; + --mq-strong: #1f1b16; + --mq-muted: #847565; + --mq-line: #e7ddce; + --mq-line-strong: #c9b79c; + --mq-gold: #b88a45; + --mq-gold-soft: #e8c78f; + --mq-olive: #52603a; + --mq-ok: #52603a; + --mq-warn: #996b28; + --mq-error: #a63e30; + --mq-focus: #8a622e; + + /* type tokens: local system stacks only, never a CDN font */ + --mq-serif: "Iowan Old Style", "Palatino Linotype", "Noto Serif CJK SC", + "Source Han Serif SC", "Songti SC", SimSun, Georgia, serif; + --mq-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", + monospace; + --mq-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", + "PingFang SC", "Microsoft YaHei", sans-serif; + + /* layout tokens */ + --mq-gutter: clamp(20px, 5vw, 64px); + --mq-column: 820px; + --mq-topbar-h: 76px; + --mq-radius: 12px; + --mq-dock-h: 66px; + --mq-note-width: 176px; + } +} + +@layer reset { + *, + *::before, + *::after { + box-sizing: border-box; + } + .mq-reader { + margin: 0; + background: var(--mq-paper); + color: var(--mq-ink); + font-family: var(--mq-serif); + font-size: 18px; + line-height: 1.72; + -webkit-text-size-adjust: 100%; + text-rendering: optimizeLegibility; + } + .mq-reader img, + .mq-reader svg { + max-width: 100%; + } + .mq-reader button { + font: inherit; + color: inherit; + } + .mq-reader dialog { + border: 0; + padding: 0; + background: transparent; + color: var(--mq-ink); + } + .mq-reader dialog::backdrop { + background: #29251f66; + backdrop-filter: blur(2px); + } + .mq-reader [hidden] { + display: none; + } +} + +@layer layout { + .mq-reader { + position: relative; + min-height: 100dvh; + } + .mq-skip { + position: absolute; + left: -9999px; + top: 0; + z-index: 99; + padding: 10px 16px; + background: var(--mq-surface); + border: 1px solid var(--mq-gold); + border-radius: 8px; + } + .mq-skip:focus { + left: 16px; + top: 16px; + } + + .mq-topbar { + position: relative; + z-index: 20; + display: grid; + grid-template-columns: 1fr auto 1fr; + align-items: center; + gap: 12px; + max-width: 1120px; + margin: 0 auto; + padding: 16px var(--mq-gutter) 0; + min-height: var(--mq-topbar-h); + } + .mq-topbar-start { + display: flex; + align-items: center; + gap: 6px; + } + .mq-topbar-end { + display: flex; + align-items: center; + justify-content: flex-end; + gap: 6px; + } + .mq-brand { + display: inline-flex; + align-items: center; + gap: 10px; + text-decoration: none; + color: var(--mq-ink); + text-align: left; + } + .mq-brand-logo { + width: 44px; + height: 44px; + flex: none; + } + .mq-brand-word { + font: 30px/1.05 var(--mq-serif); + letter-spacing: -0.5px; + color: var(--mq-strong); + } + .mq-brand-sub { + display: block; + margin-top: 3px; + padding-left: 2px; + font: 9px/1.4 var(--mq-sans); + letter-spacing: 3.2px; + text-transform: uppercase; + color: var(--mq-muted); + } + + .mq-icon-btn { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 8px; + width: 44px; + height: 44px; + padding: 0; + border: 0; + border-radius: 50%; + background: transparent; + cursor: pointer; + } + .mq-icon-btn:hover { + background: var(--mq-surface-2); + } + .mq-icon-btn svg { + width: 22px; + height: 22px; + fill: none; + stroke: currentColor; + stroke-width: 1.7; + stroke-linecap: round; + stroke-linejoin: round; + } + + .mq-tabs { + display: flex; + justify-content: center; + gap: clamp(18px, 5vw, 68px); + margin: 6px auto 0; + padding: 0 var(--mq-gutter); + border-bottom: 1px solid var(--mq-line); + max-width: 1120px; + } + .mq-tab { + position: relative; + padding: 12px 10px 14px; + border: 0; + background: transparent; + font: 20px/1.4 var(--mq-serif); + color: var(--mq-ink); + cursor: pointer; + } + .mq-tab[aria-current="page"] { + color: var(--mq-focus); + } + .mq-tab[aria-current="page"]::after { + content: ""; + position: absolute; + left: 0; + right: 0; + bottom: -1px; + height: 2px; + background: var(--mq-gold); + } + .mq-tab[data-disabled="true"] { + color: var(--mq-muted); + cursor: help; + } + + .mq-main { + position: relative; + z-index: 2; + width: min(100% - var(--mq-gutter) * 2, var(--mq-column)); + margin: 0 auto; + padding: clamp(28px, 5vh, 56px) 0 calc(var(--mq-dock-h) + 72px); + } + + .mq-docmeta { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 10px 14px; + margin: 0 0 26px; + font: 13px/1.6 var(--mq-sans); + color: var(--mq-muted); + } + .mq-filename { + font-family: var(--mq-mono); + letter-spacing: 0.02em; + } + .mq-shares { + display: flex; + flex-wrap: wrap; + gap: 8px; + margin: 0; + padding: 0; + list-style: none; + } + .mq-chip { + display: inline-flex; + align-items: center; + gap: 6px; + padding: 3px 12px; + border: 1px solid var(--mq-line); + border-radius: 22px; + background: var(--mq-surface-2); + font: 12px/1.5 var(--mq-mono); + color: var(--mq-ink); + text-decoration: none; + } + .mq-chip::before { + content: "◇"; + color: var(--mq-gold); + } + + .mq-footer { + position: relative; + z-index: 2; + display: flex; + flex-wrap: wrap; + justify-content: space-between; + gap: 8px; + width: min(100% - var(--mq-gutter) * 2, var(--mq-column)); + margin: 0 auto; + padding: 0 0 40px; + font: 11px/1.6 var(--mq-sans); + letter-spacing: 0.16em; + text-transform: uppercase; + color: var(--mq-muted); + } + + .mq-dock { + position: fixed; + z-index: 30; + left: 50%; + bottom: calc(18px + env(safe-area-inset-bottom, 0px)); + transform: translateX(-50%); + display: flex; + align-items: center; + gap: 4px; + padding: 6px; + border: 1px solid var(--mq-line); + border-radius: 999px; + background: color-mix(in srgb, var(--mq-surface) 94%, transparent); + box-shadow: 0 10px 30px #3c2f1c1a, 0 1px 0 #fff inset; + backdrop-filter: blur(8px); + } + .mq-dock-btn { + display: inline-flex; + flex-direction: column; + align-items: center; + gap: 2px; + min-width: 58px; + padding: 7px 10px 5px; + border: 0; + border-radius: 999px; + background: transparent; + color: var(--mq-ink); + font: 10px/1.2 var(--mq-sans); + letter-spacing: 0.06em; + cursor: pointer; + } + .mq-dock-btn svg { + width: 20px; + height: 20px; + fill: none; + stroke: currentColor; + stroke-width: 1.7; + stroke-linecap: round; + stroke-linejoin: round; + } + .mq-dock-btn:hover { + background: var(--mq-surface-2); + } + .mq-dock-btn[data-action="run"] { + background: var(--mq-gold); + color: #fffdf8; + min-width: 66px; + } + .mq-dock-btn[data-action="run"]:hover { + background: var(--mq-focus); + } + .mq-dock-btn[disabled] { + opacity: 0.55; + cursor: not-allowed; + background: transparent; + color: var(--mq-muted); + } + + .mq-dialog { + width: min(92vw, 640px); + max-height: 82vh; + overflow: auto; + padding: 22px 24px; + border: 1px solid var(--mq-line); + border-radius: 16px; + background: var(--mq-surface); + box-shadow: 0 30px 80px #33251a26; + } + .mq-dialog-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + margin-bottom: 14px; + } + .mq-dialog-head h2 { + margin: 0; + font: 22px/1.3 var(--mq-serif); + } + .mq-dialog p { + font-size: 15px; + color: var(--mq-muted); + } + .mq-dialog .mq-close { + flex: none; + font-size: 22px; + } +} + +@layer typography { + .mq-document { + font-family: var(--mq-serif); + } + .mq-document > *:first-child { + margin-top: 0; + } + .mq-document h1, + .mq-document h2, + .mq-document h3, + .mq-document h4, + .mq-document h5, + .mq-document h6 { + position: relative; + margin: 2em 0 0.6em; + font-family: var(--mq-serif); + font-weight: 600; + line-height: 1.35; + color: var(--mq-strong); + scroll-margin-top: calc(var(--mq-topbar-h) + 20px); + } + .mq-document h1 { + margin-top: 0.2em; + font-size: clamp(30px, 4vw, 40px); + } + .mq-document h2 { + font-size: clamp(25px, 3vw, 31px); + } + .mq-document h3 { + font-size: 23px; + } + .mq-document h4 { + font-size: 20px; + } + .mq-document h5, + .mq-document h6 { + font-size: 18px; + color: var(--mq-muted); + } + .mq-document h2[data-semantic="exec"] { + padding-left: 20px; + } + .mq-document h2[data-semantic="exec"]::before { + content: ""; + position: absolute; + left: 0; + top: 0.16em; + bottom: 0.12em; + width: 5px; + transform: skew(-10deg); + background: linear-gradient(var(--mq-gold), var(--mq-gold-soft), var(--mq-gold)); + border-radius: 2px; + } + .mq-document h2[data-semantic="knowledge"]::before { + content: "❧"; + margin-right: 8px; + color: var(--mq-olive); + font-size: 0.72em; + vertical-align: 0.08em; + } + .mq-document p { + margin: 0 0 1.05em; + overflow-wrap: anywhere; + } + .mq-document a { + color: var(--mq-focus); + text-decoration-color: color-mix(in srgb, var(--mq-gold) 60%, transparent); + text-underline-offset: 3px; + } + .mq-document a[data-reference-state="external"]::after { + content: "↗"; + display: inline-block; + margin-left: 3px; + font-size: 0.72em; + color: var(--mq-muted); + text-decoration: none; + } + .mq-document a[data-reference-state="broken"] { + color: var(--mq-error); + text-decoration-style: wavy; + } + .mq-document strong { + font-weight: 650; + color: var(--mq-strong); + } + .mq-document em { + font-style: italic; + } + .mq-document del { + color: var(--mq-muted); + } + .mq-document ul, + .mq-document ol { + margin: 0 0 1.1em; + padding-left: 1.5em; + } + .mq-document li { + margin: 0.25em 0; + } + .mq-document li::marker { + color: var(--mq-gold); + } + .mq-document blockquote { + margin: 1.4em 0; + padding: 16px 20px; + border-left: 3px solid var(--mq-gold-soft); + border-radius: 0 10px 10px 0; + background: var(--mq-surface-2); + color: var(--mq-muted); + } + .mq-document blockquote p:last-child { + margin-bottom: 0; + } + .mq-document hr { + margin: 2.4em 0; + border: 0; + border-top: 1px solid var(--mq-line); + } + .mq-document code { + padding: 0.12em 0.35em; + border-radius: 6px; + background: var(--mq-surface-2); + font: 0.86em/1.5 var(--mq-mono); + color: var(--mq-strong); + } + .mq-document pre { + margin: 1.5em 0; + padding: 16px 18px; + overflow: auto; + border: 1px solid var(--mq-line); + border-radius: 10px; + background: var(--mq-surface); + font: 14px/1.65 var(--mq-mono); + } + .mq-document pre code { + padding: 0; + background: transparent; + font-size: inherit; + } + .mq-codeblock { + position: relative; + margin: 1.5em 0; + } + .mq-codeblock pre { + margin: 0; + } + .mq-codeblock-lang { + position: absolute; + top: 8px; + right: 12px; + font: 10px/1.4 var(--mq-sans); + letter-spacing: 0.14em; + text-transform: uppercase; + color: var(--mq-muted); + } + .mq-table-wrap { + margin: 1.5em 0; + overflow-x: auto; + } + .mq-document table { + width: 100%; + border-collapse: collapse; + font: 14px/1.65 var(--mq-sans); + } + .mq-document th, + .mq-document td { + padding: 9px 12px; + border: 1px solid var(--mq-line); + text-align: left; + } + .mq-document th { + background: var(--mq-surface-2); + font-weight: 600; + } + .mq-document tr:nth-child(even) td { + background: color-mix(in srgb, var(--mq-surface) 70%, var(--mq-paper)); + } + .mq-math { + padding: 0.1em 0.3em; + border-radius: 4px; + background: color-mix(in srgb, var(--mq-surface-2) 65%, transparent); + font-family: var(--mq-mono); + font-size: 0.9em; + } + .mq-math-block { + margin: 1.5em 0; + padding: 16px 18px; + overflow-x: auto; + border: 1px solid var(--mq-line); + border-left: 3px solid var(--mq-gold-soft); + border-radius: 10px; + background: var(--mq-surface); + font: 15px/1.7 var(--mq-mono); + white-space: pre-wrap; + } + .mq-math-note { + display: block; + margin-top: 6px; + font: 10px/1.4 var(--mq-sans); + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--mq-muted); + } + .mq-raw-omitted { + margin: 1.2em 0; + padding: 10px 14px; + border: 1px dashed var(--mq-line-strong); + border-radius: 8px; + font: 12px/1.6 var(--mq-sans); + color: var(--mq-muted); + } + .mq-task { + display: inline-block; + width: 1.05em; + height: 1.05em; + margin-right: 0.4em; + border: 1px solid var(--mq-line-strong); + border-radius: 4px; + vertical-align: -0.12em; + text-align: center; + font: 11px/1em var(--mq-sans); + color: var(--mq-olive); + } + .mq-task[data-checked="true"]::after { + content: "✓"; + } +} + +@layer semantics { + .mq-mode-badge { + display: inline-block; + margin-right: 10px; + padding: 2px 8px; + border: 1px solid var(--mq-line-strong); + border-radius: 4px; + vertical-align: 0.22em; + font: 9px/1.5 var(--mq-sans); + letter-spacing: 0.16em; + text-transform: uppercase; + color: var(--mq-muted); + } + .mq-mode-badge[data-mode="exec"] { + border-color: var(--mq-gold); + color: var(--mq-focus); + } + .mq-signature { + display: flex; + flex-wrap: wrap; + gap: 6px; + margin: -0.2em 0 1.2em; + font: 12px/1.6 var(--mq-mono); + color: var(--mq-muted); + } + .mq-signature code { + background: var(--mq-surface-2); + } + .mq-signature .mq-note { + font-family: var(--mq-sans); + } + + .mq-anchor { + border-radius: 5px; + text-decoration: underline; + text-decoration-color: color-mix(in srgb, var(--mq-gold) 55%, transparent); + text-decoration-style: dotted; + text-underline-offset: 4px; + cursor: help; + } + .mq-anchor[data-statement-kind="return"] { + text-decoration-color: color-mix(in srgb, var(--mq-olive) 60%, transparent); + } + .mq-anchor[data-statement-kind="branch"], + .mq-anchor[data-statement-kind="loop"] { + text-decoration-color: color-mix(in srgb, var(--mq-muted) 55%, transparent); + } + .mq-anchor:focus-visible, + .mq-anchor.is-focus { + outline: 2px solid var(--mq-gold); + outline-offset: 2px; + } + body[data-annotations="off"] .mq-anchor { + text-decoration: none; + cursor: inherit; + } + + .mq-status { + display: inline-flex; + align-items: center; + gap: 6px; + padding: 3px 10px; + border: 1px solid var(--mq-line); + border-radius: 999px; + background: var(--mq-surface); + font: 11px/1.5 var(--mq-sans); + color: var(--mq-muted); + } + .mq-status::before { + content: ""; + width: 7px; + height: 7px; + border-radius: 50%; + background: currentColor; + } + .mq-status[data-source-status="static-ok"] { + color: var(--mq-ok); + border-color: color-mix(in srgb, var(--mq-ok) 35%, var(--mq-line)); + } + .mq-status[data-source-status="core-error"] { + color: var(--mq-error); + } + .mq-status[data-source-status="core-unavailable"], + .mq-status[data-source-status="protocol-incompatible"], + .mq-status[data-source-status="source-mismatch"], + .mq-status[data-source-status="stale"] { + color: var(--mq-warn); + } + + .mq-diagnostics { + margin: 0 0 26px; + border: 1px solid var(--mq-line); + border-radius: 10px; + background: var(--mq-surface); + } + .mq-diagnostics > summary { + padding: 10px 16px; + cursor: pointer; + font: 13px/1.6 var(--mq-sans); + color: var(--mq-muted); + } + .mq-diagnostics[data-severity="error"] > summary { + color: var(--mq-error); + } + .mq-diagnostics ol { + margin: 0; + padding: 0 16px 14px 34px; + } + .mq-diagnostics li { + margin: 8px 0; + font: 13px/1.6 var(--mq-sans); + } + .mq-diagnostics .mq-diag-code { + font-family: var(--mq-mono); + color: var(--mq-focus); + } + .mq-diagnostics .mq-diag-loc { + margin-left: 6px; + font-size: 12px; + color: var(--mq-muted); + } + .mq-diagnostics .mq-diag-hint { + display: block; + color: var(--mq-muted); + font-size: 12px; + } + + .mq-annotation-list { + margin: 20px 0; + padding: 0; + list-style: none; + } + .mq-annotation-list li { + display: flex; + gap: 8px; + padding: 7px 0; + border-bottom: 1px solid var(--mq-line); + font: 13px/1.6 var(--mq-sans); + } + .mq-annotation-list .mq-annot-kind { + flex: none; + min-width: 54px; + color: var(--mq-olive); + font-family: var(--mq-mono); + font-size: 11px; + } + + .mq-welcome { + position: relative; + margin: 10px 0 48px; + text-align: center; + } + .mq-welcome .mq-eyebrow { + margin: 0 0 6px; + font: 11px/1.6 var(--mq-sans); + letter-spacing: 7px; + text-transform: uppercase; + color: var(--mq-focus); + } + .mq-welcome h1 { + margin: 0; + font: italic clamp(58px, 9vw, 92px) / 1.1 var(--mq-serif); + letter-spacing: -2px; + background: linear-gradient(120deg, #b98b46, #e8c78f 55%, #b98b46); + -webkit-background-clip: text; + background-clip: text; + color: transparent; + } + .mq-welcome .mq-feather { + position: absolute; + top: -6px; + right: max(0px, 8%); + width: 74px; + height: 108px; + background: url("__FEATHER__") no-repeat center / contain; + opacity: 0.85; + pointer-events: none; + } + .mq-welcome .mq-motto { + margin: 12px 0 0; + font: 14px/1.9 var(--mq-serif); + letter-spacing: 3px; + color: var(--mq-muted); + } + + .mq-ornament-blossom { + position: absolute; + z-index: 0; + top: 0; + left: 0; + width: clamp(160px, 19vw, 300px); + height: clamp(190px, 23vw, 350px); + background: url("__BLOSSOM__") no-repeat left top / contain; + opacity: 0.6; + pointer-events: none; + } + + .mq-functions { + margin: 0 0 28px; + padding: 14px 18px; + border: 1px solid var(--mq-line); + border-radius: 10px; + background: var(--mq-surface); + } + .mq-functions h2 { + margin: 0 0 8px; + font: 13px/1.6 var(--mq-sans); + letter-spacing: 0.12em; + text-transform: uppercase; + color: var(--mq-muted); + } + .mq-functions ul { + margin: 0; + padding: 0; + list-style: none; + } + .mq-functions li { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 8px; + padding: 6px 0; + border-top: 1px solid var(--mq-line); + font: 13px/1.6 var(--mq-sans); + } + .mq-functions li:first-child { + border-top: 0; + } + .mq-functions a { + color: var(--mq-ink); + text-decoration: none; + } + .mq-functions a:hover { + color: var(--mq-focus); + } + .mq-functions .mq-fn-sig { + font: 12px/1.6 var(--mq-mono); + color: var(--mq-muted); + } + + .mq-run-panel { + margin: 26px 0 0; + padding: 18px 20px; + border: 1px solid var(--mq-line); + border-radius: 12px; + background: var(--mq-surface); + } + .mq-run-panel h2 { + margin: 0 0 8px; + font: 15px/1.5 var(--mq-sans); + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--mq-muted); + } + .mq-run-events { + margin: 10px 0 0; + padding: 0; + list-style: none; + font: 12px/1.7 var(--mq-mono); + } + .mq-run-events li { + padding: 3px 0; + border-bottom: 1px solid var(--mq-line); + } + .mq-run-events .mq-event-kind { + display: inline-block; + min-width: 118px; + color: var(--mq-olive); + } + .mq-stdout { + margin: 12px 0 0; + padding: 12px 14px; + overflow-x: auto; + border: 1px solid var(--mq-line); + border-radius: 8px; + background: var(--mq-surface-2); + font: 12px/1.6 var(--mq-mono); + white-space: pre-wrap; + overflow-wrap: anywhere; + } + .mq-run-state[data-run-state="succeeded"] { + color: var(--mq-ok); + } + .mq-run-state[data-run-state="failed"] { + color: var(--mq-error); + } + .mq-run-state[data-run-state="stale"], + .mq-run-state[data-run-state="truncated"] { + color: var(--mq-warn); + } +} + +@layer overlays { + /* source pane: exact bytes as preformatted text with line numbers */ + .mq-source { + display: none; + margin: 0; + padding: 0; + border: 1px solid var(--mq-line); + border-radius: 12px; + background: var(--mq-surface); + overflow: hidden; + } + .mq-source-lines { + margin: 0; + padding: 14px 0; + overflow: auto; + max-height: 76vh; + font: 13px/1.7 var(--mq-mono); + list-style: none; + counter-reset: mq-line; + } + .mq-source-lines li { + display: flex; + gap: 14px; + padding: 0 16px 0 0; + white-space: pre; + } + .mq-source-lines li:target { + background: color-mix(in srgb, var(--mq-gold) 14%, transparent); + } + .mq-source-lines .mq-line-no { + flex: none; + width: 52px; + padding-right: 10px; + text-align: right; + color: var(--mq-muted); + user-select: none; + border-right: 1px solid var(--mq-line); + } + .mq-source-lines .mq-line-text { + white-space: pre; + } + .mq-source-empty { + padding: 18px; + color: var(--mq-muted); + font: 14px/1.6 var(--mq-sans); + } + body[data-mode="source"] .mq-document, + body[data-mode="source"] .mq-functions, + body[data-mode="source"] .mq-run-panel { + display: none; + } + body[data-mode="source"] .mq-source { + display: block; + } + + .mq-toast { + position: fixed; + z-index: 50; + left: 50%; + bottom: calc(var(--mq-dock-h) + 30px); + transform: translateX(-50%); + max-width: 82vw; + padding: 9px 16px; + border: 1px solid var(--mq-line); + border-radius: 999px; + background: var(--mq-surface); + box-shadow: 0 10px 26px #33251a1f; + font: 13px/1.5 var(--mq-sans); + color: var(--mq-ink); + } + + .mq-search-field { + width: 100%; + padding: 10px 14px; + border: 1px solid var(--mq-line-strong); + border-radius: 10px; + background: var(--mq-paper); + color: var(--mq-ink); + font: 15px/1.6 var(--mq-sans); + } + .mq-search-results { + margin: 14px 0 0; + padding: 0; + list-style: none; + } + .mq-search-results li { + border-top: 1px solid var(--mq-line); + } + .mq-search-results button { + display: block; + width: 100%; + padding: 9px 4px; + border: 0; + background: transparent; + text-align: left; + font: 13px/1.6 var(--mq-sans); + color: var(--mq-ink); + cursor: pointer; + } + .mq-search-results button:hover { + background: var(--mq-surface-2); + } + .mq-search-results mark { + background: color-mix(in srgb, var(--mq-gold) 30%, transparent); + color: inherit; + } + + .mq-menu-list { + margin: 0; + padding: 0; + list-style: none; + } + .mq-menu-list button { + display: flex; + width: 100%; + align-items: center; + justify-content: space-between; + gap: 16px; + padding: 10px 4px; + border: 0; + border-top: 1px solid var(--mq-line); + background: transparent; + font: 14px/1.6 var(--mq-sans); + color: var(--mq-ink); + text-align: left; + cursor: pointer; + } + .mq-menu-list button:hover { + background: var(--mq-surface-2); + } + .mq-menu-list .mq-menu-hint { + font-size: 11px; + color: var(--mq-muted); + } + + .mq-colophon { + margin: 8px 0 0; + font: 12px/1.7 var(--mq-sans); + color: var(--mq-muted); + } +} + +@layer interactions { + .mq-reader :focus-visible { + outline: 2px solid var(--mq-gold); + outline-offset: 2px; + } + .mq-reader a:focus-visible, + .mq-dock-btn:focus-visible { + border-radius: 6px; + } + body[data-size="large"] .mq-document { + font-size: 21px; + } + body[data-size="small"] .mq-document { + font-size: 16px; + } + body[data-annotations="off"] .mq-annotation-list, + body[data-annotations="off"] .mq-run-panel { + display: none; + } + @media (prefers-reduced-motion: no-preference) { + .mq-reader { + scroll-behavior: smooth; + } + .mq-dock, + .mq-dialog { + transition: opacity 0.16s ease, transform 0.16s ease; + } + } + @media (prefers-reduced-motion: reduce) { + .mq-reader { + scroll-behavior: auto; + } + } +} + +@layer responsive { + @media (max-width: 899px) { + .mq-reader { + --mq-column: 680px; + --mq-note-width: 0px; + } + .mq-topbar { + grid-template-columns: auto 1fr auto; + } + .mq-brand { + justify-self: start; + } + .mq-brand-logo { + width: 38px; + height: 38px; + } + .mq-brand-word { + font-size: 26px; + } + .mq-tabs { + justify-content: flex-start; + overflow-x: auto; + scrollbar-width: none; + } + .mq-tab { + font-size: 17px; + white-space: nowrap; + } + } + @media (max-width: 600px) { + .mq-reader { + font-size: 17px; + --mq-gutter: 18px; + } + .mq-topbar { + min-height: 64px; + padding-top: 10px; + } + .mq-brand-sub { + display: none; + } + .mq-tab-label { + font-size: 0; + } + .mq-tab-label::first-letter { + font-size: 17px; + } + .mq-dock { + gap: 0; + padding: 5px; + } + .mq-dock-btn { + min-width: 48px; + padding: 6px 8px 4px; + } + .mq-dock-btn span { + display: none; + } + .mq-welcome .mq-feather { + display: none; + } + .mq-footer { + flex-direction: column; + align-items: flex-start; + } + } + @media (min-width: 1440px) { + .mq-main { + --mq-column: 840px; + } + } + @media (min-width: 1800px) { + .mq-main { + --mq-column: 880px; + } + } + @media print { + .mq-reader { + background: #fff; + color: #111; + font-size: 12pt; + } + .mq-topbar, + .mq-tabs, + .mq-dock, + .mq-footer, + .mq-ornament-blossom, + .mq-welcome .mq-feather, + .mq-source, + .mq-dialog, + .mq-toast { + display: none; + } + .mq-main { + width: 100%; + padding: 0; + } + .mq-annotation-list, + .mq-run-panel { + break-inside: avoid; + } + .mq-document a::after { + content: " (" attr(href) ")"; + font-size: 9pt; + color: #555; + } + } +} diff --git a/assets/reader.js b/assets/reader.js new file mode 100644 index 0000000..64da91b --- /dev/null +++ b/assets/reader.js @@ -0,0 +1,386 @@ +/* Marqdo View — the single reader interaction script. + * + * Boundaries: this file only manipulates DOM state, layout and accessibility. + * It never parses @exec/@knowledge, never invents Analysis/Trace facts and + * never executes anything. All content is rendered by the one server-side + * ReaderRenderer (RFC-VIEW-0001 §7.1, §14.3). */ +(function () { + "use strict"; + + var reader = document.querySelector(".mq-reader"); + if (!reader) return; + + function $(selector, root) { + return (root || document).querySelector(selector); + } + function $$(selector, root) { + return Array.prototype.slice.call((root || document).querySelectorAll(selector)); + } + + var toastTimer = null; + function toast(message) { + var el = $("#mq-toast"); + if (!el) return; + el.textContent = message; + el.hidden = false; + clearTimeout(toastTimer); + toastTimer = setTimeout(function () { + el.hidden = true; + }, 3800); + } + + function openDialog(id) { + var dialog = document.getElementById(id); + if (!dialog) return null; + if (typeof dialog.showModal === "function") { + if (!dialog.open) dialog.showModal(); + } else { + dialog.setAttribute("open", ""); + } + var focusTarget = dialog.querySelector("[autofocus], input, button"); + if (focusTarget) focusTarget.focus(); + return dialog; + } + + function closeDialog(dialog) { + if (!dialog) return; + if (typeof dialog.close === "function" && dialog.open) dialog.close(); + else dialog.removeAttribute("open"); + } + + function closeAllDialogs() { + $$("dialog[open]").forEach(closeDialog); + } + + function setMode(mode) { + reader.dataset.mode = mode === "source" ? "source" : "document"; + $$("[data-action='mode-document'], [data-action='mode-source']").forEach(function (button) { + var active = button.dataset.action === "mode-" + reader.dataset.mode; + button.setAttribute("aria-current", active ? "page" : "false"); + }); + if (reader.dataset.mode === "source") { + var source = $(".mq-source"); + if (source) source.focus({ preventScroll: true }); + } + try { + var url = new URL(window.location.href); + if (reader.dataset.mode === "document") url.searchParams.delete("mode"); + else url.searchParams.set("mode", "source"); + window.history.replaceState(null, "", url.toString()); + } catch (error) { + /* history is optional */ + } + } + + function gotoAnchor(target) { + if (!target) return; + var heading = document.getElementById(target); + if (heading) { + closeAllDialogs(); + heading.scrollIntoView({ block: "start" }); + heading.classList.add("is-focus"); + setTimeout(function () { + heading.classList.remove("is-focus"); + }, 1600); + return true; + } + return false; + } + + function gotoSourceLine(line) { + var row = document.querySelector(".mq-source-lines li[data-line='" + line + "']"); + if (!row) return false; + closeAllDialogs(); + setMode("source"); + row.scrollIntoView({ block: "center" }); + row.classList.add("is-focus"); + setTimeout(function () { + row.classList.remove("is-focus"); + }, 1600); + return true; + } + + function showFunctions() { + var items = $$(".mq-functions li"); + var body = $("#mq-functions-body"); + if (!body) return; + body.textContent = ""; + if (!items.length) { + var empty = document.createElement("p"); + empty.textContent = "本文没有 Analysis 可见的 @exec 函数。"; + body.appendChild(empty); + } else { + var list = document.createElement("ul"); + list.className = "mq-annotation-list"; + items.forEach(function (item) { + var clone = item.cloneNode(true); + list.appendChild(clone); + }); + body.appendChild(list); + } + openDialog("mq-dialog-functions"); + } + + function showSearch() { + openDialog("mq-dialog-search"); + var input = $("#mq-search-input"); + if (input) { + input.value = ""; + input.focus(); + renderSearch(""); + } + } + + function collectSearchNodes() { + var nodes = []; + var walker = document.createTreeWalker( + $(".mq-document") || reader, + NodeFilter.SHOW_TEXT, + null + ); + while (walker.nextNode()) { + var text = walker.currentNode; + if (!text.nodeValue || !text.nodeValue.trim()) continue; + if (text.parentElement && text.parentElement.closest("script, style")) continue; + nodes.push(text); + } + return nodes; + } + + var searchNodes = null; + function renderSearch(query) { + var results = $("#mq-search-results"); + if (!results) return; + results.textContent = ""; + var needle = query.trim().toLowerCase(); + if (needle.length < 2) { + var hint = document.createElement("li"); + hint.textContent = "输入至少两个字符以搜索当前文档正文。"; + hint.className = "mq-search-hint"; + results.appendChild(hint); + return; + } + if (!searchNodes) searchNodes = collectSearchNodes(); + var shown = 0; + searchNodes.forEach(function (node) { + if (shown >= 40) return; + var value = node.nodeValue; + var index = value.toLowerCase().indexOf(needle); + if (index < 0) return; + var start = Math.max(0, index - 28); + var end = Math.min(value.length, index + needle.length + 34); + var li = document.createElement("li"); + var button = document.createElement("button"); + button.type = "button"; + var before = document.createTextNode( + (start > 0 ? "…" : "") + value.slice(start, index) + ); + var mark = document.createElement("mark"); + mark.textContent = value.slice(index, index + needle.length); + var after = document.createTextNode( + value.slice(index + needle.length, end) + (end < value.length ? "…" : "") + ); + button.appendChild(before); + button.appendChild(mark); + button.appendChild(after); + button.addEventListener("click", function () { + closeAllDialogs(); + var el = node.parentElement; + if (el) { + el.scrollIntoView({ block: "center" }); + el.classList.add("is-focus"); + setTimeout(function () { + el.classList.remove("is-focus"); + }, 1600); + } + }); + li.appendChild(button); + results.appendChild(li); + shown += 1; + }); + if (!shown) { + var none = document.createElement("li"); + none.textContent = "没有匹配的正文文本。"; + none.className = "mq-search-hint"; + results.appendChild(none); + } + } + + function toggleAnnotationVisibility() { + var off = reader.dataset.annotations === "off"; + reader.dataset.annotations = off ? "on" : "off"; + toast(off ? "已显示语义标注" : "已隐藏语义标注"); + closeAllDialogs(); + } + + function cycleTextSize() { + var order = ["normal", "large", "small"]; + var current = reader.dataset.size || "normal"; + var next = order[(order.indexOf(current) + 1) % order.length]; + reader.dataset.size = next; + toast("正文字号:" + (next === "large" ? "大" : next === "small" ? "小" : "标准")); + } + + function showUnsupported(what, why) { + var body = $("#mq-unsupported-body"); + if (body) { + body.textContent = ""; + var title = document.createElement("p"); + title.textContent = what + ":当前版本不支持。"; + var reason = document.createElement("p"); + reason.className = "mq-colophon"; + reason.textContent = why; + body.appendChild(title); + body.appendChild(reason); + } + openDialog("mq-dialog-unsupported"); + } + + function handleAction(action) { + switch (action) { + case "mode-document": + setMode("document"); + break; + case "mode-source": + setMode("source"); + break; + case "search": + showSearch(); + break; + case "functions": + showFunctions(); + break; + case "reload": + window.location.reload(); + break; + case "settings": + openDialog("mq-dialog-settings"); + break; + case "more": + openDialog("mq-dialog-more"); + break; + case "close-dialog": + closeAllDialogs(); + break; + case "print": + closeAllDialogs(); + window.print(); + break; + case "size": + cycleTextSize(); + break; + case "annotations": + toggleAnnotationVisibility(); + break; + case "variables": + showUnsupported( + "变量快照", + "Trace v2 不提供逐语句赋值后的实际值;View 只能展示 Analysis 中的静态参数与赋值目标,绝不猜测运行时数据。" + ); + break; + case "memory": + showUnsupported( + "内存快照", + "当前公开协议没有内存观测通道;该能力需等待未来独立、受权限审计的调试协议。" + ); + break; + case "about": + openDialog("mq-dialog-about"); + break; + case "run": + // Until the explicit-run flow is implemented, never pretend to run. + showUnsupported( + "运行文档", + "首版运行入口需要显式的风险评估与 CSRF 会话确认;在实现前该按钮不会执行任何文档。" + ); + break; + case "clear": + var panel = $("#mq-run-panel"); + if (panel) panel.hidden = true; + toast("已清理本地展示状态(源文件与缓存未修改)"); + break; + default: + break; + } + } + + document.addEventListener("click", function (event) { + var trigger = event.target.closest ? event.target.closest("[data-action]") : null; + if (!trigger) return; + event.preventDefault(); + handleAction(trigger.dataset.action); + }); + + document.addEventListener("click", function (event) { + var link = event.target.closest ? event.target.closest("[data-goto-anchor]") : null; + if (link) { + event.preventDefault(); + gotoAnchor(link.dataset.gotoAnchor); + return; + } + var lineLink = event.target.closest ? event.target.closest("[data-goto-line]") : null; + if (lineLink) { + event.preventDefault(); + var line = parseInt(lineLink.dataset.gotoLine, 10); + if (!isNaN(line)) gotoSourceLine(line); + } + }); + + document.addEventListener("input", function (event) { + if (event.target && event.target.id === "mq-search-input") { + renderSearch(event.target.value); + } + }); + + document.addEventListener("keydown", function (event) { + var isMac = /Mac|iPhone|iPad/.test(navigator.platform || ""); + var modifier = isMac ? event.metaKey : event.ctrlKey; + if (modifier && (event.key === "k" || event.key === "K")) { + event.preventDefault(); + showSearch(); + return; + } + if (event.key === "Escape") { + closeAllDialogs(); + } + }); + + document.addEventListener("toggle", function (event) { + if (event.target && event.target.classList.contains("mq-diagnostics")) { + try { + window.localStorage.setItem("marqdo.view.diagnostics", event.target.open ? "1" : "0"); + } catch (error) { + /* storage is optional */ + } + } + }, true); + + // Restore a URL-selected mode, then honour the persisted diagnostics state. + try { + var params = new URLSearchParams(window.location.search); + if (params.get("mode") === "source") setMode("source"); + else setMode("document"); + var diagnosticsState = window.localStorage.getItem("marqdo.view.diagnostics"); + if (diagnosticsState === "1") { + $$(".mq-diagnostics").forEach(function (details) { + details.open = true; + }); + } + } catch (error) { + setMode("document"); + } + + // Keep dock buttons visible above the last line on small screens. + function syncDockInset() { + var dock = $(".mq-dock"); + if (!dock) return; + var height = dock.getBoundingClientRect().height + 36; + reader.style.setProperty("--mq-dock-h", Math.round(height) + "px"); + } + if (typeof ResizeObserver !== "undefined") { + var dock = $(".mq-dock"); + if (dock) new ResizeObserver(syncDockInset).observe(dock); + } + window.addEventListener("resize", syncDockInset); + syncDockInset(); +})(); diff --git a/docs/ADR/0003-heading-prefix-and-anchor-identity.md b/docs/ADR/0003-heading-prefix-and-anchor-identity.md new file mode 100644 index 0000000..341d7a1 --- /dev/null +++ b/docs/ADR/0003-heading-prefix-and-anchor-identity.md @@ -0,0 +1,27 @@ +# ADR-0003:显示层标题前缀剥离与文档内锚点身份 + +- 状态:Accepted +- 日期:2026-11-22 +- 关联:RFC-VIEW-0001 §5.2、§8.2、§8.3;PR-02 + +## 背景 + +`@exec` / `@knowledge` 是标题语义声明,但 Markdown 标题的**显示文本**不应把声明前缀当作正文主标题重复展示。与此同时,语义标注必须能稳定指向源码位置,而且不能在标题重名时产生重复 DOM id。Analysis v2 公开字段中: + +- `units[]` 没有单独的“本标题的 mode”字段(RFC §4.3 已警告不得把 `kind=section` 当成 Exec/Knowledge); +- `functions[].heading_span` 与 `units[].span` 对 ATX 标题精确对应,可作为锚点来源; +- 继承模式无法从公开 JSON 直接读出。 + +## 决策 + +1. **标题前缀只在显示层剥离**:仅当标题文本以精确的 `@exec ` 或 `@knowledge ` 开头,且剥离后的空白折叠结果等于 Analysis `units[].name` 时,才视为合法声明并剥离;同时输出 `mq-mode-badge`。`@Exec`、拼写变体、`**@exec**` 等一律原样显示(Core 会给出诊断)。Source 态永远显示原始字节,因此剥离是可逆的显示规则,不是改写源文件。 +2. **不猜测继承模式**:没有显式声明前缀的 H3–H6 不渲染 EXEC/KNOWLEDGE 徽标,`data-semantic="document"`;H2 function 由 `functions[]` 精确映射为 `exec`,H2 knowledge 由 `units[].kind=knowledge` 映射为 `knowledge`。 +3. **锚点 id 来自源码 span**:`id="mq-h--"`,由标题自身的 UTF-8 半开区间派生;函数大纲使用同一条 `heading_span`,保证“函数列表跳转”与正文标题命中同一个 id。禁止用标题文本、序号或随机数生成 id(重名会跳错)。 +4. **语义装饰锚点 id** 使用 RFC §8.3 的 `sha256(module_id + "\0" + start + ":" + end + ":" + kind)[0..16]`;它只在本页 DOM 内有效,不跨编辑/跨运行复用。 +5. 任何无法通过 `SourceIndex` 验证的 span(越界、非 UTF-8 边界)直接丢弃该条装饰并产生 `view.source_span_invalid` 警告,绝不把它吸附到相邻文字。 + +## 后果 + +- 同页多个 H2/H3 永远得到不同 id;`tests/rendering.rs::semantic_annotations_come_from_analysis_and_are_unique` 断言唯一性。 +- Setext 标题没有合法前缀声明,会被原样显示并沿用自身 span 锚点;如果未来需要更精确的继承模式标注,必须通过新的公开协议字段实现,不能在 JS/CSS 里猜。 +- 标题显示与源码态自动保持一致;无需额外“复制原文”逻辑。 diff --git a/docs/STATUS.md b/docs/STATUS.md index c1db1c3..f509d81 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -22,8 +22,8 @@ |---|---|---| | PR-00 基线与旧 View 取证 | **完成** | `docs/audits/legacy-render-paths.md`、`docs/design/visual-tokens.md`、`docs/design/state-matrix.md`、ADR-0001/0002 | | PR-01 Tool v1 安装闭环 | **完成** | `tool.json`、`tools/package.sh`、`tools/install-smoke.sh`、`tests/core_contract.rs`、`tests/no_coupling.rs` | -| PR-02 DocumentModel + Analysis v2 浏览 | 未开始 | — | -| PR-03 Reader 视觉重建 | 未开始 | — | +| PR-02 DocumentModel + Analysis v2 浏览 | **完成** | `src/document.rs`、`src/semantic.rs`、`src/presentation.rs`、`src/render.rs`、`src/server.rs`、`tests/rendering.rs`、`tests/http_live.rs`、`tests/golden/analysis-v2/`(冻结 CLI 生成) | +| PR-03 Reader 视觉重建 | 进行中(基础主题已就绪) | `assets/reader.css`/`assets/reader.js` 单一入口,`tests/asset_integrity.rs`;完整欢迎页/响应式截图待补 | | PR-04 Trace v2 运行可视化 | 未开始 | — | | PR-05 Live 安全 + 静态导出 | 未开始 | — | | PR-06 冻结 CLI 端到端验收 | 未开始 | — | @@ -31,7 +31,10 @@ ## 证据与限制 - 旧 View 运行时状态:`LEGACY_RUNTIME_UNVERIFIED`(旧仓库无预编译产物,且任务禁止修改/编译旧仓库;只做只读静态审计)。 -- PR-01 起 `marqdo view --help/--version/verify` 由本程序提供;`browse`/`export` 仍返回 `view.unsupported`(PR-02/PR-05 落地)。 +- PR-01 起 `marqdo view --help/--version/verify` 由本程序提供;PR-02 起 `marqdo view [PATH]` 提供本机只读浏览。 +- `export` 仍返回 `view.unsupported`(PR-05 落地);运行入口仍显式“未启用”(PR-04)。 - 冻结 CLI 安装烟测通过前不得声称 Tool v1 闭环可用;证据由 `tools/install-smoke.sh` 生成。 +- PR-02 的 Analysis golden 全部由冻结 CLI `check --emit` 生成(见 `tests/golden/README.md`);`examples/diagnostics` 故意 check 失败且没有 golden。 +- 已知限制:运行/变量值/内存/证明状态仍不可用且标为 UNSUPPORTED;`export` 未实现;浏览器截图验收在 PR-06。 - 已核对旧视觉资产许可(旧仓库 Apache-2.0):logo/blossom/feather 可复用,KaTeX 不引入。 - 已知非目标:变量运行值、内存快照、调试器、Prove/Knowledge/Lint 引擎(均标 `UNSUPPORTED`)。 diff --git a/examples/control-flow/index.mq.md b/examples/control-flow/index.mq.md new file mode 100644 index 0000000..3bc8c65 --- /dev/null +++ b/examples/control-flow/index.mq.md @@ -0,0 +1,27 @@ +# @knowledge 控制流演示 + +下面的函数没有任何必需参数,因此可以在 `pure` 模式下显式运行并产生真实 Trace。 + +# @exec 演示 + +## @exec main + +`x = 0` + +**while x < 3** + +**if x > 1** + +**print(x)** + +**else** + +**print(0)** + +**end** + +**x = x + 1** + +**end** + +`return 3` diff --git a/examples/control-flow/marqdo.yaml b/examples/control-flow/marqdo.yaml new file mode 100644 index 0000000..28de26e --- /dev/null +++ b/examples/control-flow/marqdo.yaml @@ -0,0 +1,3 @@ +project: + name: control-flow + version: 0.1.0 diff --git a/examples/diagnostics/index.mq.md b/examples/diagnostics/index.mq.md new file mode 100644 index 0000000..3682a0b --- /dev/null +++ b/examples/diagnostics/index.mq.md @@ -0,0 +1,11 @@ +# @knowledge 诊断演示 + +这份源码故意不合法:`if` 没有在同一个标题段落内闭合,Core `check` 会给出诊断。 + +# @exec 演示 + +## @exec main + +**if x > 0** + +`return 1` diff --git a/examples/diagnostics/marqdo.yaml b/examples/diagnostics/marqdo.yaml new file mode 100644 index 0000000..be9989c --- /dev/null +++ b/examples/diagnostics/marqdo.yaml @@ -0,0 +1,3 @@ +project: + name: diagnostics-demo + version: 0.1.0 diff --git a/examples/mixed-modes/index.mq.md b/examples/mixed-modes/index.mq.md new file mode 100644 index 0000000..49645ca --- /dev/null +++ b/examples/mixed-modes/index.mq.md @@ -0,0 +1,31 @@ +# @knowledge 计算笔记 + +这是一份关于简单运算的知识说明。**此处加粗是知识内容,不执行。** + +## @knowledge 算法说明 + +下面描述算法的含义和适用范围;此处的 `n` 是惰性正文。 + +# @exec 演示 + +## @exec main + +`params(n: Int)` + +### @knowledge 用法 + +调用方提供整数 `n`。这一小节不应该执行任何语句。 + +### @exec 计算 + +**if n > 0** + +`result = n * 2` + +*return result* + +**else** + +`return 0` + +**end** diff --git a/examples/mixed-modes/marqdo.yaml b/examples/mixed-modes/marqdo.yaml new file mode 100644 index 0000000..01f63ac --- /dev/null +++ b/examples/mixed-modes/marqdo.yaml @@ -0,0 +1,3 @@ +project: + name: mixed-modes + version: 0.1.0 diff --git a/examples/tables-math/index.mq.md b/examples/tables-math/index.mq.md new file mode 100644 index 0000000..82c845a --- /dev/null +++ b/examples/tables-math/index.mq.md @@ -0,0 +1,21 @@ +# @knowledge 表格、公式与惰性资源 + +| 名称 | 值 | 说明 | +| --- | ---: | --- | +| 甲 | 1 | 第一行 | +| 乙 | 2 | 第二行 | + +行内公式 $E = mc^2$;块公式: + +$$ +\sum_{i=1}^{n} i = \frac{n(n+1)}{2} +$$ + +```python +print("代码围栏永远是惰性资源") +``` + +- [x] 任务列表可读 +- [ ] 不会触发任何执行 + +外部链接:[Marqdo CLI](https://github.com/cflmy/marqdo-cli)。 diff --git a/examples/tables-math/marqdo.yaml b/examples/tables-math/marqdo.yaml new file mode 100644 index 0000000..a950b2e --- /dev/null +++ b/examples/tables-math/marqdo.yaml @@ -0,0 +1,3 @@ +project: + name: tables-math + version: 0.1.0 diff --git a/examples/welcome/00-welcome.mq.md b/examples/welcome/00-welcome.mq.md new file mode 100644 index 0000000..bfb4ac6 --- /dev/null +++ b/examples/welcome/00-welcome.mq.md @@ -0,0 +1,15 @@ +# @knowledge 欢迎来到 Marqdo + +Marqdo 把 Markdown 当作可执行文档的语言:标题声明 `@exec` / `@knowledge` 模式, +强调、斜体与行内代码是**等价的单语句载体**,而 `if` / `else` / `while` / `end` / +`return` 决定真正的操作。 + +| 阅读态 | 内容 | 是否执行 | +| --- | --- | --- | +| 文档 | 原始 Markdown 排版 | 否 | +| 源码 | 逐行原文,包含全部标记 | 否 | +| 运行 | 用户显式确认后才出现 | 是(需要确认) | + +继续阅读:[语法演示](./guide.mq.md)。 + +> 这份欢迎页只是 `view.json` 显式指定的站点首页,普通 `welcome` 文件名不会自动变成 Hero。 diff --git a/examples/welcome/guide.mq.md b/examples/welcome/guide.mq.md new file mode 100644 index 0000000..9644272 --- /dev/null +++ b/examples/welcome/guide.mq.md @@ -0,0 +1,17 @@ +# @knowledge 阅读指南 + +## @knowledge 三种视图 + +文档态是默认视图;源码态保留原文字节;运行态只在用户点击“运行”并确认后出现。 + +## @knowledge 公式与代码 + +行内公式 $a^2 + b^2 = c^2$ 是惰性资源;围栏代码同样从不自动执行: + +```rust +fn main() { + println!("这段代码只是文档内容"); +} +``` + +回到[欢迎页](./00-welcome.mq.md)。 diff --git a/examples/welcome/marqdo.yaml b/examples/welcome/marqdo.yaml new file mode 100644 index 0000000..2e8d836 --- /dev/null +++ b/examples/welcome/marqdo.yaml @@ -0,0 +1,3 @@ +project: + name: welcome-demo + version: 0.1.0 diff --git a/examples/welcome/view.json b/examples/welcome/view.json new file mode 100644 index 0000000..b78a6d5 --- /dev/null +++ b/examples/welcome/view.json @@ -0,0 +1,7 @@ +{ + "schema": "marqdo.view-config", + "schema_version": 1, + "welcome": "./00-welcome.mq.md", + "site_title": "Marqdo", + "theme": "botanical" +} diff --git a/src/app.rs b/src/app.rs index 862bdb9..db57525 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,16 +1,157 @@ //! Application layer: turns parsed commands into use cases. //! -//! No HTML is built here; no Markdown is parsed here. Browse uses the single -//! renderer (PR-02+), verify only checks bindings, export only writes static -//! files through the same renderer (PR-05). +//! No HTML is built here and no Markdown semantics are decided here. Browse and +//! (later) Export call the same `load` + one `ReaderRenderer`. use crate::cli::{ExportArgs, RuntimeOpts, VerifyArgs}; -use crate::core_client::{CheckOptions, CoreClient}; +use crate::core_client::{CheckOptions, CheckResponse, CoreClient, RawCheckDiagnostic}; +use crate::document::{DocumentIdentity, DocumentModel}; use crate::error::{ViewError, ViewResult}; -use crate::project::Project; -use crate::source_map::sha256_hex; +use crate::presentation::{self, BuildInput, Navigation, PresentationModel, SourceStatus}; +use crate::project::{Project, SafeRelativePath, ViewConfig}; +use crate::semantic::{self, CoreDiagnostic}; use crate::version; +/// Process-wide context for one browsed project: root, optional site config and +/// an optional negotiated frozen core. A missing core degrades to prose only; +/// an incompatible protocol is a hard error (RFC §4). +pub struct AppContext { + project: Project, + config: ViewConfig, + core: Option, + core_version: Option, + core_note: Option, +} + +impl AppContext { + pub fn open(path: &std::path::Path, marqdo_bin: Option<&std::path::Path>) -> ViewResult { + let project = Project::open(path)?; + let config = ViewConfig::load(project.root())?; + let (core, core_version, core_note) = match CoreClient::from_env(marqdo_bin) { + Ok(client) => match client.negotiate() { + Ok(version) => (Some(client), Some(version.version.to_string()), None), + Err(err) if err.code() == "view.protocol_incompatible" => return Err(err), + Err(err) => (None, None, Some(generic_core_note(&err))), + }, + Err(err) if err.code() == "view.core_missing" => { + (None, None, Some(generic_core_note(&err))) + } + Err(err) => return Err(err), + }; + Ok(Self { + project, + config, + core, + core_version, + core_note, + }) + } + + pub fn project(&self) -> &Project { + &self.project + } + + pub fn config(&self) -> &ViewConfig { + &self.config + } + + pub fn core(&self) -> Option<&CoreClient> { + self.core.as_ref() + } + + pub fn core_version(&self) -> Option<&str> { + self.core_version.as_deref() + } + + pub fn core_note(&self) -> Option<&str> { + self.core_note.as_deref() + } + + /// Read + parse + (optionally) check one document into the one presentation + /// model. Never executes the document. + pub fn load(&self, relative: &SafeRelativePath) -> ViewResult { + let source_bytes = self.project.read_source(relative)?; + let source = String::from_utf8(source_bytes).map_err(|err| ViewError::Io { + detail: format!("{relative} is not valid UTF-8: {err}"), + })?; + let document = DocumentModel::parse(source, DocumentIdentity::placeholder(relative)); + let navigation = Navigation::from_project(&self.project, &self.config, relative); + + let mut status = SourceStatus::CoreUnavailable; + let mut status_note = self.core_note.clone(); + let mut diagnostics = Vec::new(); + let mut verified = None; + + if let Some(client) = &self.core { + match client.check(&self.project, relative, &CheckOptions::default())? { + CheckResponse { + success: false, + diagnostics: raw_diagnostics, + exit_code, + .. + } => { + status = SourceStatus::CoreError; + status_note = Some(format!( + "Core 检查失败(exit {exit_code}):语义标注已撤销,正文仍可阅读。" + )); + diagnostics = raw_diagnostics + .iter() + .map(|diagnostic| diagnostic_to_view(diagnostic, relative)) + .collect(); + } + CheckResponse { + success: true, + analysis: Some(check), + .. + } => match semantic::verify_analysis( + &check.analysis_bytes, + &document.source, + &document.source_index, + relative.as_str(), + ) { + Ok(verified_analysis) => { + status = SourceStatus::StaticOk; + status_note = None; + verified = Some(verified_analysis); + } + Err(err) if err.code() == "view.source_mismatch" => { + status = SourceStatus::SourceMismatch; + status_note = Some( + "当前源码字节与 Analysis 的 source_digest 不一致,语义标注已禁用。" + .to_string(), + ); + } + Err(err) if err.code() == "view.protocol_incompatible" => { + return Err(err); + } + Err(err) => { + status = SourceStatus::CoreError; + status_note = Some(generic_core_note(&err)); + } + }, + CheckResponse { + success: true, + analysis: None, + .. + } => { + status = SourceStatus::CoreError; + status_note = Some("Core 声称检查成功但没有产出 Analysis。".to_string()); + } + } + } + + Ok(presentation::build(BuildInput { + document, + analysis: verified.as_ref(), + status, + status_note, + diagnostics, + navigation, + core_version: self.core_version.clone(), + })) + } +} + pub fn verify(opts: &RuntimeOpts, args: &VerifyArgs) -> ViewResult { let path = args .path @@ -20,14 +161,14 @@ pub fn verify(opts: &RuntimeOpts, args: &VerifyArgs) -> ViewResult { let project = Project::open(&path)?; let entry = project.entry().relative.clone(); let source_bytes = project.read_source(&entry)?; - let source_text = String::from_utf8(source_bytes.clone()).map_err(|err| ViewError::Io { + let source = String::from_utf8(source_bytes).map_err(|err| ViewError::Io { detail: format!("{entry} is not valid UTF-8: {err}"), })?; - let _ = source_text; + let source_index = crate::source_map::SourceIndex::new(&source); let client = CoreClient::from_env(opts.marqdo_bin.as_deref())?; let core_version = client.negotiate()?; - let check = client.check( + let response = client.check( &project, &entry, &CheckOptions { @@ -35,12 +176,51 @@ pub fn verify(opts: &RuntimeOpts, args: &VerifyArgs) -> ViewResult { timeout: None, }, )?; - - let analysis: serde_json::Value = - serde_json::from_slice(&check.analysis_bytes).map_err(|err| ViewError::AnalysisFailed { - detail: format!("emitted Analysis is not JSON: {err}"), - })?; - let summary = validate_static_binding(&analysis, entry.as_str(), &source_bytes)?; + let check = match response { + CheckResponse { + success: false, + diagnostics, + exit_code, + .. + } => { + let first = diagnostics + .first() + .map(|diagnostic| { + format!( + "{}: {}", + if diagnostic.code.is_empty() { + "diagnostic" + } else { + &diagnostic.code + }, + diagnostic.message + ) + }) + .unwrap_or_else(|| "no diagnostic detail".to_string()); + return Err(ViewError::AnalysisFailed { + detail: format!( + "`marqdo check` failed with exit code {exit_code} ({} diagnostic(s)); first: {first}", + diagnostics.len() + ), + }); + } + CheckResponse { + analysis: Some(check), + .. + } => check, + CheckResponse { analysis: None, .. } => { + return Err(ViewError::AnalysisFailed { + detail: "`marqdo check` succeeded but emitted no Analysis".to_string(), + }) + } + }; + let verified = semantic::verify_analysis( + &check.analysis_bytes, + &source, + &source_index, + entry.as_str(), + )?; + let projection = &verified.projection; if args.json { let doc = serde_json::json!({ @@ -53,17 +233,24 @@ pub fn verify(opts: &RuntimeOpts, args: &VerifyArgs) -> ViewResult { }, "analysis": { "schema": "marqdo.analysis", - "schema_version": 2, - "digest": check.analysis_digest, - "producer_version": summary.producer_version, + "schema_version": version::ANALYSIS_PROTOCOL, + "digest": projection.analysis_digest, + "producer_version": projection.producer_version, + "markdown_profile": projection.markdown_profile, + "functions": projection.functions.len(), + "units": projection.units.len(), + "diagnostics": projection.diagnostics.len(), }, "project": { - "root_id": summary.root_id, - "identity_kind": summary.identity_kind, + "root_id": projection.project_root_id, + "identity_kind": projection.identity_kind, + "lock_digest": projection.lock_digest, + "stdlib_version": projection.stdlib_version, }, "document": { "relative_path": entry.as_str(), - "source_digest": summary.source_digest, + "module_id": projection.module_id, + "source_digest": projection.source_digest, "source_digest_matches": true, }, "result": "PASS", @@ -80,11 +267,16 @@ pub fn verify(opts: &RuntimeOpts, args: &VerifyArgs) -> ViewResult { core_version.version, version::PRODUCT_RANGE ); - println!("project: {} ({})", summary.root_id, summary.identity_kind); - println!("document: {}", entry); println!( - "analysis: schema=marqdo.analysis v2 modules={} digest={}", - summary.module_count, check.analysis_digest + "project: {} ({})", + projection.project_root_id, projection.identity_kind + ); + println!("document: {entry}"); + println!( + "analysis: schema=marqdo.analysis v2 modules={} functions={} digest={}", + projection.modules.len(), + projection.functions.len(), + projection.analysis_digest ); println!("source digest: match"); println!("result: PASS (static only; document not executed)"); @@ -92,130 +284,59 @@ pub fn verify(opts: &RuntimeOpts, args: &VerifyArgs) -> ViewResult { Ok(0) } +pub fn browse(opts: &RuntimeOpts) -> ViewResult { + let path = opts + .path + .clone() + .unwrap_or_else(|| std::path::PathBuf::from(".")); + let context = AppContext::open(&path, opts.marqdo_bin.as_deref())?; + crate::server::serve(context, opts) +} + pub fn export(_opts: &RuntimeOpts, _args: &ExportArgs) -> ViewResult { Err(ViewError::Unsupported { - detail: "static export lands with PR-05; this build teaches Tool Protocol and statics only" + detail: "static export lands with PR-05; browse and verify are available in this build" .to_string(), }) } -pub fn browse(_opts: &RuntimeOpts) -> ViewResult { - Err(ViewError::Unsupported { - detail: "the Live reader lands with PR-02/PR-03; this build teaches Tool Protocol and statics only" - .to_string(), - }) +fn generic_core_note(err: &ViewError) -> String { + match err.code() { + "view.core_missing" => { + "未找到可用的冻结核心(MARQDO_BIN);当前为无语义标注的纯 Markdown 阅读模式。" + .to_string() + } + "view.analysis_failed" => "Core 检查失败;语义标注已撤销,正文仍可阅读。".to_string(), + other => format!("{other}:语义标注不可用,正文仍可阅读。"), + } } -struct BindingSummary { - root_id: String, - identity_kind: String, - producer_version: String, - module_count: usize, - source_digest: String, -} - -/// Structural binding checks that do not need the full typed projection yet -/// (the typed `SemanticProjection` replaces this in PR-02 without changing the -/// externally visible `verify` result). -fn validate_static_binding( - analysis: &serde_json::Value, - relative_path: &str, - source_bytes: &[u8], -) -> ViewResult { - let schema = analysis - .get("schema") - .and_then(|v| v.as_str()) - .unwrap_or(""); - if schema != "marqdo.analysis" { - return Err(ViewError::ProtocolIncompatible { - detail: format!("unexpected Analysis schema {schema:?}"), - }); +fn diagnostic_to_view( + diagnostic: &RawCheckDiagnostic, + relative: &SafeRelativePath, +) -> CoreDiagnostic { + let belongs_to_entry = diagnostic + .module + .as_deref() + .map(|module| module.ends_with(relative.as_str())) + .unwrap_or(true); + CoreDiagnostic { + module: diagnostic.module.clone(), + relative_path: if belongs_to_entry { + Some(relative.as_str().to_string()) + } else { + None + }, + span: None, + line: diagnostic.line, + column: diagnostic.column, + severity: if diagnostic.severity.is_empty() { + "error".to_string() + } else { + diagnostic.severity.clone() + }, + code: diagnostic.code.clone(), + message: diagnostic.message.clone(), + hints: diagnostic.hints.clone(), } - match analysis.get("schema_version").and_then(|v| v.as_u64()) { - Some(2) => {} - other => { - return Err(ViewError::ProtocolIncompatible { - detail: format!( - "Analysis schema_version {other:?} is not supported (View implements v{})", - version::ANALYSIS_PROTOCOL - ), - }) - } - } - let producer = analysis - .get("producer") - .ok_or_else(|| ViewError::AnalysisFailed { - detail: "Analysis is missing producer".to_string(), - })?; - let producer_version = producer - .get("version") - .and_then(|v| v.as_str()) - .unwrap_or("") - .to_string(); - let markdown_profile = producer - .get("markdown_profile") - .and_then(|v| v.as_str()) - .unwrap_or(""); - if markdown_profile != "marqdo.md.v1" { - return Err(ViewError::ProtocolIncompatible { - detail: format!( - "unexpected Markdown profile {markdown_profile:?}; this View targets marqdo.md.v1" - ), - }); - } - let project = analysis - .get("project") - .ok_or_else(|| ViewError::AnalysisFailed { - detail: "Analysis is missing project".to_string(), - })?; - let root_id = project - .get("root_id") - .and_then(|v| v.as_str()) - .unwrap_or("") - .to_string(); - if root_id.is_empty() { - return Err(ViewError::AnalysisFailed { - detail: "Analysis project.root_id is empty".to_string(), - }); - } - let identity_kind = project - .get("identity_kind") - .and_then(|v| v.as_str()) - .unwrap_or("") - .to_string(); - let modules = analysis - .get("modules") - .and_then(|v| v.as_array()) - .ok_or_else(|| ViewError::AnalysisFailed { - detail: "Analysis is missing modules[]".to_string(), - })?; - let expected_digest = sha256_hex(source_bytes); - let mut matches = 0usize; - for module in modules { - if module.get("relative_path").and_then(|v| v.as_str()) == Some(relative_path) { - matches += 1; - let digest = module - .get("source_digest") - .and_then(|v| v.as_str()) - .unwrap_or(""); - if digest != expected_digest { - return Err(ViewError::SourceMismatch { - expected: digest.to_string(), - actual: expected_digest, - }); - } - } - } - if matches == 0 { - return Err(ViewError::AnalysisFailed { - detail: format!("Analysis has no module for {relative_path}"), - }); - } - Ok(BindingSummary { - root_id, - identity_kind, - producer_version, - module_count: modules.len(), - source_digest: expected_digest, - }) } diff --git a/src/assets.rs b/src/assets.rs new file mode 100644 index 0000000..3a912f6 --- /dev/null +++ b/src/assets.rs @@ -0,0 +1,238 @@ +//! The single embedded asset bundle. +//! +//! Live serving and static export both read these exact bytes (ADR-0002). Every +//! asset carries its SHA-256; browser URLs use a hash prefix so a changed asset +//! can never be confused with a cached older one. + +use crate::source_map::sha256_hex; +use std::collections::HashMap; +use std::sync::OnceLock; + +#[derive(Clone)] +pub struct Asset { + pub name: &'static str, + pub extension: &'static str, + pub mime: &'static str, + pub bytes: &'static [u8], + /// Lowercase hex SHA-256 of `bytes`. + pub sha256: String, +} + +impl Asset { + /// Hashed file name, e.g. `reader.1a2b3c4d5e6f7788.css`. + pub fn hashed_name(&self) -> String { + format!("{}.{}.{}", self.name, &self.sha256[..16], self.extension) + } + + pub fn data_uri(&self) -> String { + format!("data:{};base64,{}", self.mime, base64(self.bytes)) + } +} + +pub struct AssetBundle { + assets: Vec, + by_hashed_name: HashMap, + /// CSS with the two image placeholders replaced by data URIs, so there is + /// still exactly one stylesheet and no extra network request. + css_with_images: String, + css_served_sha256: String, +} + +impl AssetBundle { + fn new() -> Self { + let assets = vec![ + asset( + "reader", + "css", + "text/css; charset=utf-8", + include_bytes!("../assets/reader.css"), + ), + asset( + "reader", + "js", + "text/javascript; charset=utf-8", + include_bytes!("../assets/reader.js"), + ), + asset( + "logo", + "svg", + "image/svg+xml", + include_bytes!("../assets/logo.svg"), + ), + asset( + "blossom", + "webp", + "image/webp", + include_bytes!("../assets/blossom.webp"), + ), + asset( + "feather", + "webp", + "image/webp", + include_bytes!("../assets/feather.webp"), + ), + ]; + let mut by_hashed_name = HashMap::new(); + for (index, asset) in assets.iter().enumerate() { + by_hashed_name.insert(asset.hashed_name(), index); + } + let css_text = std::str::from_utf8(assets[0].bytes).expect("reader.css is UTF-8"); + let css_with_images = css_text + .replace("__BLOSSOM__", &assets[3].data_uri()) + .replace("__FEATHER__", &assets[4].data_uri()); + let css_served_sha256 = sha256_hex(css_with_images.as_bytes()); + Self { + assets, + by_hashed_name, + css_with_images, + css_served_sha256, + } + } + + pub fn get() -> &'static AssetBundle { + static BUNDLE: OnceLock = OnceLock::new(); + BUNDLE.get_or_init(AssetBundle::new) + } + + pub fn all(&self) -> &[Asset] { + &self.assets + } + + pub fn css(&self) -> &Asset { + &self.assets[0] + } + + pub fn js(&self) -> &Asset { + &self.assets[1] + } + + pub fn logo(&self) -> &Asset { + &self.assets[2] + } + + pub fn by_path(&self, hashed_name: &str) -> Option<&Asset> { + self.by_hashed_name + .get(hashed_name) + .map(|index| &self.assets[*index]) + } + + pub fn css_bytes(&self) -> &[u8] { + self.css_with_images.as_bytes() + } + + /// SHA-256 of the served CSS (after image substitution). + pub fn css_served_sha256(&self) -> &str { + &self.css_served_sha256 + } + + pub fn hashed_css_name(&self) -> String { + format!("reader.{}.css", &self.css_served_sha256[..16]) + } + + pub fn hashed_js_name(&self) -> String { + self.js().hashed_name() + } +} + +fn asset( + name: &'static str, + extension: &'static str, + mime: &'static str, + bytes: &'static [u8], +) -> Asset { + Asset { + name, + extension, + mime, + bytes, + sha256: sha256_hex(bytes), + } +} + +/// Minimal standard base64 (RFC 4648) encoder for data URIs. +fn base64(bytes: &[u8]) -> String { + const TABLE: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + let mut out = String::with_capacity(bytes.len().div_ceil(3) * 4); + for chunk in bytes.chunks(3) { + let b0 = chunk[0] as u32; + let b1 = chunk.get(1).copied().unwrap_or(0) as u32; + let b2 = chunk.get(2).copied().unwrap_or(0) as u32; + let triple = (b0 << 16) | (b1 << 8) | b2; + out.push(TABLE[(triple >> 18) as usize & 0x3f] as char); + out.push(TABLE[(triple >> 12) as usize & 0x3f] as char); + out.push(if chunk.len() > 1 { + TABLE[(triple >> 6) as usize & 0x3f] as char + } else { + '=' + }); + out.push(if chunk.len() > 2 { + TABLE[triple as usize & 0x3f] as char + } else { + '=' + }); + } + out +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn bundle_digests_match_source_files() { + let bundle = AssetBundle::get(); + assert_eq!( + bundle.css().sha256, + sha256_hex(include_bytes!("../assets/reader.css")) + ); + assert_eq!( + bundle.js().sha256, + sha256_hex(include_bytes!("../assets/reader.js")) + ); + assert_eq!( + bundle.logo().sha256, + sha256_hex(include_bytes!("../assets/logo.svg")) + ); + assert_eq!(bundle.assets[3].sha256.len(), 64); + assert!(bundle.by_path(&bundle.logo().hashed_name()).is_some()); + assert!(bundle.by_path("missing.css").is_none()); + // Exactly one theme and one script entry. + let css_count = bundle + .all() + .iter() + .filter(|asset| asset.extension == "css") + .count(); + let js_count = bundle + .all() + .iter() + .filter(|asset| asset.extension == "js") + .count(); + assert_eq!(css_count, 1); + assert_eq!(js_count, 1); + } + + #[test] + fn css_substitutes_images_and_keeps_one_asset() { + let bundle = AssetBundle::get(); + let css = std::str::from_utf8(bundle.css_bytes()).unwrap(); + assert!(!css.contains("__BLOSSOM__")); + assert!(!css.contains("__FEATHER__")); + assert!(css.contains("data:image/webp;base64,")); + assert!(bundle.hashed_css_name().starts_with("reader.")); + assert_eq!( + bundle.hashed_css_name().len(), + "reader.".len() + 16 + ".css".len() + ); + } + + #[test] + fn base64_matches_known_vectors() { + assert_eq!(base64(b""), ""); + assert_eq!(base64(b"f"), "Zg=="); + assert_eq!(base64(b"fo"), "Zm8="); + assert_eq!(base64(b"foo"), "Zm9v"); + assert_eq!(base64(b"foob"), "Zm9vYg=="); + assert_eq!(base64(b"fooba"), "Zm9vYmE="); + assert_eq!(base64(b"foobar"), "Zm9vYmFy"); + } +} diff --git a/src/core_client.rs b/src/core_client.rs index cd461fd..127ab4f 100644 --- a/src/core_client.rs +++ b/src/core_client.rs @@ -106,6 +106,37 @@ pub struct CheckOutput { pub stderr: String, } +/// One compile diagnostic from `check --json`, normalized so no absolute +/// machine path can leak into pages, exports or logs. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RawCheckDiagnostic { + #[serde(default)] + pub code: String, + #[serde(default)] + pub severity: String, + #[serde(default)] + pub message: String, + #[serde(default)] + pub line: Option, + #[serde(default)] + pub column: Option, + #[serde(default)] + pub module: Option, + #[serde(default)] + pub hints: Vec, +} + +/// Result of one `check` invocation. A failed check is **not** an I/O error: +/// the prose stays readable and diagnostics must be shown (RFC §12.3). +#[derive(Debug)] +pub struct CheckResponse { + pub success: bool, + pub analysis: Option, + pub diagnostics: Vec, + pub exit_code: i32, + pub stderr: String, +} + #[derive(Debug)] pub struct RunOutput { /// Exactly one JSON document emitted on stdout by the Core. @@ -267,19 +298,20 @@ impl CoreClient { Ok(version) } - /// `check --emit`; on success returns the exact Analysis v2 bytes. + /// `check --json --emit`. On success the exact Analysis v2 bytes are + /// returned; on failure the structured diagnostics are returned without + /// any absolute path. Only spawn/timeout/IO failures are hard errors. pub fn check( &self, project: &Project, relative: &SafeRelativePath, options: &CheckOptions, - ) -> ViewResult { + ) -> ViewResult { let entry = project.absolute_for(relative)?; let scratch = ScratchDir::create("check")?; let emit = scratch.file("analysis.json"); let mut args = build_check_args(&entry); - - // Scratch path is ours; the argument vector is explicit, no shell. + args.push(OsString::from("--json")); args.push(OsString::from("--emit")); args.push(emit.clone().into_os_string()); if options.refs { @@ -291,13 +323,32 @@ impl CoreClient { project.root(), options.timeout.unwrap_or(DEFAULT_CHECK_TIMEOUT), )?; - if output.exit_code != 0 { - return Err(ViewError::AnalysisFailed { - detail: format!( - "`marqdo check` failed with exit code {}: {}", - output.exit_code, - summarize_stderr(&output.stderr) - ), + let check_json: Option = + serde_json::from_slice(&output.stdout_bytes).ok(); + let success = output.exit_code == 0 + && check_json + .as_ref() + .and_then(|json| json.get("success")) + .and_then(serde_json::Value::as_bool) + .unwrap_or(true); + let diagnostics = check_json + .as_ref() + .and_then(|json| json.get("diagnostics")) + .and_then(serde_json::Value::as_array) + .map(|items| { + items + .iter() + .filter_map(|item| serde_json::from_value(item.clone()).ok()) + .collect::>() + }) + .unwrap_or_default(); + if !success { + return Ok(CheckResponse { + success: false, + analysis: None, + diagnostics, + exit_code: output.exit_code, + stderr: output.stderr, }); } let analysis_bytes = std::fs::read(&emit).map_err(|err| ViewError::AnalysisFailed { @@ -311,12 +362,18 @@ impl CoreClient { detail: "`marqdo check` emitted an empty Analysis file".to_string(), }); } - Ok(CheckOutput { - analysis_sha256: sha256_hex(&analysis_bytes), - analysis_digest: sha256_prefixed(&analysis_bytes), - analysis_bytes, - stdout: output.stdout, - stderr: output.stderr, + Ok(CheckResponse { + success: true, + analysis: Some(CheckOutput { + analysis_sha256: sha256_hex(&analysis_bytes), + analysis_digest: sha256_prefixed(&analysis_bytes), + analysis_bytes, + stdout: output.stdout, + stderr: output.stderr, + }), + diagnostics, + exit_code: 0, + stderr: String::new(), }) } diff --git a/src/document.rs b/src/document.rs new file mode 100644 index 0000000..d380e81 --- /dev/null +++ b/src/document.rs @@ -0,0 +1,681 @@ +//! Reader-oriented Markdown document model. +//! +//! Comrak (the same parser version as the frozen Markdown profile) parses the +//! source for **typography only**; the resulting tree is converted into a +//! View-owned `DocBlock`/`Inline` model that keeps exact UTF-8 byte spans. +//! No semantic decision (which node is executable) is taken here — that comes +//! exclusively from validated Analysis v2 (`semantic.rs`). + +use crate::project::SafeRelativePath; +use crate::source_map::{sha256_hex, SourceIndex, SourceSpan}; +use comrak::nodes::{ListType, NodeValue, Sourcepos, TableAlignment}; +use comrak::{parse_document, Arena, Options}; + +/// Class of a table column. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum TableAlign { + None, + Left, + Center, + Right, +} + +#[derive(Debug, Clone)] +pub enum Inline { + Text { + span: SourceSpan, + literal: String, + }, + Code { + span: SourceSpan, + literal: String, + ticks: usize, + }, + Strong { + span: SourceSpan, + children: Vec, + }, + Emph { + span: SourceSpan, + children: Vec, + }, + Strikethrough { + span: SourceSpan, + children: Vec, + }, + Link { + span: SourceSpan, + url: String, + title: String, + children: Vec, + }, + Image { + span: SourceSpan, + url: String, + title: String, + alt: String, + }, + Math { + span: SourceSpan, + literal: String, + display: bool, + }, + HtmlInline { + span: SourceSpan, + raw: String, + }, + SoftBreak { + span: SourceSpan, + }, + LineBreak { + span: SourceSpan, + }, + Other { + span: SourceSpan, + }, +} + +impl Inline { + pub fn span(&self) -> SourceSpan { + match self { + Inline::Text { span, .. } + | Inline::Code { span, .. } + | Inline::Strong { span, .. } + | Inline::Emph { span, .. } + | Inline::Strikethrough { span, .. } + | Inline::Link { span, .. } + | Inline::Image { span, .. } + | Inline::Math { span, .. } + | Inline::HtmlInline { span, .. } + | Inline::SoftBreak { span } + | Inline::LineBreak { span } + | Inline::Other { span } => *span, + } + } + + pub fn plain_text(&self) -> String { + let mut out = String::new(); + self.push_plain_text(&mut out); + out + } + + fn push_plain_text(&self, out: &mut String) { + match self { + Inline::Text { literal, .. } | Inline::Code { literal, .. } => out.push_str(literal), + Inline::Strong { children, .. } + | Inline::Emph { children, .. } + | Inline::Strikethrough { children, .. } + | Inline::Link { children, .. } => { + for child in children { + child.push_plain_text(out); + } + } + Inline::Image { alt, .. } => out.push_str(alt), + Inline::Math { literal, .. } => out.push_str(literal), + Inline::SoftBreak { .. } | Inline::LineBreak { .. } => out.push(' '), + Inline::HtmlInline { .. } | Inline::Other { .. } => {} + } + } +} + +#[derive(Debug, Clone)] +pub enum DocBlock { + Heading { + level: u8, + span: SourceSpan, + content: Vec, + }, + Paragraph { + span: SourceSpan, + content: Vec, + }, + List { + ordered: bool, + start: Option, + tight: bool, + span: SourceSpan, + items: Vec, + }, + ListItem { + span: SourceSpan, + task: Option, + children: Vec, + }, + BlockQuote { + span: SourceSpan, + children: Vec, + }, + CodeBlock { + span: SourceSpan, + info: String, + literal: String, + }, + Table { + span: SourceSpan, + alignments: Vec, + header: Vec>, + rows: Vec>>, + }, + MathBlock { + span: SourceSpan, + literal: String, + }, + ThematicBreak { + span: SourceSpan, + }, + HtmlBlock { + span: SourceSpan, + literal: String, + }, + Other { + span: SourceSpan, + }, +} + +impl DocBlock { + pub fn span(&self) -> SourceSpan { + match self { + DocBlock::Heading { span, .. } + | DocBlock::Paragraph { span, .. } + | DocBlock::List { span, .. } + | DocBlock::ListItem { span, .. } + | DocBlock::BlockQuote { span, .. } + | DocBlock::CodeBlock { span, .. } + | DocBlock::Table { span, .. } + | DocBlock::MathBlock { span, .. } + | DocBlock::ThematicBreak { span } + | DocBlock::HtmlBlock { span, .. } + | DocBlock::Other { span } => *span, + } + } + + pub fn heading_text(&self) -> Option { + match self { + DocBlock::Heading { content, .. } => { + Some(content.iter().map(Inline::plain_text).collect::()) + } + _ => None, + } + } +} + +#[derive(Debug, Clone)] +pub struct DocumentIdentity { + pub project_root_id: String, + pub module_id: String, + pub relative_path: String, + pub source_sha256: String, +} + +impl DocumentIdentity { + pub fn placeholder(relative_path: &SafeRelativePath) -> Self { + Self { + project_root_id: String::new(), + module_id: String::new(), + relative_path: relative_path.as_str().to_string(), + source_sha256: String::new(), + } + } +} + +#[derive(Debug, Clone)] +pub struct DocumentModel { + pub identity: DocumentIdentity, + pub source: String, + pub blocks: Vec, + pub source_index: SourceIndex, + /// Number of leading BOM bytes stripped before parsing. + pub bom_len: usize, +} + +impl DocumentModel { + /// Parse the exact source for display. Never decides executable semantics. + pub fn parse(source: String, identity: DocumentIdentity) -> Self { + let (bom_len, body) = strip_bom(&source); + let options = markdown_options(); + let arena = Arena::new(); + let root = parse_document(&arena, body, &options); + let lines = line_starts(body); + let body_len = body.len(); + let blocks = root + .children() + .filter_map(|child| convert_block(child, &lines, bom_len, body_len)) + .collect(); + let source_index = SourceIndex::new(&source); + Self { + identity, + source, + blocks, + source_index, + bom_len, + } + } + + /// First level-1 heading text, else the document stem. + pub fn title(&self) -> String { + for block in &self.blocks { + if let DocBlock::Heading { + level: 1, content, .. + } = block + { + let raw = content + .iter() + .map(Inline::plain_text) + .collect::() + .trim() + .to_string(); + // Display-only: strip a legal mode declaration prefix. Source + // view still shows the exact original text. + let text = raw + .strip_prefix("@exec ") + .or_else(|| raw.strip_prefix("@knowledge ")) + .unwrap_or(&raw) + .trim() + .to_string(); + if !text.is_empty() { + return text; + } + } + } + let name = self + .identity + .relative_path + .rsplit('/') + .next() + .unwrap_or(&self.identity.relative_path); + name.trim_end_matches(".mq.md").to_string() + } + + /// Plain text of the whole document (search/alt helpers). + pub fn plain_text(&self) -> String { + let mut out = String::new(); + collect_block_text(&self.blocks, &mut out); + out + } + + pub fn source_digest(&self) -> String { + sha256_hex(self.source.as_bytes()) + } +} + +/// The frozen `marqdo.md.v1` parser options (same set as the Core profile). +pub fn markdown_options() -> Options<'static> { + let mut options = Options::default(); + options.extension.table = true; + options.extension.strikethrough = true; + options.extension.tasklist = true; + options.extension.math_dollars = true; + options.extension.math_dollars_block = true; + options.extension.front_matter_delimiter = Some("---".to_string()); + options +} + +fn collect_block_text(blocks: &[DocBlock], out: &mut String) { + for block in blocks { + match block { + DocBlock::Heading { content, .. } | DocBlock::Paragraph { content, .. } => { + for inline in content { + out.push_str(&inline.plain_text()); + } + out.push('\n'); + } + DocBlock::List { items, .. } => collect_block_text(items, out), + DocBlock::ListItem { children, .. } => collect_block_text(children, out), + DocBlock::BlockQuote { children, .. } => collect_block_text(children, out), + DocBlock::CodeBlock { literal, .. } | DocBlock::MathBlock { literal, .. } => { + out.push_str(literal); + out.push('\n'); + } + DocBlock::Table { header, rows, .. } => { + for cell in header { + for inline in cell { + out.push_str(&inline.plain_text()); + } + } + for row in rows { + for cell in row { + for inline in cell { + out.push_str(&inline.plain_text()); + } + } + } + out.push('\n'); + } + DocBlock::ThematicBreak { .. } + | DocBlock::HtmlBlock { .. } + | DocBlock::Other { .. } => {} + } + } +} + +fn strip_bom(source: &str) -> (usize, &str) { + match source.strip_prefix('\u{feff}') { + Some(rest) => (source.len() - rest.len(), rest), + None => (0, source), + } +} + +fn line_starts(text: &str) -> Vec { + let bytes = text.as_bytes(); + let mut starts = vec![0usize]; + for (index, byte) in bytes.iter().enumerate() { + if *byte == b'\n' { + starts.push(index + 1); + } + } + starts +} + +fn span_of(pos: Sourcepos, lines: &[usize], shift: usize, body_len: usize) -> SourceSpan { + fn offset_of(line: usize, column: usize, lines: &[usize], inclusive: bool) -> Option { + if line == 0 { + return None; + } + let line_start = *lines.get(line - 1)?; + Some(line_start + column.saturating_sub(1) + usize::from(inclusive)) + } + let start = offset_of(pos.start.line, pos.start.column, lines, false) + .map(|offset| offset.min(body_len)) + .unwrap_or(0); + let end = offset_of(pos.end.line, pos.end.column, lines, true) + .map(|offset| offset.min(body_len)) + .unwrap_or(start) + .max(start); + SourceSpan::new((start + shift) as u64, (end + shift) as u64) +} + +fn convert_block<'a>( + node: &'a comrak::nodes::AstNode<'a>, + lines: &[usize], + shift: usize, + body_len: usize, +) -> Option { + let data = node.data(); + let span = span_of(data.sourcepos, lines, shift, body_len); + let value = &data.value; + let block = match value { + NodeValue::Document => return None, + NodeValue::FrontMatter(_) => return None, + NodeValue::Paragraph => DocBlock::Paragraph { + span, + content: convert_inlines(node, lines, shift, body_len), + }, + NodeValue::Heading(heading) => DocBlock::Heading { + level: heading.level, + span, + content: convert_inlines(node, lines, shift, body_len), + }, + NodeValue::List(list) => { + let ordered = list.list_type == ListType::Ordered; + let items = node + .children() + .filter_map(|child| convert_block(child, lines, shift, body_len)) + .collect(); + DocBlock::List { + ordered, + start: if ordered { Some(list.start) } else { None }, + tight: list.tight, + span, + items, + } + } + NodeValue::Item(_) => DocBlock::ListItem { + span, + task: None, + children: node + .children() + .filter_map(|child| convert_block(child, lines, shift, body_len)) + .collect(), + }, + NodeValue::TaskItem(item) => DocBlock::ListItem { + span, + task: Some(item.symbol.is_some()), + children: node + .children() + .filter_map(|child| convert_block(child, lines, shift, body_len)) + .collect(), + }, + NodeValue::BlockQuote | NodeValue::MultilineBlockQuote(_) => DocBlock::BlockQuote { + span, + children: node + .children() + .filter_map(|child| convert_block(child, lines, shift, body_len)) + .collect(), + }, + NodeValue::CodeBlock(code) => DocBlock::CodeBlock { + span, + info: code.info.clone(), + literal: code.literal.clone(), + }, + NodeValue::HtmlBlock(html) => DocBlock::HtmlBlock { + span, + literal: html.literal.clone(), + }, + NodeValue::ThematicBreak(_) => DocBlock::ThematicBreak { span }, + NodeValue::MathBlock(math) => DocBlock::MathBlock { + span, + literal: math.literal.clone(), + }, + NodeValue::Table(table) => { + let alignments = table + .alignments + .iter() + .map(|alignment| match alignment { + TableAlignment::None => TableAlign::None, + TableAlignment::Left => TableAlign::Left, + TableAlignment::Center => TableAlign::Center, + TableAlignment::Right => TableAlign::Right, + }) + .collect(); + let mut header = Vec::new(); + let mut rows = Vec::new(); + for row in node.children() { + let row_data = row.data(); + let is_header = match &row_data.value { + NodeValue::TableRow(table_row) => table_row.header, + _ => false, + }; + let mut cells = Vec::new(); + for cell in row.children() { + cells.push(convert_inlines(cell, lines, shift, body_len)); + } + if is_header { + header = cells; + } else { + rows.push(cells); + } + } + DocBlock::Table { + span, + alignments, + header, + rows, + } + } + _ => { + // Unknown block kinds are inert. If they carry block children, keep + // them so future additive nodes cannot hide readable content. + let children: Vec = node + .children() + .filter_map(|child| convert_block(child, lines, shift, body_len)) + .collect(); + if children.is_empty() { + DocBlock::Other { span } + } else { + DocBlock::BlockQuote { span, children } + } + } + }; + Some(block) +} + +fn convert_inlines<'a>( + node: &'a comrak::nodes::AstNode<'a>, + lines: &[usize], + shift: usize, + body_len: usize, +) -> Vec { + node.children() + .filter_map(|child| convert_inline(child, lines, shift, body_len)) + .collect() +} + +fn convert_inline<'a>( + node: &'a comrak::nodes::AstNode<'a>, + lines: &[usize], + shift: usize, + body_len: usize, +) -> Option { + let data = node.data(); + let span = span_of(data.sourcepos, lines, shift, body_len); + let inline = match &data.value { + NodeValue::Text(text) => Inline::Text { + span, + literal: text.to_string(), + }, + NodeValue::Code(code) => Inline::Code { + span, + literal: code.literal.clone(), + ticks: code.num_backticks, + }, + NodeValue::SoftBreak => Inline::SoftBreak { span }, + NodeValue::LineBreak => Inline::LineBreak { span }, + NodeValue::Strong(_) => Inline::Strong { + span, + children: convert_inlines(node, lines, shift, body_len), + }, + NodeValue::Emph(_) => Inline::Emph { + span, + children: convert_inlines(node, lines, shift, body_len), + }, + NodeValue::Strikethrough(_) => Inline::Strikethrough { + span, + children: convert_inlines(node, lines, shift, body_len), + }, + NodeValue::Link(link) => Inline::Link { + span, + url: link.url.clone(), + title: link.title.clone(), + children: convert_inlines(node, lines, shift, body_len), + }, + NodeValue::Image(link) => { + let children = convert_inlines(node, lines, shift, body_len); + Inline::Image { + span, + url: link.url.clone(), + title: link.title.clone(), + alt: children.iter().map(Inline::plain_text).collect(), + } + } + NodeValue::Math(math) => Inline::Math { + span, + literal: math.literal.clone(), + display: math.display_math, + }, + NodeValue::HtmlInline(raw) => Inline::HtmlInline { + span, + raw: raw.clone(), + }, + _ => Inline::Other { span }, + }; + Some(inline) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn parse(source: &str) -> DocumentModel { + DocumentModel::parse( + source.to_string(), + DocumentIdentity { + project_root_id: "root:t@0.1.0".into(), + module_id: "root:t@0.1.0::index.mq.md".into(), + relative_path: "index.mq.md".into(), + source_sha256: String::new(), + }, + ) + } + + #[test] + fn parses_gfm_and_preserves_utf8_spans() { + let source = + "# @knowledge 标题\n\n| 名称 | 值 |\n| --- | --- |\n| 甲 | 1 |\n\n**加粗** 和 `代码`\n"; + let document = parse(source); + // Display title drops a legal mode prefix; the source keeps it. + assert_eq!(document.title(), "标题"); + assert!(document.source.starts_with("# @knowledge 标题")); + assert!(document + .blocks + .iter() + .any(|block| matches!(block, DocBlock::Table { .. }))); + // Every block span slices valid UTF-8. + for block in &document.blocks { + let span = block.span(); + assert!( + document + .source_index + .source_text(&document.source, span) + .is_some(), + "invalid span {span:?}" + ); + } + } + + #[test] + fn parses_math_and_code_as_inert_literals() { + let source = "行内 $a^2$ 与\n\n$$\n\\sum i\n$$\n\n```rust\nfn x() {}\n```\n"; + let document = parse(source); + assert!(document.plain_text().contains("a^2")); + assert!(document.plain_text().contains("sum i")); + assert!(document.plain_text().contains("fn x()")); + } + + #[test] + fn parses_lists_quotes_and_task_items() { + let source = "- [x] 完成\n- [ ] 未完成\n\n> 引用\n\n1. 一\n2. 二\n"; + let document = parse(source); + let has_task = document.blocks.iter().any(|block| match block { + DocBlock::List { items, .. } => items.iter().any(|item| { + matches!( + item, + DocBlock::ListItem { + task: Some(true), + .. + } + ) + }), + _ => false, + }); + assert!(has_task); + assert!(document + .blocks + .iter() + .any(|block| matches!(block, DocBlock::BlockQuote { .. }))); + assert_eq!(document.blocks.len(), 3); + } + + #[test] + fn heading_spans_are_exact() { + let source = "# 数学 #\n\n正文\n"; + let document = parse(source); + match &document.blocks[0] { + DocBlock::Heading { span, .. } => { + let text = document + .source_index + .source_text(&document.source, *span) + .unwrap(); + assert_eq!(text, "# 数学 #"); + } + other => panic!("expected heading, got {other:?}"), + } + } + + #[test] + fn front_matter_is_not_rendered_as_a_block() { + let source = "---\nimport:\n lib: \"./lib.mq.md\"\n---\n\n# hi\n"; + let document = parse(source); + assert_eq!(document.blocks.len(), 1); + assert!(matches!(document.blocks[0], DocBlock::Heading { .. })); + } +} diff --git a/src/lib.rs b/src/lib.rs index 822db8c..331fce7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,10 +7,16 @@ //! this library so there is never a second renderer or a second parser. pub mod app; +pub mod assets; pub mod cli; pub mod core_client; +pub mod document; pub mod error; +pub mod presentation; pub mod project; +pub mod render; +pub mod semantic; +pub mod server; pub mod source_map; pub mod version; diff --git a/src/presentation.rs b/src/presentation.rs new file mode 100644 index 0000000..38506a1 --- /dev/null +++ b/src/presentation.rs @@ -0,0 +1,275 @@ +//! Presentation model: the one intermediate form between verified domain data +//! and the one `ReaderRenderer`. +//! +//! Nothing here spawns processes, builds HTML or parses Markdown semantics. It +//! only composes already-verified pieces (RFC-VIEW-0001 §6.3, §14.2). + +use crate::document::{DocumentIdentity, DocumentModel}; +use crate::project::{Project, SafeRelativePath, ViewConfig}; +use crate::semantic::{CoreDiagnostic, SemanticProjection, ViewWarning}; + +/// Private View presentation-model version. Not a public protocol. +pub const PRESENTATION_VERSION: u32 = 1; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum SourceStatus { + /// No usable `MARQDO_BIN`; prose only, semantics explicitly unverified. + CoreUnavailable, + /// `check` succeeded and Analysis v2 was verified. + StaticOk, + /// `check` failed; diagnostics shown, semantics revoked. + CoreError, + /// Analysis/source digest mismatch or an outdated artifact. + Stale, + /// Unknown Analysis/Tool major or product range. + ProtocolIncompatible, + /// Analysis `source_digest` differs from the current source bytes. + SourceMismatch, +} + +impl SourceStatus { + pub fn data_value(&self) -> &'static str { + match self { + SourceStatus::CoreUnavailable => "core-unavailable", + SourceStatus::StaticOk => "static-ok", + SourceStatus::CoreError => "core-error", + SourceStatus::Stale => "stale", + SourceStatus::ProtocolIncompatible => "protocol-incompatible", + SourceStatus::SourceMismatch => "source-mismatch", + } + } + + pub fn label(&self) -> &'static str { + match self { + SourceStatus::CoreUnavailable => "核心不可用 · 语义未验证", + SourceStatus::StaticOk => "静态检查已通过 · 未运行", + SourceStatus::CoreError => "Core 检查失败 · 语义不可用", + SourceStatus::Stale => "语义结果已过期", + SourceStatus::ProtocolIncompatible => "核心协议不兼容", + SourceStatus::SourceMismatch => "源码与分析不一致", + } + } + + pub fn semantics_usable(&self) -> bool { + matches!(self, SourceStatus::StaticOk) + } +} + +#[derive(Debug, Clone)] +pub struct Navigation { + pub site_title: String, + pub documents: Vec, + pub active: Option, + /// True only when an explicit `view.json` names this document as welcome. + pub welcome: bool, +} + +impl Navigation { + pub fn from_project(project: &Project, config: &ViewConfig, active: &SafeRelativePath) -> Self { + let documents = project.list_documents().unwrap_or_default(); + let welcome = config + .welcome + .as_ref() + .map(|welcome| welcome == active) + .unwrap_or(false); + Self { + site_title: config + .site_title + .clone() + .unwrap_or_else(|| "Marqdo".to_string()), + documents, + active: Some(active.clone()), + welcome, + } + } +} + +#[derive(Debug, Clone)] +pub struct PresentationModel { + pub version: u32, + pub title: String, + pub document: DocumentModel, + pub semantic: Option, + pub source_status: SourceStatus, + /// Human-readable reason for a degraded status (already normalized: no + /// absolute paths from the Core). + pub status_note: Option, + pub diagnostics: Vec, + pub warnings: Vec, + pub navigation: Navigation, + /// Function/section outline entries rendered from verified Analysis only. + pub outline: Vec, + /// Frozen core product version used for this page, when one was consulted. + pub core_version: Option, +} + +#[derive(Debug, Clone)] +pub struct OutlineEntry { + pub label: String, + pub anchor: String, + pub detail: String, + pub kind: OutlineKind, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum OutlineKind { + Function, + Knowledge, + Section, +} + +impl PresentationModel { + pub fn functions(&self) -> impl Iterator { + self.outline + .iter() + .filter(|entry| entry.kind == OutlineKind::Function) + } + + pub fn error_diagnostics(&self) -> impl Iterator { + self.diagnostics + .iter() + .filter(|diagnostic| diagnostic.severity == "error") + } +} + +/// Input to the one builder. `analysis` is already protocol/byte verified. +pub struct BuildInput<'a> { + pub document: DocumentModel, + pub analysis: Option<&'a crate::semantic::VerifiedAnalysis>, + pub status: SourceStatus, + pub status_note: Option, + pub diagnostics: Vec, + pub navigation: Navigation, + pub core_version: Option, +} + +pub fn build(input: BuildInput<'_>) -> PresentationModel { + let BuildInput { + mut document, + analysis, + status, + status_note, + mut diagnostics, + navigation, + core_version, + } = input; + + let semantic = analysis.map(|verified| verified.projection.clone()); + if let Some(projection) = &semantic { + document.identity = DocumentIdentity { + project_root_id: projection.project_root_id.clone(), + module_id: projection.module_id.clone(), + relative_path: projection.relative_path.clone(), + source_sha256: projection.source_digest.clone(), + }; + for diagnostic in &projection.diagnostics { + if !diagnostics.iter().any(|existing| { + existing.code == diagnostic.code + && existing.message == diagnostic.message + && existing.span == diagnostic.span + }) { + diagnostics.push(diagnostic.clone()); + } + } + } + let warnings = semantic + .as_ref() + .map(|projection| projection.warnings.clone()) + .unwrap_or_default(); + let outline = semantic.as_ref().map(build_outline).unwrap_or_default(); + + PresentationModel { + version: PRESENTATION_VERSION, + title: document.title(), + document, + semantic, + source_status: status, + status_note, + diagnostics, + warnings, + navigation, + outline, + core_version, + } +} + +fn build_outline(projection: &SemanticProjection) -> Vec { + let mut entries = Vec::new(); + for function in &projection.functions { + let params = if function.signature.params.is_empty() { + String::new() + } else { + function + .signature + .params + .iter() + .map(|param| { + if param.ty.is_empty() { + param.name.clone() + } else { + format!("{}: {}", param.name, param.ty) + } + }) + .collect::>() + .join(", ") + }; + let detail = if params.is_empty() { + "无参数".to_string() + } else { + format!("params({params})") + }; + entries.push(OutlineEntry { + label: function.local_name.clone(), + anchor: anchor_for_span(function.heading_span.start, function.heading_span.end), + detail, + kind: OutlineKind::Function, + }); + } + for unit in &projection.units { + let kind = match unit.kind { + crate::semantic::UnitKind::Knowledge if unit.level >= 2 => OutlineKind::Knowledge, + crate::semantic::UnitKind::Section => OutlineKind::Section, + _ => continue, + }; + if unit.name.is_empty() { + continue; + } + entries.push(OutlineEntry { + label: unit.name.clone(), + anchor: anchor_for_span(unit.span.start, unit.span.end), + detail: if unit.level == 2 { + "知识单元".to_string() + } else { + "章节".to_string() + }, + kind, + }); + } + entries +} + +/// Deterministic heading anchor derived from the heading byte span. It never +/// depends on rendered text, so duplicate headings cannot collide. +pub fn anchor_for_span(start: u64, end: u64) -> String { + format!("mq-h-{start:x}-{end:x}") +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn status_values_are_stable() { + assert_eq!(SourceStatus::StaticOk.data_value(), "static-ok"); + assert_eq!(SourceStatus::CoreError.data_value(), "core-error"); + assert!(SourceStatus::StaticOk.semantics_usable()); + assert!(!SourceStatus::CoreUnavailable.semantics_usable()); + assert!(!SourceStatus::SourceMismatch.semantics_usable()); + } + + #[test] + fn heading_anchors_are_deterministic_and_collision_free() { + assert_eq!(anchor_for_span(1, 2), "mq-h-1-2"); + assert_ne!(anchor_for_span(1, 2), anchor_for_span(1, 3)); + } +} diff --git a/src/project.rs b/src/project.rs index c8c2ee2..f0db180 100644 --- a/src/project.rs +++ b/src/project.rs @@ -306,6 +306,86 @@ impl Project { } } +/// Optional View-only site configuration (`view.json`). +/// +/// This is **not** a Marqdo language protocol and cannot grant execution: only +/// the fields below are read, and the welcome path is still subject to the same +/// project-root boundary (RFC-VIEW-0001 §9.4). +#[derive(Debug, Clone, Default)] +pub struct ViewConfig { + pub welcome: Option, + pub site_title: Option, + pub theme: Option, +} + +impl ViewConfig { + pub fn load(root: &Path) -> ViewResult { + let path = root.join("view.json"); + let metadata = match std::fs::metadata(&path) { + Ok(metadata) => metadata, + Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(Self::default()), + Err(err) => return Err(ViewError::io(&format!("stat {}", path.display()), err)), + }; + if !metadata.is_file() || metadata.len() > 64 * 1024 { + return Err(ViewError::PathForbidden { + detail: "view.json must be a regular file under 64 KiB".to_string(), + }); + } + let bytes = std::fs::read(&path) + .map_err(|err| ViewError::io(&format!("read {}", path.display()), err))?; + #[derive(serde::Deserialize)] + struct RawConfig { + #[serde(default)] + schema: String, + #[serde(default)] + schema_version: u32, + #[serde(default)] + welcome: Option, + #[serde(default)] + site_title: Option, + #[serde(default)] + theme: Option, + } + let raw: RawConfig = serde_json::from_slice(&bytes).map_err(|err| ViewError::Io { + detail: format!("view.json is not valid JSON: {err}"), + })?; + if raw.schema != "marqdo.view-config" || raw.schema_version != 1 { + return Err(ViewError::ProtocolIncompatible { + detail: format!( + "unsupported view.json schema {:?} version {}; expected marqdo.view-config v1", + raw.schema, raw.schema_version + ), + }); + } + let welcome = match raw.welcome { + Some(path) => Some(SafeRelativePath::parse(&path)?), + None => None, + }; + if let Some(welcome) = &welcome { + if !root.join(welcome.to_path()).is_file() { + return Err(ViewError::PathForbidden { + detail: format!( + "view.json welcome file {welcome} does not exist under the project root" + ), + }); + } + } + let site_title = raw + .site_title + .map(|title| title.trim().to_string()) + .filter(|title| !title.is_empty() && title.chars().count() <= 80); + let theme = raw + .theme + .map(|theme| theme.trim().to_string()) + .filter(|theme| theme == "botanical" || theme == "paper"); + Ok(Self { + welcome, + site_title, + theme, + }) + } +} + /// Discover the project root for a source file: nearest ancestor with /// `marqdo.yaml`, else the file's directory. The file itself is canonical. pub fn discover_project_root(file: &Path) -> PathBuf { diff --git a/src/render.rs b/src/render.rs new file mode 100644 index 0000000..c6a5988 --- /dev/null +++ b/src/render.rs @@ -0,0 +1,1162 @@ +// Rendering appends explicit newlines to keep the generated HTML readable; +// the `write_with_newline` style lint is therefore not useful here. +#![allow(clippy::write_with_newline)] +#![allow(clippy::type_complexity)] + +//! The one ReaderRenderer. +//! +//! Live and Export both call `render()`; the only difference is `LinkPolicy` +//! and whether interactive controls are available (RFC-VIEW-0001 §14.3). +//! Markdown is serialized here from the View-owned `DocBlock` tree, with raw +//! HTML omitted by default and every URL scheme sanitized. + +use crate::assets::AssetBundle; +use crate::document::{DocBlock, Inline, TableAlign}; +use crate::presentation::{anchor_for_span, PresentationModel}; +use crate::project::SafeRelativePath; +use crate::semantic::{source_id, UnitKind}; +use crate::source_map::SourceSpan; +use std::fmt::Write as _; + +/// How links to other documents are resolved. This is the only Live/Export +/// difference in rendered content. +#[derive(Debug, Clone)] +pub enum LinkPolicy { + /// `GET /file?path=` on the local server. + LocalServer, + /// Relative links from a static page at `page_depth` directories below the + /// site root (`0` for `index.html`). + StaticRelative { page_depth: usize }, +} + +impl LinkPolicy { + pub fn document_href(&self, current: &SafeRelativePath, target: &SafeRelativePath) -> String { + match self { + LinkPolicy::LocalServer => { + format!("/file?path={}", percent_encode_path(target.as_str())) + } + LinkPolicy::StaticRelative { page_depth } => { + let _ = current; + let mut prefix = String::new(); + for _ in 0..*page_depth { + prefix.push_str("../"); + } + format!("{prefix}pages/{}.html", target.as_str()) + } + } + } + + fn asset_prefix(&self, page_depth: usize) -> String { + match self { + LinkPolicy::LocalServer => "/assets/".to_string(), + LinkPolicy::StaticRelative { .. } => { + let mut prefix = String::new(); + for _ in 0..page_depth { + prefix.push_str("../"); + } + format!("{prefix}assets/") + } + } + } +} + +/// Everything the renderer needs beyond the model. +#[derive(Debug, Clone)] +pub struct RenderContext { + pub links: LinkPolicy, + pub live: bool, + pub csrf_token: Option, + /// Whether a Run control may be shown as available. False until the + /// explicit-run flow exists; the button then explains that it is disabled. + pub run_available: bool, +} + +impl RenderContext { + pub fn live() -> Self { + Self { + links: LinkPolicy::LocalServer, + live: true, + csrf_token: None, + run_available: false, + } + } + + pub fn static_site(page_depth: usize) -> Self { + Self { + links: LinkPolicy::StaticRelative { page_depth }, + live: false, + csrf_token: None, + run_available: false, + } + } +} + +pub struct RenderedPage { + pub html: String, + /// Asset hashed names actually referenced by the page. + pub assets_used: Vec, +} + +pub struct ReaderRenderer { + assets: &'static AssetBundle, +} + +impl ReaderRenderer { + pub fn new() -> Self { + Self { + assets: AssetBundle::get(), + } + } + + pub fn render(&self, model: &PresentationModel, ctx: &RenderContext) -> RenderedPage { + let asset_prefix = ctx.links.asset_prefix(match ctx.links { + LinkPolicy::StaticRelative { page_depth } => page_depth, + LinkPolicy::LocalServer => 0, + }); + let css_name = self.assets.hashed_css_name(); + let js_name = self.assets.hashed_js_name(); + let logo_uri = self.assets.logo().data_uri(); + + let navigation = &model.navigation; + let document_href = format!( + "{prefix}reader.{hash}.css", + prefix = asset_prefix, + hash = &self.assets.css_served_sha256()[..16] + ); + let _ = document_href; + let mut html = String::with_capacity(16 * 1024 + model.document.source.len()); + let page_title = if navigation.site_title.is_empty() { + model.title.clone() + } else { + format!("{} · {}", model.title, navigation.site_title) + }; + let _ = write!( + html, + r##" + + + + + + + +{title} + + + + + +跳到正文 +"##, + presentation_version = model.version, + view_version = env!("CARGO_PKG_VERSION"), + csp = csp_policy(), + title = escape_text(&page_title), + logo = escape_attr(&logo_uri), + css = escape_attr(&format!("{asset_prefix}{css_name}")), + js = escape_attr(&format!("{asset_prefix}{js_name}")), + status = model.source_status.data_value(), + live = if ctx.live { "true" } else { "false" }, + ); + + self.render_topbar(&mut html, model, ctx, navigation); + self.render_ornament(&mut html); + let _ = write!(html, "
\n"); + + if navigation.welcome { + self.render_welcome(&mut html, navigation); + } + self.render_document_meta(&mut html, model); + self.render_diagnostics(&mut html, model); + self.render_functions(&mut html, model); + self.render_document(&mut html, model, ctx); + self.render_source_pane(&mut html, model, ctx); + self.render_footer(&mut html, model); + let _ = write!(html, "
\n"); + + self.render_dock(&mut html, ctx); + self.render_toast(&mut html); + self.render_dialogs(&mut html, model, ctx); + html.push_str("\n\n"); + + RenderedPage { + html, + assets_used: vec![css_name, js_name], + } + } + + fn render_topbar( + &self, + html: &mut String, + model: &PresentationModel, + _ctx: &RenderContext, + navigation: &crate::presentation::Navigation, + ) { + let active = model + .navigation + .active + .as_ref() + .map(|path| path.as_str()) + .unwrap_or(""); + let files_count = navigation.documents.len(); + let _ = write!( + html, + r##"
+
+ +
+ + + {site_title}EXECUTABLE KNOWLEDGE + +
+ +
+
+ +"##, + menu_icon = icon("M4 6h16M4 12h16M4 18h16"), + site_title = escape_text(&navigation.site_title), + logo = escape_attr(&self.assets.logo().data_uri()), + search_icon = icon("M21 21l-5-5M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0"), + run_disabled = if _ctx.run_available { "false" } else { "true" }, + run_title = if _ctx.run_available { + "运行文档(需要确认)" + } else { + "运行入口尚未启用;当前版本不会执行文档" + }, + ); + let _ = (files_count, active); + } + + fn render_ornament(&self, html: &mut String) { + html.push_str( + "
\n", + ); + } + + fn render_welcome(&self, html: &mut String, navigation: &crate::presentation::Navigation) { + let _ = write!( + html, + r##"
+

WELCOME TO

+

{title}

+ +

代码即文档 · 文档即知识库 · 知识即可执行

+
+"##, + title = escape_text(&navigation.site_title) + ); + } + + fn render_document_meta(&self, html: &mut String, model: &PresentationModel) { + let status = model.source_status; + let _ = write!( + html, + r##"
+ {file} + {label} +"##, + file = escape_text(&model.document.identity.relative_path), + status_value = status.data_value(), + label = escape_text(status.label()), + ); + if let Some(projection) = &model.semantic { + if !projection.imports.is_empty() { + html.push_str("
    \n"); + for import in &projection.imports { + let _ = write!( + html, + "
  • {alias} → {target}
  • \n", + alias = escape_text(&import.alias), + target = escape_text(&import.target) + ); + } + html.push_str("
\n"); + } + } + html.push_str("
\n"); + if let Some(note) = &model.status_note { + let _ = write!( + html, + "

{note}

\n", + note = escape_text(note) + ); + } + } + + fn render_diagnostics(&self, html: &mut String, model: &PresentationModel) { + let mut items: Vec<(&str, &str, Option, Option, &str)> = Vec::new(); + for diagnostic in &model.diagnostics { + items.push(( + &diagnostic.severity, + &diagnostic.code, + diagnostic.line, + diagnostic.column, + &diagnostic.message, + )); + } + for warning in &model.warnings { + let (line, column) = warning + .span + .map(|span| model.document.source_index.line_col(span.start as usize)) + .map(|(line, column)| (Some(line as u64), Some(column as u64))) + .unwrap_or((None, None)); + items.push(("warning", &warning.code, line, column, &warning.message)); + } + if items.is_empty() { + return; + } + let has_error = items.iter().any(|item| item.0 == "error"); + let open = if has_error { " open" } else { "" }; + let _ = write!( + html, + "
\n{count} 条诊断(Core 与 View 来源已区分)\n
    \n", + severity = if has_error { "error" } else { "warning" }, + open = open, + count = items.len() + ); + for (severity, code, line, column, message) in items { + let _ = write!( + html, + "
  1. {code}{loc}{message}
  2. \n", + severity = escape_attr(severity), + code = escape_text(code), + loc = match (line, column) { + (Some(line), Some(column)) => format!( + "第 {line} 行第 {column} 列" + ), + _ => String::new(), + }, + message = escape_text(message) + ); + } + html.push_str("
\n
\n"); + } + + fn render_functions(&self, html: &mut String, model: &PresentationModel) { + if model.outline.is_empty() { + return; + } + let functions: Vec<_> = model.functions().collect(); + if functions.is_empty() { + return; + } + let _ = write!( + html, + "
\n本文函数({count})\n
    \n", + count = functions.len() + ); + for entry in functions { + let _ = write!( + html, + "
  • {label}{detail}
  • \n", + anchor = escape_attr(&entry.anchor), + label = escape_text(&entry.label), + detail = escape_text(&entry.detail) + ); + } + html.push_str("
\n
\n"); + } + + fn render_document(&self, html: &mut String, model: &PresentationModel, ctx: &RenderContext) { + html.push_str("
\n"); + let current = SafeRelativePath::parse(&model.document.identity.relative_path).ok(); + match ¤t { + Some(current) => { + render_blocks( + html, + &model.document.blocks, + model, + ctx, + current, + self.assets, + ); + } + None => { + let _ = write!( + html, + "

相对路径无效,已进入纯文本阅读模式。

\n" + ); + } + } + html.push_str("
\n"); + } + + fn render_source_pane( + &self, + html: &mut String, + model: &PresentationModel, + _ctx: &RenderContext, + ) { + let source = &model.document.source; + html.push_str("
\n
    \n"); + if source.is_empty() { + html.push_str("
  1. (空文件)
  2. \n"); + } + let index = &model.document.source_index; + for line in 1..=index.line_count() { + let text = index.line_text(source, line).unwrap_or(""); + let _ = write!( + html, + "
  3. {line}{text}
  4. \n", + line = line, + text = escape_text(text) + ); + } + html.push_str("
\n
\n"); + // Exact bytes for the copy action (never interpreted as markup). + let _ = write!( + html, + "\n", + escape_text(source) + ); + } + + fn render_footer(&self, html: &mut String, model: &PresentationModel) { + let core = model + .core_version + .clone() + .unwrap_or_else(|| "core unavailable".to_string()); + let _ = write!( + html, + r##"
+ Marqdo · 静态阅读 + Analysis v2 · Trace v2 · {core} + 默认不执行 · 无自动运行 +
+"##, + core = escape_text(&core) + ); + } + + fn render_dock(&self, html: &mut String, ctx: &RenderContext) { + let run_disabled = if ctx.run_available { + "" + } else { + " data-disabled=\"true\"" + }; + let _ = write!( + html, + r##" +"##, + reload = icon("M20 7V3l-3 3a8 8 0 1 0 2 11M20 3h-5"), + settings = icon("M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8M12 2v3M12 19v3M2 12h3M19 12h3M5 5l2 2M17 17l2 2M5 19l2-2M17 7l2-2"), + play = icon("m9 5 11 7-11 7z"), + clear = icon("m14 3 4 2-4 8M5 12l8 2 2 6H3zM7 15l-1 4M10 16l-1 4"), + more = icon("M5 12h.01M12 12h.01M19 12h.01"), + run_disabled = run_disabled + ); + } + + fn render_toast(&self, html: &mut String) { + html.push_str("\n"); + } + + fn render_dialogs(&self, html: &mut String, model: &PresentationModel, ctx: &RenderContext) { + let csrf = ctx + .csrf_token + .as_deref() + .map(|token| { + format!( + "", + escape_attr(token) + ) + }) + .unwrap_or_default(); + let _ = write!( + html, + r##"{csrf} + +

搜索当前文档

+ +
    +
    + +

    阅读设置

    +
      +
    • +
    • +
    • +
    +
    + +

    文件与更多

    +
      +
    • +
    • +
    • +
    • +
    • +
    • +
    • +
    + {files} +
    + +

    函数与知识单元

    +
    +
    + +

    当前版本不支持

    +
    +
    + +

    关于 Marqdo View

    +

    版本 {view_version} · Tool Protocol v1 · Analysis v2 · Trace v2。

    +

    冻结核心:{core}。

    +

    本页面只渲染原始 Markdown 与已校验的静态语义;打开、刷新、搜索、导出都不会执行文档。运行需要用户显式确认。

    +
    +"##, + csrf = csrf, + files = self.render_file_list(model, ctx), + view_version = env!("CARGO_PKG_VERSION"), + core = escape_text(model.core_version.as_deref().unwrap_or("未检测到可用核心")), + ); + } + + fn render_file_list(&self, model: &PresentationModel, ctx: &RenderContext) -> String { + if model.navigation.documents.len() <= 1 { + return String::new(); + } + let Ok(current) = SafeRelativePath::parse(&model.document.identity.relative_path) else { + return String::new(); + }; + let mut out = String::from( + "
    项目内文档
      \n", + ); + for document in &model.navigation.documents { + let href = ctx.links.document_href(¤t, document); + let active = model + .navigation + .active + .as_ref() + .map(|active| active == document) + .unwrap_or(false); + let _ = write!( + out, + "
    • {name}
    • \n", + if active { " aria-current=\"page\"" } else { "" }, + href = escape_attr(&href), + name = escape_text(document.as_str()) + ); + } + out.push_str("
    \n"); + out + } +} + +impl Default for ReaderRenderer { + fn default() -> Self { + Self::new() + } +} + +fn render_blocks( + html: &mut String, + blocks: &[DocBlock], + model: &PresentationModel, + ctx: &RenderContext, + current: &SafeRelativePath, + assets: &AssetBundle, +) { + for block in blocks { + render_block(html, block, model, ctx, current, assets); + } +} + +fn render_block( + html: &mut String, + block: &DocBlock, + model: &PresentationModel, + ctx: &RenderContext, + current: &SafeRelativePath, + assets: &AssetBundle, +) { + match block { + DocBlock::Heading { + level, + span, + content, + } => { + let unit = resolve_heading_unit(model, *span, *level); + let anchor = anchor_for_span(span.start, span.end); + let (badge, cleaned) = display_heading_content(content, unit); + let data_semantic = if let Some((_, data)) = badge { + data + } else if let Some(unit) = unit { + match unit.kind { + UnitKind::Function => "exec", + UnitKind::Knowledge => "knowledge", + _ => "document", + } + } else { + "document" + }; + let _ = write!( + html, + "", + level, + escape_attr(&anchor), + source_id_id(model, *span), + data_semantic, + ); + if let Some(badge) = badge { + let _ = write!( + html, + "{}", + badge.1, badge.0 + ); + } + render_inlines(html, &cleaned, model, ctx, current, assets); + let _ = write!(html, "\n"); + } + DocBlock::Paragraph { content, .. } => { + html.push_str("

    "); + render_inlines(html, content, model, ctx, current, assets); + html.push_str("

    \n"); + } + DocBlock::List { + ordered, + start, + tight: _, + items, + .. + } => { + if *ordered { + match start { + Some(start) if *start != 1 => { + let _ = write!(html, "
      \n"); + } + _ => html.push_str("
        \n"), + } + } else { + html.push_str("
          \n"); + } + for item in items { + if let DocBlock::ListItem { task, children, .. } = item { + html.push_str("
        • "); + if let Some(checked) = task { + let _ = write!( + html, + "", + checked = checked, + label = if *checked { "已完成" } else { "未完成" } + ); + } + if let Some(first) = children.first() { + if let DocBlock::Paragraph { content, .. } = first { + render_inlines(html, content, model, ctx, current, assets); + for child in &children[1..] { + render_block(html, child, model, ctx, current, assets); + } + } else { + for child in children { + render_block(html, child, model, ctx, current, assets); + } + } + } + html.push_str("
        • \n"); + } + } + html.push_str(if *ordered { "
      \n" } else { "\n" }); + } + DocBlock::ListItem { children, .. } => { + html.push_str("
    1. "); + for child in children { + render_block(html, child, model, ctx, current, assets); + } + html.push_str("
    2. \n"); + } + DocBlock::BlockQuote { children, .. } => { + html.push_str("
      \n"); + render_blocks(html, children, model, ctx, current, assets); + html.push_str("
      \n"); + } + DocBlock::CodeBlock { + span, + info, + literal, + } => { + let resource = model + .semantic + .as_ref() + .and_then(|projection| projection.resource_for_span(*span)); + let language = info.split_whitespace().next().unwrap_or(""); + let _ = write!( + html, + "
      ", + resource + .map(|resource| format!( + " data-source-id=\"{}\"", + escape_attr(&source_id( + &model.document.identity.module_id, + resource.span, + "resource-code" + )) + )) + .unwrap_or_default() + ); + if !language.is_empty() { + let _ = write!( + html, + "{}", + escape_text(language) + ); + } + let _ = write!( + html, + "
      {}
      \n", + escape_text(literal) + ); + } + DocBlock::Table { + alignments, + header, + rows, + .. + } => { + html.push_str("
      \n"); + if !header.is_empty() { + html.push_str(""); + for (index, cell) in header.iter().enumerate() { + let align = alignments.get(index).copied().unwrap_or(TableAlign::None); + let _ = write!(html, "", align_attr(align)); + render_inlines(html, cell, model, ctx, current, assets); + html.push_str(""); + } + html.push_str("\n"); + } + if !rows.is_empty() { + html.push_str("\n"); + for row in rows { + html.push_str(""); + for (index, cell) in row.iter().enumerate() { + let align = alignments.get(index).copied().unwrap_or(TableAlign::None); + let _ = write!(html, "", align_attr(align)); + render_inlines(html, cell, model, ctx, current, assets); + html.push_str(""); + } + html.push_str("\n"); + } + html.push_str("\n"); + } + html.push_str("
      \n"); + } + DocBlock::MathBlock { span, literal } => { + let _ = write!( + html, + "
      {}公式原文 · 未渲染数学
      \n", + escape_attr(&source_id( + &model.document.identity.module_id, + *span, + "resource-formula" + )), + escape_text(literal) + ); + } + DocBlock::ThematicBreak { .. } => html.push_str("
      \n"), + DocBlock::HtmlBlock { .. } => { + html.push_str( + "
      已忽略原始 HTML 内容(安全默认)。源码态可查看原文。
      \n", + ); + } + DocBlock::Other { .. } => {} + } +} + +fn resolve_heading_unit( + model: &PresentationModel, + heading_span: SourceSpan, + level: u8, +) -> Option<&crate::semantic::SemanticUnit> { + let projection = model.semantic.as_ref()?; + // A function heading maps to its function unit exactly; never borrow the + // ancestor function for H3/H4 sections (that would duplicate DOM ids). + if let Some(function) = projection + .functions + .iter() + .find(|function| function.heading_span == heading_span) + { + if let Some(unit) = projection + .units + .iter() + .find(|unit| unit.id == function.unit_id) + { + return Some(unit); + } + } + projection + .units + .iter() + .filter(|unit| unit.level == level && unit.span == heading_span) + .min_by_key(|unit| unit.span.len()) + .or_else(|| projection.unit_for_heading(heading_span, level)) +} + +fn display_heading_content( + content: &[Inline], + unit: Option<&crate::semantic::SemanticUnit>, +) -> (Option<(&'static str, &'static str)>, Vec) { + let Some(unit) = unit else { + return (None, content.to_vec()); + }; + let plain: String = content.iter().map(Inline::plain_text).collect(); + for (prefix, badge, data) in [ + ("@exec ", "EXEC", "exec"), + ("@knowledge ", "KNOWLEDGE", "knowledge"), + ] { + if let Some(rest) = plain.strip_prefix(prefix) { + if normalize_heading_name(rest) == unit.name { + return ( + Some((badge, data)), + strip_prefix_from_inlines(content, prefix), + ); + } + } + } + (None, content.to_vec()) +} + +fn normalize_heading_name(raw: &str) -> String { + // Name comparison here is only a display heuristic; the Core already + // decided the semantic name. Collapse whitespace and trim. + raw.split_whitespace().collect::>().join(" ") +} + +fn strip_prefix_from_inlines(content: &[Inline], prefix: &str) -> Vec { + let mut remaining = prefix.len(); + let mut out = Vec::new(); + for inline in content { + if remaining == 0 { + out.push(inline.clone()); + continue; + } + match inline { + Inline::Text { span, literal } => { + if remaining >= literal.len() { + remaining -= literal.len(); + } else { + let cut = remaining; + remaining = 0; + let rest = &literal[cut..]; + if !rest.is_empty() { + out.push(Inline::Text { + span: *span, + literal: rest.to_string(), + }); + } + } + } + other => { + remaining = 0; + out.push(other.clone()); + } + } + } + out +} + +fn render_inlines( + html: &mut String, + inlines: &[Inline], + model: &PresentationModel, + ctx: &RenderContext, + current: &SafeRelativePath, + assets: &AssetBundle, +) { + let _ = assets; + for inline in inlines { + render_inline(html, inline, model, ctx, current); + } +} + +fn render_inline( + html: &mut String, + inline: &Inline, + model: &PresentationModel, + ctx: &RenderContext, + current: &SafeRelativePath, +) { + let projection = model.semantic.as_ref(); + match inline { + Inline::Text { span, literal } => { + // A text node can itself be the payload of an inline code carrier; + // anchors are applied by the enclosing carrier branch below. + let _ = span; + html.push_str(&escape_text(literal)); + } + Inline::Code { + span, + literal, + ticks: _, + } => { + let anchor = projection.and_then(|projection| projection.statement_for_inline(*span)); + html.push_str("'); + html.push_str(&escape_text(literal)); + html.push_str(""); + } + Inline::Strong { span, children } => { + let anchor = projection.and_then(|projection| projection.statement_for_inline(*span)); + html.push_str("'); + render_inlines(html, children, model, ctx, current, assets_placeholder()); + html.push_str(""); + } + Inline::Emph { span, children } => { + let anchor = projection.and_then(|projection| projection.statement_for_inline(*span)); + html.push_str("'); + render_inlines(html, children, model, ctx, current, assets_placeholder()); + html.push_str(""); + } + Inline::Strikethrough { children, .. } => { + html.push_str(""); + render_inlines(html, children, model, ctx, current, assets_placeholder()); + html.push_str(""); + } + Inline::Link { + span, + url, + title, + children, + } => { + let reference = projection.and_then(|projection| projection.reference_for_span(*span)); + let state = reference.map(|reference| reference.state.as_str()); + let target = resolve_link(url, current, &ctx.links); + match target { + Some(href) => { + let _ = write!(html, "'); + render_inlines(html, children, model, ctx, current, assets_placeholder()); + html.push_str(""); + } + None => { + html.push_str( + "", + ); + render_inlines(html, children, model, ctx, current, assets_placeholder()); + html.push_str(""); + } + } + } + Inline::Image { + url, alt, title, .. + } => { + // Remote or unverified images are never loaded implicitly. + let _ = (url, title); + let _ = write!( + html, + "[图片已阻止自动加载:{}]", + escape_text(if alt.is_empty() { + "无替代文本" + } else { + alt + }) + ); + } + Inline::Math { + span, + literal, + display, + } => { + let resource = projection.and_then(|projection| projection.resource_for_span(*span)); + let _ = write!( + html, + "{}", + resource + .map(|resource| format!( + " data-source-id=\"{}\"", + escape_attr(&source_id( + &model.document.identity.module_id, + resource.span, + "resource-formula" + )) + )) + .unwrap_or_default(), + escape_text(literal) + ); + let _ = display; + } + Inline::HtmlInline { .. } => { + html.push_str("已忽略原始行内 HTML"); + } + Inline::SoftBreak { .. } => html.push(' '), + Inline::LineBreak { .. } => html.push_str("
      "), + Inline::Other { .. } => {} + } +} + +// The renderer is a struct method in the hot path; this helper keeps the +// recursive inline signature small without a second renderer. +fn assets_placeholder() -> &'static AssetBundle { + AssetBundle::get() +} + +fn align_attr(align: TableAlign) -> &'static str { + match align { + TableAlign::None => "", + TableAlign::Left => " style=\"text-align:left\"", + TableAlign::Center => " style=\"text-align:center\"", + TableAlign::Right => " style=\"text-align:right\"", + } +} + +fn icon(path: &str) -> String { + format!( + "" + ) +} + +fn source_id_id(model: &PresentationModel, span: SourceSpan) -> String { + escape_attr(&source_id( + &model.document.identity.module_id, + span, + "heading", + )) +} + +fn escape_text(raw: &str) -> String { + let mut out = String::with_capacity(raw.len() + 8); + for ch in raw.chars() { + match ch { + '&' => out.push_str("&"), + '<' => out.push_str("<"), + '>' => out.push_str(">"), + '"' => out.push_str("""), + '\'' => out.push_str("'"), + _ => out.push(ch), + } + } + out +} + +fn escape_attr(raw: &str) -> String { + escape_text(raw) +} + +fn csp_policy() -> &'static str { + "default-src 'none'; style-src 'self'; script-src 'self' file:; img-src 'self' data:; font-src 'self'; connect-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; object-src 'none'" +} + +fn percent_encode_path(raw: &str) -> String { + let mut out = String::with_capacity(raw.len()); + for byte in raw.as_bytes() { + let unreserved = + byte.is_ascii_alphanumeric() || matches!(*byte, b'-' | b'_' | b'.' | b'~' | b'/'); + if unreserved { + out.push(*byte as char); + } else { + use std::fmt::Write as _; + let _ = write!(out, "%{byte:02X}"); + } + } + out +} + +/// Sanitize one Markdown link destination. Returns `None` for schemes the +/// reader must never expose (`javascript:`, `data:`, `file:`, ...) and for +/// console-control-looking payloads. +fn resolve_link(raw: &str, current: &SafeRelativePath, policy: &LinkPolicy) -> Option { + let url = raw.trim(); + if url.is_empty() { + return None; + } + if url.chars().any(|ch| ch.is_control() || ch == '\u{7f}') { + return None; + } + // Explicit scheme: only http/https/mailto are navigable. A single-letter + // prefix is a Windows drive, not a scheme. + if let Some(colon) = url.find(':') { + let scheme = &url[..colon]; + if scheme.len() > 1 && scheme.chars().all(|ch| ch.is_ascii_alphabetic()) { + return match scheme.to_ascii_lowercase().as_str() { + "http" | "https" | "mailto" => Some(url.to_string()), + _ => None, + }; + } + } + if url.starts_with("//") { + return None; + } + if url.starts_with('#') { + return Some(url.to_string()); + } + if url.starts_with('/') { + return match policy { + LinkPolicy::LocalServer => Some(url.to_string()), + LinkPolicy::StaticRelative { .. } => None, + }; + } + let path_part = url.split(['?', '#']).next().unwrap_or(url); + if path_part.ends_with(".mq.md") { + let joined = match current.parent() { + Some(dir) => format!("{dir}/{path_part}"), + None => path_part.to_string(), + }; + if let Ok(target) = SafeRelativePath::parse(&joined) { + return Some(policy.document_href(current, &target)); + } + return None; + } + Some(url.to_string()) +} diff --git a/src/semantic.rs b/src/semantic.rs new file mode 100644 index 0000000..0cc05e9 --- /dev/null +++ b/src/semantic.rs @@ -0,0 +1,941 @@ +//! Analysis v2 validation and static semantic projection. +//! +//! This module is the only consumer of the public Analysis JSON. It verifies +//! protocol identity first, then projects functions/units/statements/diagnostics +//! into View-owned types with **validated** source spans. A span that is out of +//! range or not on a UTF-8 boundary is dropped with an explicit View warning +//! instead of being pointed at nearby text (RFC-VIEW-0001 §4.3, §8.2). + +use crate::error::{ViewError, ViewResult}; +use crate::source_map::{sha256_hex, sha256_prefixed, SourceIndex, SourceSpan}; +use crate::version; +use serde::Deserialize; +use serde_json::Value; + +/// Stable DOM identity for one source-bound annotation, local to this document +/// and run. It is not a cross-edit identity. +pub fn source_id(module_id: &str, span: SourceSpan, kind: &str) -> String { + let material = format!("{module_id}\0{}:{}:{}", span.start, span.end, kind); + sha256_hex(material.as_bytes())[..16].to_string() +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum UnitKind { + Root, + Namespace, + Function, + Knowledge, + Section, + Other, +} + +#[derive(Debug, Clone)] +pub struct SemanticUnit { + pub id: String, + pub name: String, + pub level: u8, + pub kind: UnitKind, + pub function: Option, + pub span: SourceSpan, +} + +#[derive(Debug, Clone)] +pub struct FunctionParam { + pub name: String, + pub ty: String, + pub required: bool, + pub default: Option, + pub span: Option, +} + +#[derive(Debug, Clone)] +pub struct FunctionSignature { + pub kind: String, + pub params: Vec, +} + +#[derive(Debug, Clone)] +pub struct SemanticFunction { + pub id: String, + pub unit_id: String, + pub local_name: String, + pub namespace: Option, + pub span: SourceSpan, + pub heading_span: SourceSpan, + pub signature: FunctionSignature, + pub effects: Vec, + pub statements: Vec, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum StatementKind { + Assign, + Expression, + Branch, + Loop, + Return, + Other, +} + +impl StatementKind { + pub fn label(&self) -> &'static str { + match self { + StatementKind::Assign => "赋值", + StatementKind::Expression => "表达式", + StatementKind::Branch => "条件分支", + StatementKind::Loop => "循环", + StatementKind::Return => "返回", + StatementKind::Other => "语句", + } + } + + pub fn data_value(&self) -> &'static str { + match self { + StatementKind::Assign => "assign", + StatementKind::Expression => "expression", + StatementKind::Branch => "branch", + StatementKind::Loop => "loop", + StatementKind::Return => "return", + StatementKind::Other => "other", + } + } +} + +#[derive(Debug, Clone)] +pub struct SemanticStatement { + pub kind: StatementKind, + /// Header span for control flow, payload span for simple statements. + pub span: SourceSpan, + /// For `if` arms and `while` conditions: the condition text span as the + /// compiler recorded it. + pub condition_span: Option, + pub arms: Vec, + pub body: Vec, + /// Target name for assignments (local name or `index` form), for static + /// outline display only. Never a runtime value. + pub target: Option, +} + +#[derive(Debug, Clone)] +pub struct SemanticArm { + pub span: Option, + pub condition_span: Option, + pub body: Vec, +} + +impl SemanticFunction { + /// Depth-first statement walk in source order. + pub fn flattened_statements(&self) -> Vec<&SemanticStatement> { + let mut out = Vec::new(); + for statement in &self.statements { + collect_statements(statement, &mut out); + } + out + } +} + +fn collect_statements<'a>(statement: &'a SemanticStatement, out: &mut Vec<&'a SemanticStatement>) { + out.push(statement); + for arm in &statement.arms { + for child in &arm.body { + collect_statements(child, out); + } + } + for child in &statement.body { + collect_statements(child, out); + } +} + +#[derive(Debug, Clone)] +pub struct StaticResource { + pub id: String, + pub kind: String, + pub span: SourceSpan, + pub content_digest: String, + pub language: Option, + pub display: bool, +} + +#[derive(Debug, Clone)] +pub struct StaticImport { + pub alias: String, + pub target: String, + pub resolved: Option, + pub span: SourceSpan, +} + +#[derive(Debug, Clone)] +pub struct StaticReference { + pub url: String, + pub span: SourceSpan, + pub state: String, + pub target_module: Option, + pub target_unit: Option, +} + +#[derive(Debug, Clone)] +pub struct StaticCall { + pub state: String, + pub target: Option, + pub function: Option, + pub span: SourceSpan, +} + +#[derive(Debug, Clone)] +pub struct CoreDiagnostic { + pub module: Option, + pub relative_path: Option, + pub span: Option, + pub line: Option, + pub column: Option, + pub severity: String, + pub code: String, + pub message: String, + pub hints: Vec, +} + +#[derive(Debug, Clone)] +pub struct ViewWarning { + pub code: String, + pub message: String, + pub span: Option, +} + +#[derive(Debug, Clone)] +pub struct ModuleSummary { + pub id: String, + pub package_instance_id: String, + pub relative_path: String, + pub source_digest: String, +} + +#[derive(Debug, Clone)] +pub struct SemanticProjection { + pub analysis_sha256: String, + pub analysis_digest: String, + pub producer_version: String, + pub markdown_profile: String, + pub project_root_id: String, + pub identity_kind: String, + pub lock_digest: String, + pub stdlib_version: Option, + pub module_id: String, + pub package_instance_id: String, + pub relative_path: String, + pub source_digest: String, + pub units: Vec, + pub functions: Vec, + pub resources: Vec, + pub imports: Vec, + pub references: Vec, + pub calls: Vec, + pub diagnostics: Vec, + pub warnings: Vec, + pub modules: Vec, +} + +#[derive(Debug)] +pub struct VerifiedAnalysis { + pub projection: SemanticProjection, +} + +impl SemanticProjection { + pub fn unit_for_heading(&self, span: SourceSpan, level: u8) -> Option<&SemanticUnit> { + self.units + .iter() + .filter(|unit| unit.level == level && unit.span.contains(span)) + .min_by_key(|unit| unit.span.len()) + } + + pub fn function_by_heading(&self, span: SourceSpan) -> Option<&SemanticFunction> { + self.functions + .iter() + .find(|function| function.heading_span == span) + .or_else(|| { + self.functions + .iter() + .find(|function| function.span.contains(span)) + }) + } + + /// All statements of all functions, flattened in deterministic order. + pub fn all_statements(&self) -> Vec<(&SemanticFunction, &SemanticStatement)> { + let mut out = Vec::new(); + for function in &self.functions { + for statement in function.flattened_statements() { + out.push((function, statement)); + } + } + out + } + + /// The innermost statement whose span is contained in `inline_span`. + pub fn statement_for_inline( + &self, + inline_span: SourceSpan, + ) -> Option<(&SemanticFunction, &SemanticStatement)> { + self.all_statements() + .into_iter() + .filter(|(_, statement)| { + statement.span.start >= inline_span.start + && statement.span.end <= inline_span.end + && !statement.span.is_empty() + }) + .max_by_key(|(_, statement)| statement.span.start) + } + + pub fn resource_for_span(&self, span: SourceSpan) -> Option<&StaticResource> { + self.resources + .iter() + .find(|resource| resource.span == span || resource.span.contains(span)) + } + + pub fn reference_for_span(&self, span: SourceSpan) -> Option<&StaticReference> { + self.references + .iter() + .find(|reference| reference.span == span || reference.span.contains(span)) + } +} + +// --------------------------------------------------------------------------- +// Raw protocol types (additive fields are tolerated and ignored). +// --------------------------------------------------------------------------- + +#[derive(Debug, Deserialize)] +struct RawAnalysis { + schema: String, + schema_version: u32, + producer: RawProducer, + project: RawProject, + modules: Vec, + #[serde(default)] + diagnostics: Vec, +} + +#[derive(Debug, Deserialize)] +struct RawProducer { + #[serde(default)] + name: String, + #[serde(default)] + version: String, + #[serde(default)] + markdown_profile: String, +} + +#[derive(Debug, Deserialize)] +struct RawProject { + #[serde(default)] + root_id: String, + #[serde(default)] + identity_kind: String, + #[serde(default)] + lock_digest: String, + #[serde(default)] + stdlib: Option, +} + +#[derive(Debug, Deserialize)] +struct RawStdlib { + #[serde(default)] + version: String, +} + +#[derive(Debug, Deserialize)] +struct RawModule { + #[serde(default)] + id: String, + #[serde(default)] + package_instance_id: String, + #[serde(default)] + relative_path: String, + #[serde(default)] + source_digest: String, + #[serde(default)] + units: Vec, + #[serde(default)] + functions: Vec, + #[serde(default)] + imports: Vec, + #[serde(default)] + references: Vec, + #[serde(default)] + calls: Vec, + #[serde(default)] + resources: Vec, +} + +#[derive(Debug, Deserialize)] +struct RawUnit { + #[serde(default)] + id: String, + #[serde(default)] + name: String, + #[serde(default)] + level: u8, + #[serde(default)] + kind: String, + #[serde(default)] + function: Option, + #[serde(default)] + span: Option, +} + +#[derive(Debug, Deserialize)] +struct RawFunction { + #[serde(default)] + id: String, + #[serde(default)] + unit_id: String, + #[serde(default)] + local_name: String, + #[serde(default)] + namespace: Option, + #[serde(default)] + span: Option, + #[serde(default)] + heading_span: Option, + #[serde(default)] + signature: Option, + #[serde(default)] + effects: Vec, + #[serde(default)] + body: Vec, +} + +#[derive(Debug, Deserialize)] +struct RawSignature { + #[serde(default)] + kind: String, + #[serde(default)] + params: Vec, +} + +#[derive(Debug, Deserialize)] +struct RawParam { + #[serde(default)] + name: String, + #[serde(default, rename = "type")] + ty: Option, + #[serde(default)] + required: bool, + #[serde(default)] + default: Option, + #[serde(default)] + span: Option, +} + +#[derive(Debug, Deserialize)] +struct RawStatement { + #[serde(default)] + kind: String, + #[serde(default)] + span: Option, + #[serde(default)] + condition_span: Option, + #[serde(default)] + arms: Vec, + #[serde(default)] + body: Vec, + #[serde(default)] + target: Option, +} + +#[derive(Debug, Deserialize)] +struct RawArm { + #[serde(default)] + span: Option, + #[serde(default)] + condition_span: Option, + #[serde(default)] + body: Vec, +} + +#[derive(Debug, Deserialize)] +struct RawResource { + #[serde(default)] + id: String, + #[serde(default)] + kind: String, + #[serde(default)] + span: Option, + #[serde(default)] + content_digest: String, + #[serde(default)] + language: Option, + #[serde(default)] + display: bool, +} + +#[derive(Debug, Deserialize)] +struct RawImport { + #[serde(default)] + alias: String, + #[serde(default)] + target: String, + #[serde(default)] + resolved: Option, + #[serde(default)] + span: Option, +} + +#[derive(Debug, Deserialize)] +struct RawReference { + #[serde(default)] + url: String, + #[serde(default)] + state: String, + #[serde(default)] + target_module: Option, + #[serde(default)] + target_unit: Option, + #[serde(default)] + span: Option, +} + +#[derive(Debug, Deserialize)] +struct RawCall { + #[serde(default)] + state: String, + #[serde(default)] + target: Option, + #[serde(default)] + function: Option, + #[serde(default)] + span: Option, +} + +#[derive(Debug, Deserialize)] +struct RawDiagnostic { + #[serde(default)] + module: Option, + #[serde(default)] + relative_path: Option, + #[serde(default)] + span: Option, + #[serde(default)] + line: Option, + #[serde(default)] + column: Option, + #[serde(default)] + severity: String, + #[serde(default)] + code: String, + #[serde(default)] + message: String, + #[serde(default)] + hints: Vec, +} + +// --------------------------------------------------------------------------- +// Validation +// --------------------------------------------------------------------------- + +/// Verify Analysis bytes against the exact source and project the static facts. +/// +/// Rejects protocol incompatibility and source-digest mismatch as errors; drops +/// individual invalid spans as warnings so the prose stays readable. +pub fn verify_analysis( + analysis_bytes: &[u8], + source: &str, + source_index: &SourceIndex, + expected_relative_path: &str, +) -> ViewResult { + let raw: RawAnalysis = + serde_json::from_slice(analysis_bytes).map_err(|err| ViewError::AnalysisFailed { + detail: format!("Analysis v2 is not valid JSON: {err}"), + })?; + if raw.schema != "marqdo.analysis" { + return Err(ViewError::ProtocolIncompatible { + detail: format!("unexpected Analysis schema {:?}", raw.schema), + }); + } + if raw.schema_version != version::ANALYSIS_PROTOCOL { + return Err(ViewError::ProtocolIncompatible { + detail: format!( + "Analysis schema_version {} is not supported (View implements v{})", + raw.schema_version, + version::ANALYSIS_PROTOCOL + ), + }); + } + if raw.producer.name != "marqdo" { + return Err(ViewError::ProtocolIncompatible { + detail: format!( + "Analysis producer.name {:?} is not `marqdo`", + raw.producer.name + ), + }); + } + if raw.producer.markdown_profile != "marqdo.md.v1" { + return Err(ViewError::ProtocolIncompatible { + detail: format!( + "unexpected Markdown profile {:?}; this View targets marqdo.md.v1", + raw.producer.markdown_profile + ), + }); + } + if raw.project.root_id.is_empty() { + return Err(ViewError::AnalysisFailed { + detail: "Analysis project.root_id is empty".to_string(), + }); + } + + let actual_digest = sha256_hex(source.as_bytes()); + let module = raw + .modules + .iter() + .find(|module| module.relative_path == expected_relative_path) + .ok_or_else(|| ViewError::AnalysisFailed { + detail: format!("Analysis has no module for {expected_relative_path}"), + })?; + if module.source_digest != actual_digest { + return Err(ViewError::SourceMismatch { + expected: module.source_digest.clone(), + actual: actual_digest, + }); + } + + let mut warnings = Vec::new(); + let mut valid_span = |span: Option, what: &str| -> Option { + let span = span?; + if source_index.validate_span_bytes(source.as_bytes(), span) { + Some(span) + } else { + warnings.push(ViewWarning { + code: "view.source_span_invalid".to_string(), + message: format!("{what} 的字节区间超出源码或不在 UTF-8 边界,已跳过该标注"), + span: Some(span), + }); + None + } + }; + + let units: Vec = module + .units + .iter() + .filter_map(|unit| { + let span = valid_span(unit.span, "语义单元")?; + Some(SemanticUnit { + id: unit.id.clone(), + name: unit.name.clone(), + level: unit.level, + kind: match unit.kind.as_str() { + "root" => UnitKind::Root, + "namespace" => UnitKind::Namespace, + "function" => UnitKind::Function, + "knowledge" => UnitKind::Knowledge, + "section" => UnitKind::Section, + _ => UnitKind::Other, + }, + function: unit.function.clone(), + span, + }) + }) + .collect(); + + let functions: Vec = module + .functions + .iter() + .filter_map(|function| { + let span = valid_span(function.span, "函数范围")?; + let heading_span = valid_span(function.heading_span, "函数标题")?; + let statements = function + .body + .iter() + .filter_map(|statement| convert_statement(statement, &mut valid_span)) + .collect(); + Some(SemanticFunction { + id: function.id.clone(), + unit_id: function.unit_id.clone(), + local_name: function.local_name.clone(), + namespace: function.namespace.clone(), + span, + heading_span, + signature: FunctionSignature { + kind: function + .signature + .as_ref() + .map(|signature| signature.kind.clone()) + .unwrap_or_default(), + params: function + .signature + .as_ref() + .map(|signature| { + signature + .params + .iter() + .map(|param| FunctionParam { + name: param.name.clone(), + ty: param.ty.clone().unwrap_or_default(), + required: param.required, + default: param.default.as_ref().map(compact_value), + span: param.span.filter(|span| { + source_index.validate_span_bytes(source.as_bytes(), *span) + }), + }) + .collect() + }) + .unwrap_or_default(), + }, + effects: function.effects.clone(), + statements, + }) + }) + .collect(); + + let resources: Vec = module + .resources + .iter() + .filter(|resource| matches!(resource.kind.as_str(), "formula" | "code")) + .filter_map(|resource| { + let span = valid_span(resource.span, "资源")?; + Some(StaticResource { + id: resource.id.clone(), + kind: resource.kind.clone(), + span, + content_digest: resource.content_digest.clone(), + language: resource.language.clone(), + display: resource.display, + }) + }) + .collect(); + + let imports: Vec = module + .imports + .iter() + .filter_map(|import| { + Some(StaticImport { + alias: import.alias.clone(), + target: import.target.clone(), + resolved: import.resolved.clone(), + span: valid_span(import.span, "导入声明")?, + }) + }) + .collect(); + + let references: Vec = module + .references + .iter() + .filter_map(|reference| { + Some(StaticReference { + url: reference.url.clone(), + state: reference.state.clone(), + target_module: reference.target_module.clone(), + target_unit: reference.target_unit.clone(), + span: valid_span(reference.span, "Markdown 引用")?, + }) + }) + .collect(); + + let calls: Vec = module + .calls + .iter() + .filter_map(|call| { + Some(StaticCall { + state: call.state.clone(), + target: call.target.clone(), + function: call.function.clone(), + span: valid_span(call.span, "调用点")?, + }) + }) + .collect(); + + let diagnostics: Vec = raw + .diagnostics + .iter() + .map(|diagnostic| { + let span = diagnostic + .span + .filter(|span| source_index.validate_span_bytes(source.as_bytes(), *span)); + CoreDiagnostic { + module: diagnostic.module.clone(), + relative_path: diagnostic.relative_path.clone(), + span, + line: diagnostic.line, + column: diagnostic.column, + severity: if diagnostic.severity.is_empty() { + "error".to_string() + } else { + diagnostic.severity.clone() + }, + code: diagnostic.code.clone(), + message: diagnostic.message.clone(), + hints: diagnostic.hints.clone(), + } + }) + .collect(); + + let modules = raw + .modules + .iter() + .map(|module| ModuleSummary { + id: module.id.clone(), + package_instance_id: module.package_instance_id.clone(), + relative_path: module.relative_path.clone(), + source_digest: module.source_digest.clone(), + }) + .collect(); + + Ok(VerifiedAnalysis { + projection: SemanticProjection { + analysis_sha256: sha256_hex(analysis_bytes), + analysis_digest: sha256_prefixed(analysis_bytes), + producer_version: raw.producer.version.clone(), + markdown_profile: raw.producer.markdown_profile.clone(), + project_root_id: raw.project.root_id.clone(), + identity_kind: raw.project.identity_kind.clone(), + lock_digest: raw.project.lock_digest.clone(), + stdlib_version: raw.project.stdlib.as_ref().map(|s| s.version.clone()), + module_id: module.id.clone(), + package_instance_id: module.package_instance_id.clone(), + relative_path: module.relative_path.clone(), + source_digest: module.source_digest.clone(), + units, + functions, + resources, + imports, + references, + calls, + diagnostics, + warnings, + modules, + }, + }) +} + +fn convert_statement( + raw: &RawStatement, + valid_span: &mut impl FnMut(Option, &str) -> Option, +) -> Option { + let span = valid_span(raw.span, "语句")?; + let kind = match raw.kind.as_str() { + "assign" => StatementKind::Assign, + "expression" => StatementKind::Expression, + "branch" => StatementKind::Branch, + "loop" => StatementKind::Loop, + "return" => StatementKind::Return, + _ => StatementKind::Other, + }; + let body = raw + .body + .iter() + .filter_map(|child| convert_statement(child, valid_span)) + .collect(); + let arms = raw + .arms + .iter() + .map(|arm| SemanticArm { + span: valid_span(arm.span, "分支臂"), + condition_span: valid_span(arm.condition_span, "分支条件"), + body: arm + .body + .iter() + .filter_map(|child| convert_statement(child, valid_span)) + .collect(), + }) + .collect(); + Some(SemanticStatement { + kind, + span, + condition_span: valid_span(raw.condition_span, "控制条件"), + arms, + body, + target: raw.target.as_ref().and_then(assignment_target_label), + }) +} + +fn assignment_target_label(target: &Value) -> Option { + match target { + Value::String(name) => Some(name.clone()), + Value::Object(map) => { + if map.get("kind").and_then(Value::as_str) == Some("index") { + Some("索引赋值".to_string()) + } else { + None + } + } + _ => None, + } +} + +fn compact_value(value: &Value) -> String { + match value { + Value::String(text) => text.clone(), + other => { + let text = other.to_string(); + if text.chars().count() > 40 { + format!("{}…", text.chars().take(40).collect::()) + } else { + text + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn analysis(schema_version: u32, digest: &str) -> Vec { + serde_json::json!({ + "schema": "marqdo.analysis", + "schema_version": schema_version, + "producer": {"name": "marqdo", "version": "3.0.0-beta.1", "markdown_profile": "marqdo.md.v1"}, + "project": {"root_id": "root:t@0.1.0", "identity_kind": "manifest", "lock_digest": "", "stdlib": null}, + "modules": [{ + "id": "root:t@0.1.0::index.mq.md", + "package_instance_id": "root:t@0.1.0", + "relative_path": "index.mq.md", + "source_digest": digest, + "units": [], + "functions": [], + "imports": [], + "references": [], + "calls": [], + "resources": [] + }], + "diagnostics": [] + }) + .to_string() + .into_bytes() + } + + #[test] + fn rejects_unknown_schema_major_and_profile() { + let source = "# hi\n"; + let index = SourceIndex::new(source); + let digest = sha256_hex(source.as_bytes()); + let err = + verify_analysis(&analysis(3, &digest), source, &index, "index.mq.md").unwrap_err(); + assert_eq!(err.code(), "view.protocol_incompatible"); + } + + #[test] + fn rejects_digest_mismatch() { + let source = "# hi\n"; + let index = SourceIndex::new(source); + let err = verify_analysis(&analysis(2, &"0".repeat(64)), source, &index, "index.mq.md") + .unwrap_err(); + assert_eq!(err.code(), "view.source_mismatch"); + } + + #[test] + fn projects_valid_analysis() { + let source = "# hi\n"; + let index = SourceIndex::new(source); + let digest = sha256_hex(source.as_bytes()); + let verified = + verify_analysis(&analysis(2, &digest), source, &index, "index.mq.md").unwrap(); + assert_eq!(verified.projection.project_root_id, "root:t@0.1.0"); + assert_eq!(verified.projection.relative_path, "index.mq.md"); + } + + #[test] + fn source_id_is_deterministic_and_bounded() { + let span = SourceSpan::new(1, 5); + let id = source_id("mod", span, "statement"); + assert_eq!(id.len(), 16); + assert_eq!(id, source_id("mod", span, "statement")); + assert_ne!(id, source_id("mod", span, "resource")); + } +} diff --git a/src/server.rs b/src/server.rs new file mode 100644 index 0000000..44e96a5 --- /dev/null +++ b/src/server.rs @@ -0,0 +1,663 @@ +//! Localhost Live reader. +//! +//! Minimal, loopback-only surface (RFC-VIEW-0001 §11.1). Only read APIs are +//! exposed until the explicit-run flow lands; every response carries a strict +//! CSP and the Host header is validated to blunt DNS-rebinding. + +use crate::app::AppContext; +use crate::assets::AssetBundle; +use crate::cli::RuntimeOpts; +use crate::error::{ViewError, ViewResult}; +use crate::presentation::PresentationModel; +use crate::project::SafeRelativePath; +use crate::render::{ReaderRenderer, RenderContext}; +use crate::source_map::sha256_hex; +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; +use tiny_http::{Header, Method, Request, Response, Server, StatusCode}; + +const MAX_URL_BYTES: usize = 2048; +const MAX_QUERY_BYTES: usize = 4096; + +pub fn serve(ctx: AppContext, opts: &RuntimeOpts) -> ViewResult { + let address = format!("{}:{}", opts.host, opts.port); + let server = Server::http(&address).map_err(|err| ViewError::Io { + detail: format!("listen on {address}: {err}"), + })?; + let bound = server.server_addr().to_ip().ok_or_else(|| ViewError::Io { + detail: "server address is not an IP socket".to_string(), + })?; + let port = bound.port(); + let display_host = match opts.host.as_str() { + "localhost" => "localhost".to_string(), + "::1" | "[::1]" => "[::1]".to_string(), + _ => "127.0.0.1".to_string(), + }; + let url = format!("http://{display_host}:{port}/"); + + eprintln!("marqdo view: {url}"); + eprintln!("root: {}", ctx.project().root().display()); + eprintln!( + "{} .mq.md document(s). Ctrl+C to stop.", + ctx.project() + .list_documents() + .map(|docs| docs.len()) + .unwrap_or(0) + ); + if ctx.core_version().is_some() { + eprintln!( + "core: marqdo {} (Analysis v2, Trace v2)", + ctx.core_version().unwrap_or_default() + ); + } else if let Some(note) = ctx.core_note() { + eprintln!("core: unavailable ({note})"); + } + if !opts.no_open { + open_browser(&url); + } + + let state = Arc::new(ServerState { + ctx, + csrf_token: random_token(), + renderer: ReaderRenderer::new(), + cache: Mutex::new(HashMap::new()), + allowed_hosts: allowed_hosts(port), + }); + + loop { + let request = match server.recv() { + Ok(request) => request, + Err(err) => { + eprintln!("view: accept failed: {err}"); + continue; + } + }; + let state = Arc::clone(&state); + std::thread::spawn(move || { + if let Err(err) = handle(&state, request) { + eprintln!("view request error: {err}"); + } + }); + } +} + +struct ServerState { + ctx: AppContext, + csrf_token: String, + renderer: ReaderRenderer, + cache: Mutex>, + allowed_hosts: Vec, +} + +struct CacheEntry { + source_digest: String, + model: PresentationModel, +} + +impl ServerState { + /// Load one document, reusing a cached model only while the exact source + /// bytes are unchanged (no path-only cache identity, RFC §6.5). + fn load(&self, relative: &SafeRelativePath) -> ViewResult { + let digest = self.ctx.project().source_digest(relative)?; + if let Ok(cache) = self.cache.lock() { + if let Some(entry) = cache.get(relative.as_str()) { + if entry.source_digest == digest { + return Ok(entry.model.clone()); + } + } + } + let model = self.ctx.load(relative)?; + if let Ok(mut cache) = self.cache.lock() { + if cache.len() < 64 { + cache.insert( + relative.as_str().to_string(), + CacheEntry { + source_digest: digest, + model: model.clone(), + }, + ); + } + } + Ok(model) + } +} + +fn handle(state: &ServerState, request: Request) -> ViewResult<()> { + let method = request.method().clone(); + if !matches!(method, Method::Get | Method::Head) { + return respond_text( + request, + StatusCode(405), + "text/plain; charset=utf-8", + "method not allowed\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + } + let is_head = method == Method::Head; + + if !host_is_allowed(&request, &state.allowed_hosts) { + return respond_text( + request, + StatusCode(400), + "text/plain; charset=utf-8", + "invalid Host header\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + } + + let raw_url = request.url().to_string(); + if raw_url.len() > MAX_URL_BYTES { + return respond_text( + request, + StatusCode(414), + "text/plain; charset=utf-8", + "request target too long\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + } + let (path_part, query) = split_url(&raw_url); + if query.len() > MAX_QUERY_BYTES { + return respond_text( + request, + StatusCode(414), + "text/plain; charset=utf-8", + "query too long\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + } + + if let Some(hashed_name) = path_part.strip_prefix("/assets/") { + return serve_asset(request, hashed_name, is_head); + } + + match path_part { + "/" | "/index.html" => { + let entry = state.ctx.project().entry().relative.clone(); + match state.load(&entry) { + Ok(model) => serve_page(state, request, &model, is_head), + Err(err) => serve_error_page(request, &err, is_head), + } + } + "/file" => { + let Some(raw_path) = query_param(query, "path") else { + return respond_text( + request, + StatusCode(400), + "text/plain; charset=utf-8", + "missing path\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + }; + let Some(decoded) = percent_decode(&raw_path) else { + return respond_text( + request, + StatusCode(400), + "text/plain; charset=utf-8", + "malformed path\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + }; + let relative = match SafeRelativePath::parse(&decoded) { + Ok(relative) => relative, + Err(err) => { + return respond_text( + request, + StatusCode(403), + "text/plain; charset=utf-8", + format!("{}\n", err.code()).into_bytes(), + CacheKind::NoStore, + ) + } + }; + if state.ctx.project().read_source(&relative).is_err() { + return respond_text( + request, + StatusCode(404), + "text/plain; charset=utf-8", + "document not found\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + } + match state.load(&relative) { + Ok(model) => serve_page(state, request, &model, is_head), + Err(err) => serve_error_page(request, &err, is_head), + } + } + "/api/document" => { + let relative = match query_param(query, "path") + .and_then(|raw| percent_decode(&raw)) + .map(|decoded| SafeRelativePath::parse(&decoded)) + { + Some(Ok(relative)) => relative, + Some(Err(err)) => { + return respond_json_error(request, StatusCode(400), &err); + } + None => state.ctx.project().entry().relative.clone(), + }; + match state.load(&relative) { + Ok(model) => serve_document_json(request, &model), + Err(err) => respond_json_error(request, StatusCode(500), &err), + } + } + "/api/health" => { + let documents = state + .ctx + .project() + .list_documents() + .map(|documents| documents.len()) + .unwrap_or(0); + let health = serde_json::json!({ + "schema": "marqdo.view-health", + "schema_version": 1, + "ok": true, + "view": { + "name": "marqdo-view", + "version": env!("CARGO_PKG_VERSION"), + }, + "core": { + "version": state.ctx.core_version(), + }, + "protocols": { + "tool": crate::version::TOOL_PROTOCOL, + "analysis": crate::version::ANALYSIS_PROTOCOL, + "trace": crate::version::TRACE_PROTOCOL, + }, + "documents": documents, + "run_api": false, + }); + respond_json(request, StatusCode(200), &health) + } + _ => respond_text( + request, + StatusCode(404), + "text/plain; charset=utf-8", + "not found\n".as_bytes().to_vec(), + CacheKind::NoStore, + ), + } +} + +fn serve_page( + state: &ServerState, + request: Request, + model: &PresentationModel, + is_head: bool, +) -> ViewResult<()> { + let ctx = RenderContext { + links: crate::render::LinkPolicy::LocalServer, + live: true, + csrf_token: Some(state.csrf_token.clone()), + run_available: false, + }; + let page = state.renderer.render(model, &ctx); + respond_html(request, page.html.into_bytes(), is_head) +} + +fn serve_error_page(request: Request, err: &ViewError, is_head: bool) -> ViewResult<()> { + let html = format!( + "Marqdo View · 错误

      无法生成阅读页面

      {code}

      {message}

      返回入口

      ", + code = escape_html(err.code()), + message = escape_html(&err.to_string()), + ); + respond_html(request, html.into_bytes(), is_head) +} + +fn serve_document_json(request: Request, model: &PresentationModel) -> ViewResult<()> { + let semantic = model.semantic.as_ref(); + let doc = serde_json::json!({ + "schema": "marqdo.view-document", + "schema_version": 1, + "title": model.title, + "document": { + "relative_path": model.document.identity.relative_path, + "module_id": model.document.identity.module_id, + "source_sha256": sha256_hex(model.document.source.as_bytes()), + }, + "source_status": model.source_status.data_value(), + "semantics_usable": model.source_status.semantics_usable(), + "analysis": semantic.map(|projection| serde_json::json!({ + "digest": projection.analysis_digest, + "schema_version": crate::version::ANALYSIS_PROTOCOL, + "producer_version": projection.producer_version, + "project_root_id": projection.project_root_id, + "functions": projection.functions.len(), + "units": projection.units.len(), + "diagnostics": projection.diagnostics.len(), + })), + "outline": model.outline.iter().map(|entry| serde_json::json!({ + "label": entry.label, + "anchor": entry.anchor, + "detail": entry.detail, + "kind": match entry.kind { + crate::presentation::OutlineKind::Function => "function", + crate::presentation::OutlineKind::Knowledge => "knowledge", + crate::presentation::OutlineKind::Section => "section", + }, + })).collect::>(), + "navigation": { + "documents": model.navigation.documents.iter().map(|doc| doc.as_str()).collect::>(), + "welcome": model.navigation.welcome, + }, + "note": "Read-only PresentationModel summary; the document was not executed.", + }); + respond_json(request, StatusCode(200), &doc) +} + +fn serve_asset(request: Request, hashed_name: &str, is_head: bool) -> ViewResult<()> { + let bundle = AssetBundle::get(); + if hashed_name == bundle.hashed_css_name() { + return respond_asset( + request, + bundle.css_bytes().to_vec(), + "text/css; charset=utf-8", + is_head, + ); + } + let Some(asset) = bundle.by_path(hashed_name) else { + return respond_text( + request, + StatusCode(404), + "text/plain; charset=utf-8", + "asset not found\n".as_bytes().to_vec(), + CacheKind::NoStore, + ); + }; + respond_asset(request, asset.bytes.to_vec(), asset.mime, is_head) +} + +enum CacheKind { + NoStore, + Immutable, +} + +fn respond_html(request: Request, body: Vec, is_head: bool) -> ViewResult<()> { + respond_with( + request, + StatusCode(200), + "text/html; charset=utf-8", + if is_head { Vec::new() } else { body }, + CacheKind::NoStore, + ) +} + +fn respond_asset( + request: Request, + body: Vec, + content_type: &str, + is_head: bool, +) -> ViewResult<()> { + respond_with( + request, + StatusCode(200), + content_type, + if is_head { Vec::new() } else { body }, + CacheKind::Immutable, + ) +} + +fn respond_json(request: Request, status: StatusCode, value: &serde_json::Value) -> ViewResult<()> { + let body = serde_json::to_vec_pretty(value).unwrap_or_else(|_| b"{}".to_vec()); + respond_with( + request, + status, + "application/json; charset=utf-8", + body, + CacheKind::NoStore, + ) +} + +fn respond_json_error(request: Request, status: StatusCode, err: &ViewError) -> ViewResult<()> { + respond_json(request, status, &err.to_json()) +} + +fn respond_text( + request: Request, + status: StatusCode, + content_type: &str, + body: Vec, + cache: CacheKind, +) -> ViewResult<()> { + respond_with(request, status, content_type, body, cache) +} + +fn respond_with( + request: Request, + status: StatusCode, + content_type: &str, + body: Vec, + cache: CacheKind, +) -> ViewResult<()> { + let length = body.len(); + let mut response = Response::from_data(body).with_status_code(status); + if let Ok(header) = Header::from_bytes(&b"Content-Type"[..], content_type.as_bytes()) { + response.add_header(header); + } + for (name, value) in security_headers() { + if let Ok(header) = Header::from_bytes(name.as_bytes(), value.as_bytes()) { + response.add_header(header); + } + } + let cache_value = match cache { + CacheKind::NoStore => "no-store", + CacheKind::Immutable => "public, max-age=31536000, immutable", + }; + if let Ok(header) = Header::from_bytes(&b"Cache-Control"[..], cache_value.as_bytes()) { + response.add_header(header); + } + let _ = length; + request.respond(response).map_err(|err| ViewError::Io { + detail: format!("write response: {err}"), + }) +} + +fn security_headers() -> Vec<(&'static str, &'static str)> { + vec![ + ( + "Content-Security-Policy", + "default-src 'none'; style-src 'self'; script-src 'self' file:; img-src 'self' data:; font-src 'self'; connect-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; object-src 'none'", + ), + ("X-Content-Type-Options", "nosniff"), + ("Referrer-Policy", "no-referrer"), + ("X-Frame-Options", "DENY"), + ("Cross-Origin-Resource-Policy", "same-origin"), + ("Cross-Origin-Opener-Policy", "same-origin"), + ] +} + +fn split_url(url: &str) -> (&str, &str) { + match url.split_once('?') { + Some((path, query)) => (path, query), + None => (url, ""), + } +} + +fn query_param(query: &str, key: &str) -> Option { + for pair in query.split('&') { + let (name, value) = match pair.split_once('=') { + Some(parts) => parts, + None => (pair, ""), + }; + if name == key { + return Some(value.to_string()); + } + } + None +} + +/// Decode `%XX` exactly once. Rejects malformed escapes, NUL, other control +/// characters and non-UTF-8 results (RFC §11.2.4). +fn percent_decode(raw: &str) -> Option { + let bytes = raw.as_bytes(); + let mut out = Vec::with_capacity(bytes.len()); + let mut index = 0; + while index < bytes.len() { + match bytes[index] { + b'%' => { + if index + 2 >= bytes.len() { + return None; + } + let high = hex_value(*bytes.get(index + 1)?)?; + let low = hex_value(*bytes.get(index + 2)?)?; + out.push(high * 16 + low); + index += 3; + } + b'+' => { + // Query strings here are paths, not form data: keep a literal +. + out.push(b'+'); + index += 1; + } + byte => { + out.push(byte); + index += 1; + } + } + } + if out.contains(&0) || out.iter().any(|byte| *byte < 0x20 || *byte == 0x7f) { + return None; + } + String::from_utf8(out).ok() +} + +fn hex_value(byte: u8) -> Option { + match byte { + b'0'..=b'9' => Some(byte - b'0'), + b'a'..=b'f' => Some(byte - b'a' + 10), + b'A'..=b'F' => Some(byte - b'A' + 10), + _ => None, + } +} + +fn allowed_hosts(port: u16) -> Vec { + vec![ + format!("127.0.0.1:{port}"), + format!("localhost:{port}"), + format!("[::1]:{port}"), + ] +} + +fn host_is_allowed(request: &Request, allowed: &[String]) -> bool { + let mut host: Option<&str> = None; + for header in request.headers() { + if header.field.equiv("Host") { + host = Some(header.value.as_str()); + break; + } + } + match host { + Some(value) => allowed + .iter() + .any(|allowed| allowed.eq_ignore_ascii_case(value)), + None => false, + } +} + +fn escape_html(raw: &str) -> String { + let mut out = String::with_capacity(raw.len()); + for ch in raw.chars() { + match ch { + '&' => out.push_str("&"), + '<' => out.push_str("<"), + '>' => out.push_str(">"), + '"' => out.push_str("""), + '\'' => out.push_str("'"), + _ => out.push(ch), + } + } + out +} + +fn random_token() -> String { + #[cfg(unix)] + { + use std::io::Read as _; + if let Ok(mut file) = std::fs::File::open("/dev/urandom") { + let mut bytes = [0u8; 32]; + if file.read_exact(&mut bytes).is_ok() { + return hex_encode(&bytes); + } + } + } + // Fallback: still unique per process/session, never a constant. + let material = format!( + "{}-{}-{:?}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0), + std::thread::current().id() + ); + sha256_hex(material.as_bytes()) +} + +fn hex_encode(bytes: &[u8]) -> String { + let mut out = String::with_capacity(bytes.len() * 2); + for byte in bytes { + use std::fmt::Write as _; + let _ = write!(out, "{byte:02x}"); + } + out +} + +fn open_browser(url: &str) { + let program = if cfg!(target_os = "macos") { + "open" + } else if cfg!(target_os = "windows") { + "cmd" + } else { + "xdg-open" + }; + let mut command = std::process::Command::new(program); + if cfg!(target_os = "windows") { + command.args(["/C", "start", ""]); + } + command.arg(url); + command + .stdin(std::process::Stdio::null()) + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()); + if command.spawn().is_err() { + eprintln!("view: could not open a browser; open {url} manually"); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn percent_decode_is_single_pass_and_strict() { + assert_eq!(percent_decode("a%20b").as_deref(), Some("a b")); + assert_eq!(percent_decode("100%25").as_deref(), Some("100%")); + assert_eq!(percent_decode("a+b").as_deref(), Some("a+b")); + assert!(percent_decode("%2e%2e%2fsecret").is_some()); + assert!(percent_decode("%zz").is_none()); + assert!(percent_decode("%2").is_none()); + assert!(percent_decode("a%00b").is_none()); + assert!(percent_decode("%0a").is_none()); + assert!(percent_decode("%ff").is_none()); + } + + #[test] + fn query_params_are_parsed_without_form_plus_rules() { + assert_eq!(query_param("path=a%2Fb", "path").as_deref(), Some("a%2Fb")); + assert_eq!(query_param("x=1&path=y", "path").as_deref(), Some("y")); + assert_eq!(query_param("", "path"), None); + } + + #[test] + fn allowed_hosts_include_loopback_and_port() { + let hosts = allowed_hosts(7429); + assert!(hosts.contains(&"127.0.0.1:7429".to_string())); + assert!(hosts.contains(&"localhost:7429".to_string())); + assert!(!hosts.contains(&"127.0.0.1:7428".to_string())); + } + + #[test] + fn random_token_is_64_hex_chars_and_unique() { + let a = random_token(); + let b = random_token(); + assert_eq!(a.len(), 64); + assert_ne!(a, b); + } +} diff --git a/src/source_map.rs b/src/source_map.rs index efb19b5..34c14ba 100644 --- a/src/source_map.rs +++ b/src/source_map.rs @@ -127,6 +127,34 @@ impl SourceIndex { is_char_boundary(bytes, start) && is_char_boundary(bytes, end) } + /// Byte offset of the start of a 1-based line. + pub fn line_start(&self, line: usize) -> Option { + if line == 0 { + return None; + } + self.line_starts.get(line - 1).copied() + } + + /// Number of lines in the source. + pub fn line_count(&self) -> usize { + self.line_starts.len() + } + + /// Text of a 1-based line without its trailing newline. + pub fn line_text<'a>(&self, source: &'a str, line: usize) -> Option<&'a str> { + let start = self.line_start(line)?; + let end = self.line_starts.get(line).copied().unwrap_or(self.len); + let bytes = source.as_bytes(); + let mut end = end.min(bytes.len()); + if end > start && bytes.get(end - 1) == Some(&b'\n') { + end -= 1; + if end > start && bytes.get(end - 1) == Some(&b'\r') { + end -= 1; + } + } + source.get(start..end) + } + /// 1-based line and 1-based byte column for a byte offset, clamped to the /// file length. Column counts bytes, matching Core's presentation fields. pub fn line_col(&self, byte: usize) -> (usize, usize) { diff --git a/tests/asset_integrity.rs b/tests/asset_integrity.rs new file mode 100644 index 0000000..6ecdc4b --- /dev/null +++ b/tests/asset_integrity.rs @@ -0,0 +1,87 @@ +//! Asset provenance and integrity: the three reused legacy visual assets are +//! pinned by SHA-256 in `assets/licenses/ASSETS.md` and embedded by +//! `src/assets.rs` (ADR-0002). + +use sha2::{Digest, Sha256}; + +fn sha256_hex(bytes: &[u8]) -> String { + let mut hasher = Sha256::new(); + hasher.update(bytes); + let mut out = String::with_capacity(64); + for byte in hasher.finalize() { + use std::fmt::Write as _; + let _ = write!(out, "{byte:02x}"); + } + out +} + +#[test] +fn reused_assets_match_their_recorded_hashes() { + let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + for (file, expected) in [ + ( + "assets/logo.svg", + "52b2338468c62a7da86178ecec86cbb7ea44a996cd1bc4275ebb56f16f2244fe", + ), + ( + "assets/blossom.webp", + "901fd6b37ebb20d1dfc3bf4d265a063308605350fd317e41914fa35b06f46e00", + ), + ( + "assets/feather.webp", + "fbd787174be1e8027ae4661b99f7f2cc01b824d8fc875a1d2d39cbd0c052e5de", + ), + ] { + let bytes = + std::fs::read(root.join(file)).unwrap_or_else(|err| panic!("read {file}: {err}")); + assert_eq!(sha256_hex(&bytes), expected, "{file} digest changed"); + } + let licenses = std::fs::read_to_string(root.join("assets/licenses/ASSETS.md")).unwrap(); + for expected in [ + "52b2338468c62a7da86178ecec86cbb7ea44a996cd1bc4275ebb56f16f2244fe", + "901fd6b37ebb20d1dfc3bf4d265a063308605350fd317e41914fa35b06f46e00", + "fbd787174be1e8027ae4661b99f7f2cc01b824d8fc875a1d2d39cbd0c052e5de", + "Apache-2.0", + ] { + assert!(licenses.contains(expected), "ASSETS.md misses {expected}"); + } +} + +#[test] +fn embedded_asset_bundle_matches_disk_and_has_one_theme() { + let bundle = marqdo_view::assets::AssetBundle::get(); + let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let css = std::fs::read(root.join("assets/reader.css")).unwrap(); + assert_eq!(sha256_hex(&css), bundle.css().sha256); + let js = std::fs::read(root.join("assets/reader.js")).unwrap(); + assert_eq!(sha256_hex(&js), bundle.js().sha256); + assert_eq!( + bundle + .all() + .iter() + .filter(|asset| asset.extension == "css" || asset.extension == "js") + .count(), + 2 + ); +} + +#[test] +fn theme_has_one_token_layer_and_no_legacy_skin() { + let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let css = std::fs::read_to_string(root.join("assets/reader.css")).unwrap(); + assert_eq!(css.matches("@layer tokens").count(), 1); + assert!(css.contains( + "@layer reset, tokens, layout, typography, semantics, overlays, interactions, responsive;" + )); + for banned in ["notebook-page", "reader-page", "legacy.css", "new.css"] { + assert!(!css.contains(banned), "legacy skin marker {banned} in CSS"); + } + assert!( + !css.contains("!important"), + "the theme must not rely on !important overrides" + ); + // No remote font/CDN requests. + for banned in ["@font-face", "fonts.googleapis", "https://"] { + assert!(!css.contains(banned), "remote resource marker {banned}"); + } +} diff --git a/tests/cli_surface.rs b/tests/cli_surface.rs index 8ae660c..3ed81e4 100644 --- a/tests/cli_surface.rs +++ b/tests/cli_surface.rs @@ -57,17 +57,30 @@ fn non_loopback_bind_is_refused_by_default() { } #[test] -fn browse_without_core_reports_core_missing() { - // Browse is not implemented yet, but the reader must still fail with a - // stable View code and exit class rather than pretending to work. +fn browse_on_missing_path_fails_without_starting_a_server() { let cwd = std::env::current_dir().unwrap(); - let output = run_view(&[], &cwd, &clean_env()); - let stderr = String::from_utf8_lossy(&output.stderr); - assert_eq!(output.status.code(), Some(2), "stderr: {stderr}"); - assert!( - stderr.contains("view.unsupported") || stderr.contains("view.core_missing"), - "unexpected diagnostic: {stderr}" + let output = run_view( + &["definitely-missing.mq.md", "--no-open"], + &cwd, + &clean_env(), ); + assert_eq!(output.status.code(), Some(1)); + assert!(String::from_utf8_lossy(&output.stderr).contains("view.io")); +} + +#[test] +fn degradation_without_core_keeps_prose_readable() { + // The reader must degrade to prose-only with an explicit status, never + // invent semantic annotations or a fake run state. + let project = common::TempProject::new("cli-degrade-no-core"); + project.marqdo_project("# @knowledge 标题\n\n正文 **加粗**。\n"); + let context = marqdo_view::app::AppContext::open(&project.dir, None).unwrap(); + let relative = context.project().entry().relative.clone(); + let model = context.load(&relative).unwrap(); + assert_eq!(model.source_status.data_value(), "core-unavailable"); + assert!(model.semantic.is_none()); + assert!(model.document.plain_text().contains("正文")); + assert!(model.status_note.is_some()); } #[test] diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 997e925..1c1d73d 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -13,7 +13,11 @@ pub fn view_bin() -> &'static str { } pub fn temp_root(name: &str) -> PathBuf { - let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join(name); + use std::sync::atomic::{AtomicU64, Ordering}; + static NEXT: AtomicU64 = AtomicU64::new(0); + let seq = NEXT.fetch_add(1, Ordering::Relaxed); + let dir = PathBuf::from(env!("CARGO_TARGET_TMPDIR")) + .join(format!("{name}-{}-{seq}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).expect("create test temp dir"); dir @@ -79,6 +83,7 @@ case "$1" in ;; check) if [ -f "$dir/check_stderr" ]; then cat "$dir/check_stderr" >&2; fi + if [ -f "$dir/check_json" ]; then cat "$dir/check_json"; fi emit="" prev="" for a in "$@"; do @@ -126,6 +131,10 @@ esac std::fs::write(self.dir.join("check_stderr"), stderr).expect("write stderr"); } + pub fn set_check_json(&self, json: &str) { + std::fs::write(self.dir.join("check_json"), json).expect("write check json"); + } + pub fn set_analysis(&self, analysis: &str) { std::fs::write(self.dir.join("analysis.json"), analysis).expect("write analysis"); } diff --git a/tests/core_contract.rs b/tests/core_contract.rs index 4026b28..23da80e 100644 --- a/tests/core_contract.rs +++ b/tests/core_contract.rs @@ -7,7 +7,7 @@ mod common; use common::{minimal_analysis, sha256_hex, FakeCore, TempProject}; -use marqdo_view::core_client::{CheckOptions, CoreClient, RunOptions}; +use marqdo_view::core_client::{CheckOptions, CheckResponse, CoreClient, RunOptions}; use marqdo_view::project::Project; fn fixture(name: &str) -> (TempProject, FakeCore) { @@ -27,9 +27,11 @@ fn check_returns_exact_analysis_bytes_and_digest() { let client = CoreClient::with_bin(&core.script).unwrap(); let project = Project::open(&project.path("index.mq.md")).unwrap(); let entry = project.entry().relative.clone(); - let output = client - .check(&project, &entry, &CheckOptions::default()) - .unwrap(); + let output = expect_check_ok( + client + .check(&project, &entry, &CheckOptions::default()) + .unwrap(), + ); assert_eq!(output.analysis_bytes, analysis.as_bytes()); assert_eq!(output.analysis_sha256, sha256_hex(analysis.as_bytes())); @@ -52,16 +54,18 @@ fn check_refs_is_forwarded_as_a_stricter_flag() { let client = CoreClient::with_bin(&core.script).unwrap(); let project = Project::open(&project.path("index.mq.md")).unwrap(); let entry = project.entry().relative.clone(); - client - .check( - &project, - &entry, - &CheckOptions { - refs: true, - timeout: None, - }, - ) - .unwrap(); + expect_check_ok( + client + .check( + &project, + &entry, + &CheckOptions { + refs: true, + timeout: None, + }, + ) + .unwrap(), + ); assert!(core.last_args().contains(&"--refs".to_string())); } @@ -72,13 +76,12 @@ fn check_failure_preserves_core_stderr_and_code() { let client = CoreClient::with_bin(&core.script).unwrap(); let project = Project::open(&project.path("index.mq.md")).unwrap(); let entry = project.entry().relative.clone(); - let err = client + let response = client .check(&project, &entry, &CheckOptions::default()) - .unwrap_err(); - assert_eq!(err.code(), "view.analysis_failed"); - assert_eq!(err.exit_code(), 1); - let text = err.to_string(); - assert!(text.contains("sem.unclosed_control"), "{text}"); + .unwrap(); + assert!(!response.success); + assert_eq!(response.exit_code, 1); + assert!(response.stderr.contains("sem.unclosed_control")); } #[test] @@ -193,6 +196,33 @@ fn missing_emit_after_success_is_an_analysis_failure() { assert_eq!(err.code(), "view.analysis_failed"); } +fn expect_check_ok(response: CheckResponse) -> marqdo_view::core_client::CheckOutput { + assert!(response.success, "check failed: {:?}", response.diagnostics); + response.analysis.expect("analysis on success") +} + +#[test] +fn failed_check_normalizes_diagnostics_without_absolute_paths() { + let (project, core) = fixture("check_diagnostics"); + core.set_check(1, ""); + core.set_check_json( + r#"{"command":"check","success":false,"errors":1,"diagnostics":[{"code":"sem.unclosed_control","column":1,"file":"/home/secret/project/index.mq.md","hints":[],"line":5,"message":"`if` is not closed by `end`","module":"root:fixture@0.1.0::index.mq.md","severity":"error"}]}"#, + ); + let client = CoreClient::with_bin(&core.script).unwrap(); + let project = Project::open(&project.path("index.mq.md")).unwrap(); + let entry = project.entry().relative.clone(); + let response = client + .check(&project, &entry, &CheckOptions::default()) + .unwrap(); + assert!(!response.success); + assert_eq!(response.diagnostics.len(), 1); + assert_eq!(response.diagnostics[0].code, "sem.unclosed_control"); + assert_eq!(response.diagnostics[0].line, Some(5)); + // The raw absolute `file` field is not part of the normalized type at all. + let rendered = serde_json::to_string(&response.diagnostics).unwrap(); + assert!(!rendered.contains("/home/secret"), "{rendered}"); +} + #[test] fn cli_verify_end_to_end_against_fake_core() { let (project, core) = fixture("verify_cli"); diff --git a/tests/golden/README.md b/tests/golden/README.md new file mode 100644 index 0000000..740f4b2 --- /dev/null +++ b/tests/golden/README.md @@ -0,0 +1,29 @@ +# Protocol goldens + +These Analysis v2 files were emitted by the **frozen** `marqdo` CLI release +binary, not hand-written: + +| Binary | SHA-256 | +|---|---| +| `marqdo 3.0.0-beta.1` | `062cb56e226bee55c21d238e195920caa985e62bb3877ba7b07abcc04dc0fe3f` | +| CLI source SHA | `2c7c4f31e7a388d3fcfa717a77067e696ed13854` | + +Command shape used for every golden: + +```bash +"$MARQDO_BIN" check --emit tests/golden/analysis-v2/.json +``` + +| Golden | Input | +|---|---| +| `mixed-modes.json` | `examples/mixed-modes/index.mq.md` | +| `control-flow.json` | `examples/control-flow/index.mq.md` | +| `tables-math.json` | `examples/tables-math/index.mq.md` | +| `welcome.json` | `examples/welcome/00-welcome.mq.md` | + +`tools/gen-golden.sh` regenerates them from a frozen binary. If an example's +bytes change, its `source_digest` changes too and the tests will fail until the +golden is regenerated — that is intentional evidence, not a test bug. + +`examples/diagnostics/index.mq.md` is deliberately invalid and has **no** +golden; its failure path is covered with `check --json` output. diff --git a/tests/golden/analysis-v2/control-flow.json b/tests/golden/analysis-v2/control-flow.json new file mode 100644 index 0000000..082f39e --- /dev/null +++ b/tests/golden/analysis-v2/control-flow.json @@ -0,0 +1,18757 @@ +{ + "diagnostics": [], + "modules": [ + { + "calls": [ + { + "callee": { + "kind": "ident", + "name": "print" + }, + "function": "root:control-flow@0.1.0::index.mq.md::演示.main", + "span": { + "end": 223, + "start": 215 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写值" + }, + { + "callee": { + "kind": "ident", + "name": "print" + }, + "function": "root:control-flow@0.1.0::index.mq.md::演示.main", + "span": { + "end": 247, + "start": 239 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写值" + } + ], + "functions": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 180, + "start": 173 + }, + "target": "x", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "expression", + "span": { + "end": 225, + "start": 213 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 222, + "start": 221 + }, + "value": { + "kind": "variable", + "name": "x", + "span": { + "end": 222, + "start": 221 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "print", + "span": { + "end": 220, + "start": 215 + } + }, + "kind": "call", + "span": { + "end": 223, + "start": 215 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "x", + "span": { + "end": 205, + "start": 204 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 209, + "start": 204 + } + }, + "condition_span": { + "end": 211, + "start": 199 + }, + "span": { + "end": 211, + "start": 199 + } + }, + { + "body": [ + { + "kind": "expression", + "span": { + "end": 249, + "start": 237 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 246, + "start": 245 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "callee": { + "kind": "variable", + "name": "print", + "span": { + "end": 244, + "start": 239 + } + }, + "kind": "call", + "span": { + "end": 247, + "start": 239 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 211, + "start": 199 + }, + "span": { + "end": 211, + "start": 199 + } + } + ], + "kind": "branch", + "span": { + "end": 211, + "start": 199 + } + }, + { + "kind": "assign", + "span": { + "end": 273, + "start": 260 + }, + "target": "x", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "x", + "span": { + "end": 267, + "start": 266 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 271, + "start": 266 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "x", + "span": { + "end": 191, + "start": 190 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + }, + "span": { + "end": 195, + "start": 190 + } + }, + "condition_span": { + "end": 197, + "start": 182 + }, + "kind": "loop", + "span": { + "end": 197, + "start": 182 + } + }, + { + "kind": "return", + "span": { + "end": 294, + "start": 284 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 171, + "start": 158 + }, + "id": "root:control-flow@0.1.0::index.mq.md::演示.main", + "local_name": "main", + "namespace": "演示", + "signature": { + "kind": "inferred", + "params": [] + }, + "span": { + "end": 294, + "start": 158 + }, + "unit_id": "root:control-flow@0.1.0::index.mq.md#演示/main" + } + ], + "id": "root:control-flow@0.1.0::index.mq.md", + "imports": [], + "package_instance_id": "root:control-flow@0.1.0", + "references": [], + "relative_path": "index.mq.md", + "resources": [], + "source_digest": "42a6c5af2e0e6df1988978930fd4e5d56ee040fcf7ebfc9fe4088c1a2dc4f454", + "units": [ + { + "function": null, + "id": "root:control-flow@0.1.0::index.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 294, + "start": 0 + } + }, + { + "function": null, + "id": "root:control-flow@0.1.0::index.mq.md#控制流演示", + "kind": "namespace", + "level": 1, + "name": "控制流演示", + "span": { + "end": 28, + "start": 0 + } + }, + { + "function": null, + "id": "root:control-flow@0.1.0::index.mq.md#演示", + "kind": "namespace", + "level": 1, + "name": "演示", + "span": { + "end": 156, + "start": 142 + } + }, + { + "function": "root:control-flow@0.1.0::index.mq.md::演示.main", + "id": "root:control-flow@0.1.0::index.mq.md#演示/main", + "kind": "function", + "level": 2, + "name": "main", + "span": { + "end": 171, + "start": 158 + } + } + ] + }, + { + "calls": [ + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "codepoints", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.字节长度", + "span": { + "end": 82, + "start": 59 + }, + "state": "builtin", + "target": "text.codepoints" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.字节长度", + "span": { + "end": 148, + "start": 137 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "kind": "ident", + "name": "类型" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 699, + "start": 688 + }, + "state": "builtin", + "target": "类型" + }, + { + "callee": { + "kind": "ident", + "name": "列表显示" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 889, + "start": 872 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.列表显示" + }, + { + "callee": { + "kind": "ident", + "name": "映射显示" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 946, + "start": 929 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.映射显示" + }, + { + "callee": { + "kind": "ident", + "name": "表格显示" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 1005, + "start": 988 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示" + }, + { + "callee": { + "kind": "ident", + "name": "转义文本" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 1085, + "start": 1062 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本" + }, + { + "callee": { + "kind": "ident", + "name": "转义文本" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 1168, + "start": 1142 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本" + }, + { + "callee": { + "kind": "ident", + "name": "文本" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 1210, + "start": 1178 + }, + "state": "builtin", + "target": "文本" + }, + { + "callee": { + "kind": "ident", + "name": "字节长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 1209, + "start": 1185 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.字节长度" + }, + { + "callee": { + "kind": "ident", + "name": "文本" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "span": { + "end": 1570, + "start": 1559 + }, + "state": "builtin", + "target": "文本" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.列表显示", + "span": { + "end": 1750, + "start": 1736 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "kind": "ident", + "name": "值显示" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.列表显示", + "span": { + "end": 1889, + "start": 1864 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.值显示" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "map" + }, + "field": "keys", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.映射显示", + "span": { + "end": 2006, + "start": 1990 + }, + "state": "builtin", + "target": "map.keys" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.映射显示", + "span": { + "end": 2071, + "start": 2060 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "kind": "ident", + "name": "值显示" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.映射显示", + "span": { + "end": 2270, + "start": 2233 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.值显示" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "map" + }, + "field": "get", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.映射显示", + "span": { + "end": 2269, + "start": 2243 + }, + "state": "builtin", + "target": "map.get" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "table" + }, + "field": "columns", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2392, + "start": 2371 + }, + "state": "builtin", + "target": "table.columns" + }, + { + "callee": { + "kind": "ident", + "name": "连接文本" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2442, + "start": 2418 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.连接文本" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2499, + "start": 2485 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "table" + }, + "field": "row", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2626, + "start": 2601 + }, + "state": "builtin", + "target": "table.row" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2693, + "start": 2682 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "list" + }, + "field": "append", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2753, + "start": 2710 + }, + "state": "builtin", + "target": "list.append" + }, + { + "callee": { + "kind": "ident", + "name": "显示" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2752, + "start": 2733 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示" + }, + { + "callee": { + "kind": "ident", + "name": "连接文本" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "span": { + "end": 2838, + "start": 2808 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.连接文本" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.连接文本", + "span": { + "end": 3002, + "start": 2988 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "kind": "ident", + "name": "类型" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.值显示", + "span": { + "end": 3334, + "start": 3323 + }, + "state": "builtin", + "target": "类型" + }, + { + "callee": { + "kind": "ident", + "name": "转义文本" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.值显示", + "span": { + "end": 3386, + "start": 3369 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本" + }, + { + "callee": { + "kind": "ident", + "name": "显示" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.值显示", + "span": { + "end": 3426, + "start": 3415 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "codepoints", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本", + "span": { + "end": 3507, + "start": 3484 + }, + "state": "builtin", + "target": "text.codepoints" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本", + "span": { + "end": 3575, + "start": 3564 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "from_codepoint", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本", + "span": { + "end": 3948, + "start": 3921 + }, + "state": "builtin", + "target": "text.from_codepoint" + } + ], + "functions": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 84, + "start": 51 + }, + "target": "点", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 81, + "start": 75 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 81, + "start": 75 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 63, + "start": 59 + } + }, + "field": "codepoints", + "kind": "member", + "span": { + "end": 74, + "start": 59 + } + }, + "kind": "call", + "span": { + "end": 82, + "start": 59 + } + } + }, + { + "kind": "assign", + "span": { + "end": 103, + "start": 86 + }, + "target": "总字节", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "kind": "assign", + "span": { + "end": 119, + "start": 105 + }, + "target": "下标", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 175, + "start": 151 + }, + "target": "码点", + "value": { + "base": { + "kind": "variable", + "name": "点", + "span": { + "end": 165, + "start": 162 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 172, + "start": 166 + } + }, + "kind": "index", + "span": { + "end": 173, + "start": 162 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 225, + "start": 196 + }, + "target": "总字节", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "总字节", + "span": { + "end": 219, + "start": 210 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 223, + "start": 210 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 187, + "start": 181 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 193, + "start": 181 + } + }, + "condition_span": { + "end": 194, + "start": 177 + }, + "span": { + "end": 194, + "start": 177 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 283, + "start": 254 + }, + "target": "总字节", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "总字节", + "span": { + "end": 277, + "start": 268 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 281, + "start": 268 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 244, + "start": 238 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2048" + }, + "span": { + "end": 251, + "start": 238 + } + }, + "condition_span": { + "end": 252, + "start": 234 + }, + "span": { + "end": 252, + "start": 234 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 342, + "start": 313 + }, + "target": "总字节", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "总字节", + "span": { + "end": 336, + "start": 327 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + }, + "span": { + "end": 340, + "start": 327 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 302, + "start": 296 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "65536" + }, + "span": { + "end": 310, + "start": 296 + } + }, + "condition_span": { + "end": 311, + "start": 292 + }, + "span": { + "end": 311, + "start": 292 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 391, + "start": 362 + }, + "target": "总字节", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "总字节", + "span": { + "end": 385, + "start": 376 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "4" + }, + "span": { + "end": 389, + "start": 376 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 360, + "start": 351 + }, + "span": { + "end": 360, + "start": 351 + } + } + ], + "kind": "branch", + "span": { + "end": 360, + "start": 351 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 311, + "start": 292 + }, + "span": { + "end": 311, + "start": 292 + } + } + ], + "kind": "branch", + "span": { + "end": 311, + "start": 292 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 252, + "start": 234 + }, + "span": { + "end": 252, + "start": 234 + } + } + ], + "kind": "branch", + "span": { + "end": 252, + "start": 234 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 194, + "start": 177 + }, + "span": { + "end": 194, + "start": 177 + } + } + ], + "kind": "branch", + "span": { + "end": 194, + "start": 177 + } + }, + { + "kind": "assign", + "span": { + "end": 440, + "start": 417 + }, + "target": "下标", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 434, + "start": 428 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 438, + "start": 428 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 134, + "start": 128 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 147, + "start": 144 + }, + "value": { + "kind": "variable", + "name": "点", + "span": { + "end": 147, + "start": 144 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 143, + "start": 137 + } + }, + "kind": "call", + "span": { + "end": 148, + "start": 137 + } + }, + "span": { + "end": 148, + "start": 128 + } + }, + "condition_span": { + "end": 149, + "start": 121 + }, + "kind": "loop", + "span": { + "end": 149, + "start": 121 + } + }, + { + "kind": "return", + "span": { + "end": 466, + "start": 448 + }, + "value": { + "kind": "variable", + "name": "总字节", + "span": { + "end": 465, + "start": 456 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 31, + "start": 16 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.字节长度", + "local_name": "字节长度", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 46, + "start": 40 + }, + "type": null + } + ] + }, + "span": { + "end": 466, + "start": 16 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/字节长度" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 701, + "start": 677 + }, + "target": "类别", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 698, + "start": 695 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 698, + "start": 695 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "类型", + "span": { + "end": 694, + "start": 688 + } + }, + "kind": "call", + "span": { + "end": 699, + "start": 688 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 741, + "start": 726 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Unit" + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 713, + "start": 707 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Unit" + }, + "span": { + "end": 723, + "start": 707 + } + }, + "condition_span": { + "end": 724, + "start": 703 + }, + "span": { + "end": 724, + "start": 703 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 788, + "start": 773 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "None" + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 760, + "start": 754 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "None" + }, + "span": { + "end": 770, + "start": 754 + } + }, + "condition_span": { + "end": 771, + "start": 750 + }, + "span": { + "end": 771, + "start": 750 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 832, + "start": 820 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 831, + "start": 828 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 807, + "start": 801 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Text" + }, + "span": { + "end": 817, + "start": 801 + } + }, + "condition_span": { + "end": 818, + "start": 797 + }, + "span": { + "end": 818, + "start": 797 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 890, + "start": 864 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 888, + "start": 885 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 888, + "start": 885 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "列表显示", + "span": { + "end": 884, + "start": 872 + } + }, + "kind": "call", + "span": { + "end": 889, + "start": 872 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 851, + "start": 845 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "List" + }, + "span": { + "end": 861, + "start": 845 + } + }, + "condition_span": { + "end": 862, + "start": 841 + }, + "span": { + "end": 862, + "start": 841 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 947, + "start": 921 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 945, + "start": 942 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 945, + "start": 942 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "映射显示", + "span": { + "end": 941, + "start": 929 + } + }, + "kind": "call", + "span": { + "end": 946, + "start": 929 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 909, + "start": 903 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Map" + }, + "span": { + "end": 918, + "start": 903 + } + }, + "condition_span": { + "end": 919, + "start": 899 + }, + "span": { + "end": 919, + "start": 899 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1006, + "start": 980 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1004, + "start": 1001 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 1004, + "start": 1001 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "表格显示", + "span": { + "end": 1000, + "start": 988 + } + }, + "kind": "call", + "span": { + "end": 1005, + "start": 988 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 966, + "start": 960 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Table" + }, + "span": { + "end": 977, + "start": 960 + } + }, + "condition_span": { + "end": 978, + "start": 956 + }, + "span": { + "end": 978, + "start": 956 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1092, + "start": 1041 + }, + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Formula(" + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 1084, + "start": 1075 + }, + "value": { + "base": { + "kind": "variable", + "name": "值", + "span": { + "end": 1078, + "start": 1075 + } + }, + "field": "latex", + "kind": "member", + "span": { + "end": 1084, + "start": 1075 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "转义文本", + "span": { + "end": 1074, + "start": 1062 + } + }, + "kind": "call", + "span": { + "end": 1085, + "start": 1062 + } + }, + "span": { + "end": 1085, + "start": 1049 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": ")" + }, + "span": { + "end": 1091, + "start": 1049 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 1025, + "start": 1019 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Formula" + }, + "span": { + "end": 1038, + "start": 1019 + } + }, + "condition_span": { + "end": 1039, + "start": 1015 + }, + "span": { + "end": 1039, + "start": 1015 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1223, + "start": 1124 + }, + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Code(" + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 1167, + "start": 1155 + }, + "value": { + "base": { + "kind": "variable", + "name": "值", + "span": { + "end": 1158, + "start": 1155 + } + }, + "field": "language", + "kind": "member", + "span": { + "end": 1167, + "start": 1155 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "转义文本", + "span": { + "end": 1154, + "start": 1142 + } + }, + "kind": "call", + "span": { + "end": 1168, + "start": 1142 + } + }, + "span": { + "end": 1168, + "start": 1132 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": ", " + }, + "span": { + "end": 1175, + "start": 1132 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 1209, + "start": 1185 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1208, + "start": 1198 + }, + "value": { + "base": { + "kind": "variable", + "name": "值", + "span": { + "end": 1201, + "start": 1198 + } + }, + "field": "source", + "kind": "member", + "span": { + "end": 1208, + "start": 1198 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "字节长度", + "span": { + "end": 1197, + "start": 1185 + } + }, + "kind": "call", + "span": { + "end": 1209, + "start": 1185 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "文本", + "span": { + "end": 1184, + "start": 1178 + } + }, + "kind": "call", + "span": { + "end": 1210, + "start": 1178 + } + }, + "span": { + "end": 1210, + "start": 1132 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": " bytes)" + }, + "span": { + "end": 1222, + "start": 1132 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 1111, + "start": 1105 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Code" + }, + "span": { + "end": 1121, + "start": 1105 + } + }, + "condition_span": { + "end": 1122, + "start": 1101 + }, + "span": { + "end": 1122, + "start": 1101 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1322, + "start": 1262 + }, + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "FunctionRef(" + }, + "op": "add", + "right": { + "base": { + "kind": "variable", + "name": "值", + "span": { + "end": 1290, + "start": 1287 + } + }, + "field": "module", + "kind": "member", + "span": { + "end": 1297, + "start": 1287 + } + }, + "span": { + "end": 1297, + "start": 1270 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "::" + }, + "span": { + "end": 1304, + "start": 1270 + } + }, + "op": "add", + "right": { + "base": { + "kind": "variable", + "name": "值", + "span": { + "end": 1310, + "start": 1307 + } + }, + "field": "name", + "kind": "member", + "span": { + "end": 1315, + "start": 1307 + } + }, + "span": { + "end": 1315, + "start": 1270 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": ")" + }, + "span": { + "end": 1321, + "start": 1270 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 1242, + "start": 1236 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "FunctionRef" + }, + "span": { + "end": 1259, + "start": 1236 + } + }, + "condition_span": { + "end": 1260, + "start": 1232 + }, + "span": { + "end": 1260, + "start": 1232 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1425, + "start": 1362 + }, + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "PluginHandle(" + }, + "op": "add", + "right": { + "base": { + "kind": "variable", + "name": "值", + "span": { + "end": 1391, + "start": 1388 + } + }, + "field": "plugin", + "kind": "member", + "span": { + "end": 1398, + "start": 1388 + } + }, + "span": { + "end": 1398, + "start": 1370 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "::" + }, + "span": { + "end": 1405, + "start": 1370 + } + }, + "op": "add", + "right": { + "base": { + "kind": "variable", + "name": "值", + "span": { + "end": 1411, + "start": 1408 + } + }, + "field": "export", + "kind": "member", + "span": { + "end": 1418, + "start": 1408 + } + }, + "span": { + "end": 1418, + "start": 1370 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": ")" + }, + "span": { + "end": 1424, + "start": 1370 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 1341, + "start": 1335 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "PluginHandle" + }, + "span": { + "end": 1359, + "start": 1335 + } + }, + "condition_span": { + "end": 1360, + "start": 1331 + }, + "span": { + "end": 1360, + "start": 1331 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1476, + "start": 1459 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Memory" + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 1444, + "start": 1438 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Memory" + }, + "span": { + "end": 1456, + "start": 1438 + } + }, + "condition_span": { + "end": 1457, + "start": 1434 + }, + "span": { + "end": 1457, + "start": 1434 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1531, + "start": 1512 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Resource" + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 1495, + "start": 1489 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Resource" + }, + "span": { + "end": 1509, + "start": 1489 + } + }, + "condition_span": { + "end": 1510, + "start": 1485 + }, + "span": { + "end": 1510, + "start": 1485 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1571, + "start": 1551 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1569, + "start": 1566 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 1569, + "start": 1566 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "文本", + "span": { + "end": 1565, + "start": 1559 + } + }, + "kind": "call", + "span": { + "end": 1570, + "start": 1559 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1549, + "start": 1540 + }, + "span": { + "end": 1549, + "start": 1540 + } + } + ], + "kind": "branch", + "span": { + "end": 1549, + "start": 1540 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1510, + "start": 1485 + }, + "span": { + "end": 1510, + "start": 1485 + } + } + ], + "kind": "branch", + "span": { + "end": 1510, + "start": 1485 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1457, + "start": 1434 + }, + "span": { + "end": 1457, + "start": 1434 + } + } + ], + "kind": "branch", + "span": { + "end": 1457, + "start": 1434 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1360, + "start": 1331 + }, + "span": { + "end": 1360, + "start": 1331 + } + } + ], + "kind": "branch", + "span": { + "end": 1360, + "start": 1331 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1260, + "start": 1232 + }, + "span": { + "end": 1260, + "start": 1232 + } + } + ], + "kind": "branch", + "span": { + "end": 1260, + "start": 1232 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1122, + "start": 1101 + }, + "span": { + "end": 1122, + "start": 1101 + } + } + ], + "kind": "branch", + "span": { + "end": 1122, + "start": 1101 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1039, + "start": 1015 + }, + "span": { + "end": 1039, + "start": 1015 + } + } + ], + "kind": "branch", + "span": { + "end": 1039, + "start": 1015 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 978, + "start": 956 + }, + "span": { + "end": 978, + "start": 956 + } + } + ], + "kind": "branch", + "span": { + "end": 978, + "start": 956 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 919, + "start": 899 + }, + "span": { + "end": 919, + "start": 899 + } + } + ], + "kind": "branch", + "span": { + "end": 919, + "start": 899 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 862, + "start": 841 + }, + "span": { + "end": 862, + "start": 841 + } + } + ], + "kind": "branch", + "span": { + "end": 862, + "start": 841 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 818, + "start": 797 + }, + "span": { + "end": 818, + "start": 797 + } + } + ], + "kind": "branch", + "span": { + "end": 818, + "start": 797 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 771, + "start": 750 + }, + "span": { + "end": 771, + "start": 750 + } + } + ], + "kind": "branch", + "span": { + "end": 771, + "start": 750 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 724, + "start": 703 + }, + "span": { + "end": 724, + "start": 703 + } + } + ], + "kind": "branch", + "span": { + "end": 724, + "start": 703 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 477, + "start": 468 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "local_name": "显示", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "值", + "required": true, + "span": { + "end": 489, + "start": 486 + }, + "type": null + } + ] + }, + "span": { + "end": 1650, + "start": 468 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/显示" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1702, + "start": 1686 + }, + "target": "结果", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "[" + } + }, + { + "kind": "assign", + "span": { + "end": 1718, + "start": 1704 + }, + "target": "下标", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1796, + "start": 1770 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 1787, + "start": 1781 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": ", " + }, + "span": { + "end": 1794, + "start": 1781 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1763, + "start": 1757 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 1767, + "start": 1757 + } + }, + "condition_span": { + "end": 1768, + "start": 1753 + }, + "span": { + "end": 1768, + "start": 1753 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1830, + "start": 1816 + }, + "target": "忽略", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1814, + "start": 1805 + }, + "span": { + "end": 1814, + "start": 1805 + } + } + ], + "kind": "branch", + "span": { + "end": 1814, + "start": 1805 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1768, + "start": 1753 + }, + "span": { + "end": 1768, + "start": 1753 + } + } + ], + "kind": "branch", + "span": { + "end": 1768, + "start": 1753 + } + }, + { + "kind": "assign", + "span": { + "end": 1891, + "start": 1844 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 1861, + "start": 1855 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 1888, + "start": 1874 + }, + "value": { + "base": { + "kind": "variable", + "name": "列表", + "span": { + "end": 1880, + "start": 1874 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1887, + "start": 1881 + } + }, + "kind": "index", + "span": { + "end": 1888, + "start": 1874 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "值显示", + "span": { + "end": 1873, + "start": 1864 + } + }, + "kind": "call", + "span": { + "end": 1889, + "start": 1864 + } + }, + "span": { + "end": 1889, + "start": 1855 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1916, + "start": 1893 + }, + "target": "下标", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1910, + "start": 1904 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1914, + "start": 1904 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1733, + "start": 1727 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 1749, + "start": 1743 + }, + "value": { + "kind": "variable", + "name": "列表", + "span": { + "end": 1749, + "start": 1743 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1742, + "start": 1736 + } + }, + "kind": "call", + "span": { + "end": 1750, + "start": 1736 + } + }, + "span": { + "end": 1750, + "start": 1727 + } + }, + "condition_span": { + "end": 1751, + "start": 1720 + }, + "kind": "loop", + "span": { + "end": 1751, + "start": 1720 + } + }, + { + "kind": "return", + "span": { + "end": 1945, + "start": 1924 + }, + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 1938, + "start": 1932 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "]" + }, + "span": { + "end": 1944, + "start": 1932 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1666, + "start": 1651 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.列表显示", + "local_name": "列表显示", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "列表", + "required": true, + "span": { + "end": 1681, + "start": 1675 + }, + "type": null + } + ] + }, + "span": { + "end": 1945, + "start": 1651 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/列表显示" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2008, + "start": 1982 + }, + "target": "键", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 2005, + "start": 1999 + }, + "value": { + "kind": "variable", + "name": "映射", + "span": { + "end": 2005, + "start": 1999 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "map", + "span": { + "end": 1993, + "start": 1990 + } + }, + "field": "keys", + "kind": "member", + "span": { + "end": 1998, + "start": 1990 + } + }, + "kind": "call", + "span": { + "end": 2006, + "start": 1990 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2026, + "start": 2010 + }, + "target": "结果", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "{" + } + }, + { + "kind": "assign", + "span": { + "end": 2042, + "start": 2028 + }, + "target": "下标", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2117, + "start": 2091 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 2108, + "start": 2102 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": ", " + }, + "span": { + "end": 2115, + "start": 2102 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 2084, + "start": 2078 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 2088, + "start": 2078 + } + }, + "condition_span": { + "end": 2089, + "start": 2074 + }, + "span": { + "end": 2089, + "start": 2074 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2151, + "start": 2137 + }, + "target": "忽略", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 2135, + "start": 2126 + }, + "span": { + "end": 2135, + "start": 2126 + } + } + ], + "kind": "branch", + "span": { + "end": 2135, + "start": 2126 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 2089, + "start": 2074 + }, + "span": { + "end": 2089, + "start": 2074 + } + } + ], + "kind": "branch", + "span": { + "end": 2089, + "start": 2074 + } + }, + { + "kind": "assign", + "span": { + "end": 2192, + "start": 2165 + }, + "target": "当前键", + "value": { + "base": { + "kind": "variable", + "name": "键", + "span": { + "end": 2182, + "start": 2179 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 2189, + "start": 2183 + } + }, + "kind": "index", + "span": { + "end": 2190, + "start": 2179 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2272, + "start": 2194 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 2211, + "start": 2205 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "当前键", + "span": { + "end": 2223, + "start": 2214 + } + }, + "span": { + "end": 2223, + "start": 2205 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": ": " + }, + "span": { + "end": 2230, + "start": 2205 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2269, + "start": 2243 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 2257, + "start": 2251 + }, + "value": { + "kind": "variable", + "name": "映射", + "span": { + "end": 2257, + "start": 2251 + } + } + }, + { + "name": null, + "span": { + "end": 2268, + "start": 2259 + }, + "value": { + "kind": "variable", + "name": "当前键", + "span": { + "end": 2268, + "start": 2259 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "map", + "span": { + "end": 2246, + "start": 2243 + } + }, + "field": "get", + "kind": "member", + "span": { + "end": 2250, + "start": 2243 + } + }, + "kind": "call", + "span": { + "end": 2269, + "start": 2243 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "值显示", + "span": { + "end": 2242, + "start": 2233 + } + }, + "kind": "call", + "span": { + "end": 2270, + "start": 2233 + } + }, + "span": { + "end": 2270, + "start": 2205 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2297, + "start": 2274 + }, + "target": "下标", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 2291, + "start": 2285 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 2295, + "start": 2285 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 2057, + "start": 2051 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2070, + "start": 2067 + }, + "value": { + "kind": "variable", + "name": "键", + "span": { + "end": 2070, + "start": 2067 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 2066, + "start": 2060 + } + }, + "kind": "call", + "span": { + "end": 2071, + "start": 2060 + } + }, + "span": { + "end": 2071, + "start": 2051 + } + }, + "condition_span": { + "end": 2072, + "start": 2044 + }, + "kind": "loop", + "span": { + "end": 2072, + "start": 2044 + } + }, + { + "kind": "return", + "span": { + "end": 2326, + "start": 2305 + }, + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 2319, + "start": 2313 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "}" + }, + "span": { + "end": 2325, + "start": 2313 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1962, + "start": 1947 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.映射显示", + "local_name": "映射显示", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "映射", + "required": true, + "span": { + "end": 1977, + "start": 1971 + }, + "type": null + } + ] + }, + "span": { + "end": 2326, + "start": 1947 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/映射显示" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2394, + "start": 2363 + }, + "target": "列", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 2391, + "start": 2385 + }, + "value": { + "kind": "variable", + "name": "表格", + "span": { + "end": 2391, + "start": 2385 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "table", + "span": { + "end": 2376, + "start": 2371 + } + }, + "field": "columns", + "kind": "member", + "span": { + "end": 2384, + "start": 2371 + } + }, + "kind": "call", + "span": { + "end": 2392, + "start": 2371 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2451, + "start": 2396 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Table[" + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2434, + "start": 2431 + }, + "value": { + "kind": "variable", + "name": "列", + "span": { + "end": 2434, + "start": 2431 + } + } + }, + { + "name": null, + "span": { + "end": 2441, + "start": 2436 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": " | " + } + } + ], + "callee": { + "kind": "variable", + "name": "连接文本", + "span": { + "end": 2430, + "start": 2418 + } + }, + "kind": "call", + "span": { + "end": 2442, + "start": 2418 + } + }, + "span": { + "end": 2442, + "start": 2407 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "]{" + }, + "span": { + "end": 2449, + "start": 2407 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2467, + "start": 2453 + }, + "target": "行号", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2545, + "start": 2519 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 2536, + "start": 2530 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "; " + }, + "span": { + "end": 2543, + "start": 2530 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "行号", + "span": { + "end": 2512, + "start": 2506 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 2516, + "start": 2506 + } + }, + "condition_span": { + "end": 2517, + "start": 2502 + }, + "span": { + "end": 2517, + "start": 2502 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2579, + "start": 2565 + }, + "target": "忽略", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 2563, + "start": 2554 + }, + "span": { + "end": 2563, + "start": 2554 + } + } + ], + "kind": "branch", + "span": { + "end": 2563, + "start": 2554 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 2517, + "start": 2502 + }, + "span": { + "end": 2517, + "start": 2502 + } + } + ], + "kind": "branch", + "span": { + "end": 2517, + "start": 2502 + } + }, + { + "kind": "assign", + "span": { + "end": 2628, + "start": 2593 + }, + "target": "行", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 2617, + "start": 2611 + }, + "value": { + "kind": "variable", + "name": "表格", + "span": { + "end": 2617, + "start": 2611 + } + } + }, + { + "name": null, + "span": { + "end": 2625, + "start": 2619 + }, + "value": { + "kind": "variable", + "name": "行号", + "span": { + "end": 2625, + "start": 2619 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "table", + "span": { + "end": 2606, + "start": 2601 + } + }, + "field": "row", + "kind": "member", + "span": { + "end": 2610, + "start": 2601 + } + }, + "kind": "call", + "span": { + "end": 2626, + "start": 2601 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2648, + "start": 2630 + }, + "target": "单元格", + "value": { + "items": [], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2664, + "start": 2650 + }, + "target": "列号", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2755, + "start": 2696 + }, + "target": "单元格", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 2731, + "start": 2722 + }, + "value": { + "kind": "variable", + "name": "单元格", + "span": { + "end": 2731, + "start": 2722 + } + } + }, + { + "name": null, + "span": { + "end": 2752, + "start": 2733 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 2751, + "start": 2740 + }, + "value": { + "base": { + "kind": "variable", + "name": "行", + "span": { + "end": 2743, + "start": 2740 + } + }, + "index": { + "kind": "variable", + "name": "列号", + "span": { + "end": 2750, + "start": 2744 + } + }, + "kind": "index", + "span": { + "end": 2751, + "start": 2740 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "显示", + "span": { + "end": 2739, + "start": 2733 + } + }, + "kind": "call", + "span": { + "end": 2752, + "start": 2733 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "list", + "span": { + "end": 2714, + "start": 2710 + } + }, + "field": "append", + "kind": "member", + "span": { + "end": 2721, + "start": 2710 + } + }, + "kind": "call", + "span": { + "end": 2753, + "start": 2710 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2780, + "start": 2757 + }, + "target": "列号", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "列号", + "span": { + "end": 2774, + "start": 2768 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 2778, + "start": 2768 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "列号", + "span": { + "end": 2679, + "start": 2673 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2692, + "start": 2689 + }, + "value": { + "kind": "variable", + "name": "行", + "span": { + "end": 2692, + "start": 2689 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 2688, + "start": 2682 + } + }, + "kind": "call", + "span": { + "end": 2693, + "start": 2682 + } + }, + "span": { + "end": 2693, + "start": 2673 + } + }, + "condition_span": { + "end": 2694, + "start": 2666 + }, + "kind": "loop", + "span": { + "end": 2694, + "start": 2666 + } + }, + { + "kind": "assign", + "span": { + "end": 2840, + "start": 2788 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 2805, + "start": 2799 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2830, + "start": 2821 + }, + "value": { + "kind": "variable", + "name": "单元格", + "span": { + "end": 2830, + "start": 2821 + } + } + }, + { + "name": null, + "span": { + "end": 2837, + "start": 2832 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": " | " + } + } + ], + "callee": { + "kind": "variable", + "name": "连接文本", + "span": { + "end": 2820, + "start": 2808 + } + }, + "kind": "call", + "span": { + "end": 2838, + "start": 2808 + } + }, + "span": { + "end": 2838, + "start": 2799 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2865, + "start": 2842 + }, + "target": "行号", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "行号", + "span": { + "end": 2859, + "start": 2853 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 2863, + "start": 2853 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "行号", + "span": { + "end": 2482, + "start": 2476 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2498, + "start": 2492 + }, + "value": { + "kind": "variable", + "name": "表格", + "span": { + "end": 2498, + "start": 2492 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 2491, + "start": 2485 + } + }, + "kind": "call", + "span": { + "end": 2499, + "start": 2485 + } + }, + "span": { + "end": 2499, + "start": 2476 + } + }, + "condition_span": { + "end": 2500, + "start": 2469 + }, + "kind": "loop", + "span": { + "end": 2500, + "start": 2469 + } + }, + { + "kind": "return", + "span": { + "end": 2894, + "start": 2873 + }, + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 2887, + "start": 2881 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "}" + }, + "span": { + "end": 2893, + "start": 2881 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 2343, + "start": 2328 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "local_name": "表格显示", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "表格", + "required": true, + "span": { + "end": 2358, + "start": 2352 + }, + "type": null + } + ] + }, + "span": { + "end": 2894, + "start": 2328 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/表格显示" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 2954, + "start": 2939 + }, + "target": "结果", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + } + }, + { + "kind": "assign", + "span": { + "end": 2970, + "start": 2956 + }, + "target": "下标", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3050, + "start": 3022 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3039, + "start": 3033 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "分隔", + "span": { + "end": 3048, + "start": 3042 + } + }, + "span": { + "end": 3048, + "start": 3033 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 3015, + "start": 3009 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 3019, + "start": 3009 + } + }, + "condition_span": { + "end": 3020, + "start": 3005 + }, + "span": { + "end": 3020, + "start": 3005 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3084, + "start": 3070 + }, + "target": "忽略", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3068, + "start": 3059 + }, + "span": { + "end": 3068, + "start": 3059 + } + } + ], + "kind": "branch", + "span": { + "end": 3068, + "start": 3059 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3020, + "start": 3005 + }, + "span": { + "end": 3020, + "start": 3005 + } + } + ], + "kind": "branch", + "span": { + "end": 3020, + "start": 3005 + } + }, + { + "kind": "assign", + "span": { + "end": 3134, + "start": 3098 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3115, + "start": 3109 + } + }, + "op": "add", + "right": { + "base": { + "kind": "variable", + "name": "列表", + "span": { + "end": 3124, + "start": 3118 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 3131, + "start": 3125 + } + }, + "kind": "index", + "span": { + "end": 3132, + "start": 3118 + } + }, + "span": { + "end": 3132, + "start": 3109 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3159, + "start": 3136 + }, + "target": "下标", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 3153, + "start": 3147 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 3157, + "start": 3147 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 2985, + "start": 2979 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 3001, + "start": 2995 + }, + "value": { + "kind": "variable", + "name": "列表", + "span": { + "end": 3001, + "start": 2995 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 2994, + "start": 2988 + } + }, + "kind": "call", + "span": { + "end": 3002, + "start": 2988 + } + }, + "span": { + "end": 3002, + "start": 2979 + } + }, + "condition_span": { + "end": 3003, + "start": 2972 + }, + "kind": "loop", + "span": { + "end": 3003, + "start": 2972 + } + }, + { + "kind": "return", + "span": { + "end": 3182, + "start": 3167 + }, + "value": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3181, + "start": 3175 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 2911, + "start": 2896 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.连接文本", + "local_name": "连接文本", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "列表", + "required": true, + "span": { + "end": 2926, + "start": 2920 + }, + "type": null + }, + { + "default": null, + "name": "分隔", + "required": true, + "span": { + "end": 2934, + "start": 2927 + }, + "type": null + } + ] + }, + "span": { + "end": 3182, + "start": 2896 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/连接文本" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3336, + "start": 3312 + }, + "target": "类别", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3333, + "start": 3330 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 3333, + "start": 3330 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "类型", + "span": { + "end": 3329, + "start": 3323 + } + }, + "kind": "call", + "span": { + "end": 3334, + "start": 3323 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 3387, + "start": 3361 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3385, + "start": 3382 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 3385, + "start": 3382 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "转义文本", + "span": { + "end": 3381, + "start": 3369 + } + }, + "kind": "call", + "span": { + "end": 3386, + "start": 3369 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "类别", + "span": { + "end": 3348, + "start": 3342 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "Text" + }, + "span": { + "end": 3358, + "start": 3342 + } + }, + "condition_span": { + "end": 3359, + "start": 3338 + }, + "span": { + "end": 3359, + "start": 3338 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 3427, + "start": 3407 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3425, + "start": 3422 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 3425, + "start": 3422 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "显示", + "span": { + "end": 3421, + "start": 3415 + } + }, + "kind": "call", + "span": { + "end": 3426, + "start": 3415 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3405, + "start": 3396 + }, + "span": { + "end": 3405, + "start": 3396 + } + } + ], + "kind": "branch", + "span": { + "end": 3405, + "start": 3396 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3359, + "start": 3338 + }, + "span": { + "end": 3359, + "start": 3338 + } + } + ], + "kind": "branch", + "span": { + "end": 3359, + "start": 3338 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 3196, + "start": 3184 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.值显示", + "local_name": "值显示", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "值", + "required": true, + "span": { + "end": 3208, + "start": 3205 + }, + "type": null + } + ] + }, + "span": { + "end": 3440, + "start": 3184 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/值显示" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3509, + "start": 3476 + }, + "target": "点", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3506, + "start": 3500 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 3506, + "start": 3500 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 3488, + "start": 3484 + } + }, + "field": "codepoints", + "kind": "member", + "span": { + "end": 3499, + "start": 3484 + } + }, + "kind": "call", + "span": { + "end": 3507, + "start": 3484 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3530, + "start": 3511 + }, + "target": "结果", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\"" + } + }, + { + "kind": "assign", + "span": { + "end": 3546, + "start": 3532 + }, + "target": "下标", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3602, + "start": 3578 + }, + "target": "码点", + "value": { + "base": { + "kind": "variable", + "name": "点", + "span": { + "end": 3592, + "start": 3589 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 3599, + "start": 3593 + } + }, + "kind": "index", + "span": { + "end": 3600, + "start": 3589 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3653, + "start": 3623 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3641, + "start": 3635 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\\\"" + }, + "span": { + "end": 3650, + "start": 3635 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 3614, + "start": 3608 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "34" + }, + "span": { + "end": 3620, + "start": 3608 + } + }, + "condition_span": { + "end": 3621, + "start": 3604 + }, + "span": { + "end": 3621, + "start": 3604 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3711, + "start": 3681 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3699, + "start": 3693 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\\\\" + }, + "span": { + "end": 3708, + "start": 3693 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 3672, + "start": 3666 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "92" + }, + "span": { + "end": 3678, + "start": 3666 + } + }, + "condition_span": { + "end": 3679, + "start": 3662 + }, + "span": { + "end": 3679, + "start": 3662 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3768, + "start": 3739 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3757, + "start": 3751 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\\n" + }, + "span": { + "end": 3765, + "start": 3751 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 3730, + "start": 3724 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "10" + }, + "span": { + "end": 3736, + "start": 3724 + } + }, + "condition_span": { + "end": 3737, + "start": 3720 + }, + "span": { + "end": 3737, + "start": 3720 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3824, + "start": 3795 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3813, + "start": 3807 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\\t" + }, + "span": { + "end": 3821, + "start": 3807 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 3787, + "start": 3781 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "9" + }, + "span": { + "end": 3792, + "start": 3781 + } + }, + "condition_span": { + "end": 3793, + "start": 3777 + }, + "span": { + "end": 3793, + "start": 3777 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3881, + "start": 3852 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3870, + "start": 3864 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\\r" + }, + "span": { + "end": 3878, + "start": 3864 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 3843, + "start": 3837 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "13" + }, + "span": { + "end": 3849, + "start": 3837 + } + }, + "condition_span": { + "end": 3850, + "start": 3833 + }, + "span": { + "end": 3850, + "start": 3833 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3950, + "start": 3901 + }, + "target": "结果", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3918, + "start": 3912 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 3947, + "start": 3941 + }, + "value": { + "kind": "variable", + "name": "码点", + "span": { + "end": 3947, + "start": 3941 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 3925, + "start": 3921 + } + }, + "field": "from_codepoint", + "kind": "member", + "span": { + "end": 3940, + "start": 3921 + } + }, + "kind": "call", + "span": { + "end": 3948, + "start": 3921 + } + }, + "span": { + "end": 3948, + "start": 3912 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3899, + "start": 3890 + }, + "span": { + "end": 3899, + "start": 3890 + } + } + ], + "kind": "branch", + "span": { + "end": 3899, + "start": 3890 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3850, + "start": 3833 + }, + "span": { + "end": 3850, + "start": 3833 + } + } + ], + "kind": "branch", + "span": { + "end": 3850, + "start": 3833 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3793, + "start": 3777 + }, + "span": { + "end": 3793, + "start": 3777 + } + } + ], + "kind": "branch", + "span": { + "end": 3793, + "start": 3777 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3737, + "start": 3720 + }, + "span": { + "end": 3737, + "start": 3720 + } + } + ], + "kind": "branch", + "span": { + "end": 3737, + "start": 3720 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3679, + "start": 3662 + }, + "span": { + "end": 3679, + "start": 3662 + } + } + ], + "kind": "branch", + "span": { + "end": 3679, + "start": 3662 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3621, + "start": 3604 + }, + "span": { + "end": 3621, + "start": 3604 + } + } + ], + "kind": "branch", + "span": { + "end": 3621, + "start": 3604 + } + }, + { + "kind": "assign", + "span": { + "end": 4011, + "start": 3988 + }, + "target": "下标", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 4005, + "start": 3999 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 4009, + "start": 3999 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 3561, + "start": 3555 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 3574, + "start": 3571 + }, + "value": { + "kind": "variable", + "name": "点", + "span": { + "end": 3574, + "start": 3571 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 3570, + "start": 3564 + } + }, + "kind": "call", + "span": { + "end": 3575, + "start": 3564 + } + }, + "span": { + "end": 3575, + "start": 3555 + } + }, + "condition_span": { + "end": 3576, + "start": 3548 + }, + "kind": "loop", + "span": { + "end": 3576, + "start": 3548 + } + }, + { + "kind": "return", + "span": { + "end": 4043, + "start": 4019 + }, + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "结果", + "span": { + "end": 4034, + "start": 4028 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\"" + }, + "span": { + "end": 4041, + "start": 4028 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 3456, + "start": 3441 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本", + "local_name": "转义文本", + "namespace": "format", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 3471, + "start": 3465 + }, + "type": null + } + ] + }, + "span": { + "end": 4043, + "start": 3441 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/转义文本" + } + ], + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md", + "imports": [], + "package_instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "references": [], + "relative_path": "format.mq.md", + "resources": [], + "source_digest": "72a3524ab6d8633337c5fc31da5265f6ebed8265421b12aef71d162fa5f00ad5", + "units": [ + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 4043, + "start": 0 + } + }, + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format", + "kind": "namespace", + "level": 1, + "name": "format", + "span": { + "end": 15, + "start": 1 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.字节长度", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/字节长度", + "kind": "function", + "level": 2, + "name": "字节长度", + "span": { + "end": 31, + "start": 16 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/显示", + "kind": "function", + "level": 2, + "name": "显示", + "span": { + "end": 477, + "start": 468 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.列表显示", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/列表显示", + "kind": "function", + "level": 2, + "name": "列表显示", + "span": { + "end": 1666, + "start": 1651 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.映射显示", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/映射显示", + "kind": "function", + "level": 2, + "name": "映射显示", + "span": { + "end": 1962, + "start": 1947 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.表格显示", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/表格显示", + "kind": "function", + "level": 2, + "name": "表格显示", + "span": { + "end": 2343, + "start": 2328 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.连接文本", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/连接文本", + "kind": "function", + "level": 2, + "name": "连接文本", + "span": { + "end": 2911, + "start": 2896 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.值显示", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/值显示", + "kind": "function", + "level": 2, + "name": "值显示", + "span": { + "end": 3196, + "start": 3184 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.转义文本", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md#format/转义文本", + "kind": "function", + "level": 2, + "name": "转义文本", + "span": { + "end": 3456, + "start": 3441 + } + } + ] + }, + { + "calls": [ + { + "callee": { + "base": { + "kind": "ident", + "name": "stream" + }, + "field": "写文本", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写文本", + "span": { + "end": 182, + "start": 158 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "stream" + }, + "field": "写全部", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写全部", + "span": { + "end": 291, + "start": 246 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写全部" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "stream" + }, + "field": "写文本", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写值", + "span": { + "end": 430, + "start": 387 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "format" + }, + "field": "显示", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写值", + "span": { + "end": 422, + "start": 404 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "console" + }, + "field": "读取行", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.读取行", + "span": { + "end": 486, + "start": 467 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "console" + }, + "field": "打印", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.打印", + "span": { + "end": 542, + "start": 523 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.打印" + } + ], + "functions": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 183, + "start": 150 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 181, + "start": 175 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 181, + "start": 175 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "stream", + "span": { + "end": 164, + "start": 158 + } + }, + "field": "写文本", + "kind": "member", + "span": { + "end": 174, + "start": 158 + } + }, + "kind": "call", + "span": { + "end": 182, + "start": 158 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 130, + "start": 118 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写文本", + "local_name": "写文本", + "namespace": "io", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 145, + "start": 139 + }, + "type": null + } + ] + }, + "span": { + "end": 183, + "start": 118 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/写文本" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 292, + "start": 238 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 266, + "start": 263 + }, + "value": { + "kind": "variable", + "name": "流", + "span": { + "end": 266, + "start": 263 + } + } + }, + { + "name": null, + "span": { + "end": 274, + "start": 268 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 274, + "start": 268 + } + } + }, + { + "name": null, + "span": { + "end": 282, + "start": 276 + }, + "value": { + "kind": "variable", + "name": "起点", + "span": { + "end": 282, + "start": 276 + } + } + }, + { + "name": null, + "span": { + "end": 290, + "start": 284 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 290, + "start": 284 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "stream", + "span": { + "end": 252, + "start": 246 + } + }, + "field": "写全部", + "kind": "member", + "span": { + "end": 262, + "start": 246 + } + }, + "kind": "call", + "span": { + "end": 291, + "start": 246 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 197, + "start": 185 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写全部", + "local_name": "写全部", + "namespace": "io", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "流", + "required": true, + "span": { + "end": 209, + "start": 206 + }, + "type": null + }, + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 217, + "start": 210 + }, + "type": null + }, + { + "default": null, + "name": "起点", + "required": true, + "span": { + "end": 225, + "start": 218 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 233, + "start": 226 + }, + "type": null + } + ] + }, + "span": { + "end": 292, + "start": 185 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/写全部" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 431, + "start": 379 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 429, + "start": 404 + }, + "value": { + "kind": "binary", + "left": { + "args": [ + { + "name": null, + "span": { + "end": 421, + "start": 418 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 421, + "start": 418 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "format", + "span": { + "end": 410, + "start": 404 + } + }, + "field": "显示", + "kind": "member", + "span": { + "end": 417, + "start": 404 + } + }, + "kind": "call", + "span": { + "end": 422, + "start": 404 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\n" + }, + "span": { + "end": 429, + "start": 404 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "stream", + "span": { + "end": 393, + "start": 387 + } + }, + "field": "写文本", + "kind": "member", + "span": { + "end": 403, + "start": 387 + } + }, + "kind": "call", + "span": { + "end": 430, + "start": 387 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 303, + "start": 294 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写值", + "local_name": "写值", + "namespace": "io", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "值", + "required": true, + "span": { + "end": 315, + "start": 312 + }, + "type": null + } + ] + }, + "span": { + "end": 431, + "start": 294 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/写值" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 487, + "start": 459 + }, + "value": { + "args": [], + "callee": { + "base": { + "kind": "variable", + "name": "console", + "span": { + "end": 474, + "start": 467 + } + }, + "field": "读取行", + "kind": "member", + "span": { + "end": 484, + "start": 467 + } + }, + "kind": "call", + "span": { + "end": 486, + "start": 467 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 445, + "start": 433 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.读取行", + "local_name": "读取行", + "namespace": "io", + "signature": { + "kind": "explicit", + "params": [] + }, + "span": { + "end": 487, + "start": 433 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/读取行" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 543, + "start": 515 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 541, + "start": 538 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 541, + "start": 538 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "console", + "span": { + "end": 530, + "start": 523 + } + }, + "field": "打印", + "kind": "member", + "span": { + "end": 537, + "start": 523 + } + }, + "kind": "call", + "span": { + "end": 542, + "start": 523 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 498, + "start": 489 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.打印", + "local_name": "打印", + "namespace": "io", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "值", + "required": true, + "span": { + "end": 510, + "start": 507 + }, + "type": null + } + ] + }, + "span": { + "end": 543, + "start": 489 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/打印" + } + ], + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md", + "imports": [ + { + "alias": "console", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md", + "span": { + "end": 104, + "start": 0 + }, + "target": "./io/console.mq.md" + }, + { + "alias": "format", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md", + "span": { + "end": 104, + "start": 0 + }, + "target": "./format.mq.md" + }, + { + "alias": "stream", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md", + "span": { + "end": 104, + "start": 0 + }, + "target": "./io/stream.mq.md" + } + ], + "package_instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "references": [], + "relative_path": "io.mq.md", + "resources": [], + "source_digest": "5a3d67e8757b008e6ba5660dc44d57c8ab79d63df95415471b2f9944d3650ca4", + "units": [ + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 543, + "start": 0 + } + }, + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io", + "kind": "namespace", + "level": 1, + "name": "io", + "span": { + "end": 116, + "start": 106 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写文本", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/写文本", + "kind": "function", + "level": 2, + "name": "写文本", + "span": { + "end": 130, + "start": 118 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写全部", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/写全部", + "kind": "function", + "level": 2, + "name": "写全部", + "span": { + "end": 197, + "start": 185 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.写值", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/写值", + "kind": "function", + "level": 2, + "name": "写值", + "span": { + "end": 303, + "start": 294 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.读取行", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/读取行", + "kind": "function", + "level": 2, + "name": "读取行", + "span": { + "end": 445, + "start": 433 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md::io.打印", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io.mq.md#io/打印", + "kind": "function", + "level": 2, + "name": "打印", + "span": { + "end": 498, + "start": 489 + } + } + ] + }, + { + "calls": [ + { + "callee": { + "base": { + "kind": "ident", + "name": "resource" + }, + "field": "open", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 363, + "start": 322 + }, + "state": "builtin", + "target": "resource.open" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "memory" + }, + "field": "new", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 394, + "start": 378 + }, + "state": "builtin", + "target": "memory.new" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "resource" + }, + "field": "read", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 515, + "start": 483 + }, + "state": "builtin", + "target": "resource.read" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "list" + }, + "field": "append", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 768, + "start": 738 + }, + "state": "builtin", + "target": "list.append" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "resource" + }, + "field": "close", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 832, + "start": 813 + }, + "state": "builtin", + "target": "resource.close" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 990, + "start": 976 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 1110, + "start": 1096 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "memory" + }, + "field": "new", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 1329, + "start": 1309 + }, + "state": "builtin", + "target": "memory.new" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "utf8" + }, + "field": "解码", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "span": { + "end": 1497, + "start": 1461 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "stream" + }, + "field": "写文本", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.打印", + "span": { + "end": 1714, + "start": 1671 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "format" + }, + "field": "显示", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.打印", + "span": { + "end": 1706, + "start": 1688 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.显示" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "stream" + }, + "field": "写文本", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.写文本", + "span": { + "end": 1883, + "start": 1859 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "stream" + }, + "field": "写全部", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.写全部", + "span": { + "end": 1992, + "start": 1947 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写全部" + } + ], + "functions": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 365, + "start": 314 + }, + "target": "流", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 343, + "start": 336 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "stdio" + } + }, + { + "name": null, + "span": { + "end": 352, + "start": 345 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "stdin" + } + }, + { + "name": null, + "span": { + "end": 362, + "start": 354 + }, + "value": { + "items": [ + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "read" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "resource", + "span": { + "end": 330, + "start": 322 + } + }, + "field": "open", + "kind": "member", + "span": { + "end": 335, + "start": 322 + } + }, + "kind": "call", + "span": { + "end": 363, + "start": 322 + } + } + }, + { + "kind": "assign", + "span": { + "end": 396, + "start": 367 + }, + "target": "内存", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 390, + "start": 389 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + } + }, + { + "name": null, + "span": { + "end": 393, + "start": 392 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "memory", + "span": { + "end": 384, + "start": 378 + } + }, + "field": "new", + "kind": "member", + "span": { + "end": 388, + "start": 378 + } + }, + "kind": "call", + "span": { + "end": 394, + "start": 378 + } + } + }, + { + "kind": "assign", + "span": { + "end": 413, + "start": 398 + }, + "target": "字节", + "value": { + "items": [], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + }, + { + "kind": "assign", + "span": { + "end": 433, + "start": 415 + }, + "target": "结束", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": false + } + }, + { + "kind": "assign", + "span": { + "end": 450, + "start": 435 + }, + "target": "错误", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 517, + "start": 472 + }, + "target": "读取", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 500, + "start": 497 + }, + "value": { + "kind": "variable", + "name": "流", + "span": { + "end": 500, + "start": 497 + } + } + }, + { + "name": null, + "span": { + "end": 508, + "start": 502 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 508, + "start": 502 + } + } + }, + { + "name": null, + "span": { + "end": 511, + "start": 510 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "name": null, + "span": { + "end": 514, + "start": 513 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "resource", + "span": { + "end": 491, + "start": 483 + } + }, + "field": "read", + "kind": "member", + "span": { + "end": 496, + "start": 483 + } + }, + "kind": "call", + "span": { + "end": 515, + "start": 483 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 556, + "start": 539 + }, + "target": "结束", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "kind": "assign", + "span": { + "end": 582, + "start": 558 + }, + "target": "错误", + "value": { + "base": { + "kind": "variable", + "name": "读取", + "span": { + "end": 575, + "start": 569 + } + }, + "field": "code", + "kind": "member", + "span": { + "end": 580, + "start": 569 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "base": { + "kind": "variable", + "name": "读取", + "span": { + "end": 533, + "start": 527 + } + }, + "field": "ok", + "kind": "member", + "span": { + "end": 536, + "start": 527 + } + }, + "span": { + "end": 536, + "start": 523 + } + }, + "condition_span": { + "end": 537, + "start": 519 + }, + "span": { + "end": 537, + "start": 519 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 659, + "start": 642 + }, + "target": "结束", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + } + ], + "condition": { + "kind": "binary", + "left": { + "base": { + "base": { + "kind": "variable", + "name": "读取", + "span": { + "end": 601, + "start": 595 + } + }, + "field": "value", + "kind": "member", + "span": { + "end": 607, + "start": 595 + } + }, + "field": "eof", + "kind": "member", + "span": { + "end": 611, + "start": 595 + } + }, + "op": "and", + "right": { + "kind": "binary", + "left": { + "base": { + "base": { + "kind": "variable", + "name": "读取", + "span": { + "end": 622, + "start": 616 + } + }, + "field": "value", + "kind": "member", + "span": { + "end": 628, + "start": 616 + } + }, + "field": "count", + "kind": "member", + "span": { + "end": 634, + "start": 616 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 639, + "start": 616 + } + }, + "span": { + "end": 639, + "start": 595 + } + }, + "condition_span": { + "end": 640, + "start": 591 + }, + "span": { + "end": 640, + "start": 591 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 707, + "start": 690 + }, + "target": "结束", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + } + ], + "condition": { + "kind": "binary", + "left": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 678, + "start": 672 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "kind": "index", + "span": { + "end": 681, + "start": 672 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "10" + }, + "span": { + "end": 687, + "start": 672 + } + }, + "condition_span": { + "end": 688, + "start": 668 + }, + "span": { + "end": 688, + "start": 668 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 770, + "start": 727 + }, + "target": "字节", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 756, + "start": 750 + }, + "value": { + "kind": "variable", + "name": "字节", + "span": { + "end": 756, + "start": 750 + } + } + }, + { + "name": null, + "span": { + "end": 767, + "start": 758 + }, + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 764, + "start": 758 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "kind": "index", + "span": { + "end": 767, + "start": 758 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "list", + "span": { + "end": 742, + "start": 738 + } + }, + "field": "append", + "kind": "member", + "span": { + "end": 749, + "start": 738 + } + }, + "kind": "call", + "span": { + "end": 768, + "start": 738 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 725, + "start": 716 + }, + "span": { + "end": 725, + "start": 716 + } + } + ], + "kind": "branch", + "span": { + "end": 725, + "start": 716 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 688, + "start": 668 + }, + "span": { + "end": 688, + "start": 668 + } + } + ], + "kind": "branch", + "span": { + "end": 688, + "start": 668 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 640, + "start": 591 + }, + "span": { + "end": 640, + "start": 591 + } + } + ], + "kind": "branch", + "span": { + "end": 640, + "start": 591 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 537, + "start": 519 + }, + "span": { + "end": 537, + "start": 519 + } + } + ], + "kind": "branch", + "span": { + "end": 537, + "start": 519 + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "kind": "variable", + "name": "结束", + "span": { + "end": 469, + "start": 463 + } + }, + "span": { + "end": 469, + "start": 459 + } + }, + "condition_span": { + "end": 470, + "start": 452 + }, + "kind": "loop", + "span": { + "end": 470, + "start": 452 + } + }, + { + "kind": "assign", + "span": { + "end": 834, + "start": 802 + }, + "target": "关闭", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 831, + "start": 828 + }, + "value": { + "kind": "variable", + "name": "流", + "span": { + "end": 831, + "start": 828 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "resource", + "span": { + "end": 821, + "start": 813 + } + }, + "field": "close", + "kind": "member", + "span": { + "end": 827, + "start": 813 + } + }, + "kind": "call", + "span": { + "end": 832, + "start": 813 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 919, + "start": 855 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 866, + "start": 864 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": false + } + }, + { + "key": "code", + "key_span": { + "end": 879, + "start": 875 + }, + "value": { + "kind": "variable", + "name": "错误", + "span": { + "end": 887, + "start": 881 + } + } + }, + { + "key": "message", + "key_span": { + "end": 896, + "start": 889 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "stdin read failed" + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "错误", + "span": { + "end": 846, + "start": 840 + } + }, + "op": "ne", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + }, + "span": { + "end": 852, + "start": 840 + } + }, + "condition_span": { + "end": 853, + "start": 836 + }, + "span": { + "end": 853, + "start": 836 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 963, + "start": 948 + }, + "value": { + "kind": "variable", + "name": "关闭", + "span": { + "end": 962, + "start": 956 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "base": { + "kind": "variable", + "name": "关闭", + "span": { + "end": 942, + "start": 936 + } + }, + "field": "ok", + "kind": "member", + "span": { + "end": 945, + "start": 936 + } + }, + "span": { + "end": 945, + "start": 932 + } + }, + "condition_span": { + "end": 946, + "start": 928 + }, + "span": { + "end": 946, + "start": 928 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1059, + "start": 998 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 1009, + "start": 1007 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": false + } + }, + { + "key": "code", + "key_span": { + "end": 1022, + "start": 1018 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "io.eof" + } + }, + { + "key": "message", + "key_span": { + "end": 1041, + "start": 1034 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "end of input" + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "args": [ + { + "name": null, + "span": { + "end": 989, + "start": 983 + }, + "value": { + "kind": "variable", + "name": "字节", + "span": { + "end": 989, + "start": 983 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 982, + "start": 976 + } + }, + "kind": "call", + "span": { + "end": 990, + "start": 976 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 995, + "start": 976 + } + }, + "condition_span": { + "end": 996, + "start": 972 + }, + "span": { + "end": 996, + "start": 972 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1112, + "start": 1079 + }, + "target": "数据长度", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1109, + "start": 1103 + }, + "value": { + "kind": "variable", + "name": "字节", + "span": { + "end": 1109, + "start": 1103 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1102, + "start": 1096 + } + }, + "kind": "call", + "span": { + "end": 1110, + "start": 1096 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1207, + "start": 1172 + }, + "target": "数据长度", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "数据长度", + "span": { + "end": 1201, + "start": 1189 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1205, + "start": 1189 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "数据长度", + "span": { + "end": 1130, + "start": 1118 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 1134, + "start": 1118 + } + }, + "op": "and", + "right": { + "kind": "binary", + "left": { + "base": { + "kind": "variable", + "name": "字节", + "span": { + "end": 1145, + "start": 1139 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "数据长度", + "span": { + "end": 1158, + "start": 1146 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1162, + "start": 1146 + } + }, + "kind": "index", + "span": { + "end": 1163, + "start": 1139 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "13" + }, + "span": { + "end": 1169, + "start": 1139 + } + }, + "span": { + "end": 1169, + "start": 1118 + } + }, + "condition_span": { + "end": 1170, + "start": 1114 + }, + "span": { + "end": 1170, + "start": 1114 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1241, + "start": 1227 + }, + "target": "忽略", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1225, + "start": 1216 + }, + "span": { + "end": 1225, + "start": 1216 + } + } + ], + "kind": "branch", + "span": { + "end": 1225, + "start": 1216 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1170, + "start": 1114 + }, + "span": { + "end": 1170, + "start": 1114 + } + } + ], + "kind": "branch", + "span": { + "end": 1170, + "start": 1114 + } + }, + { + "kind": "assign", + "span": { + "end": 1296, + "start": 1255 + }, + "target": "页", + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "数据长度", + "span": { + "end": 1276, + "start": 1264 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "65535" + }, + "span": { + "end": 1284, + "start": 1264 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "65536" + }, + "span": { + "end": 1294, + "start": 1263 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1331, + "start": 1298 + }, + "target": "数据", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1323, + "start": 1320 + }, + "value": { + "kind": "variable", + "name": "页", + "span": { + "end": 1323, + "start": 1320 + } + } + }, + { + "name": null, + "span": { + "end": 1328, + "start": 1325 + }, + "value": { + "kind": "variable", + "name": "页", + "span": { + "end": 1328, + "start": 1325 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "memory", + "span": { + "end": 1315, + "start": 1309 + } + }, + "field": "new", + "kind": "member", + "span": { + "end": 1319, + "start": 1309 + } + }, + "kind": "call", + "span": { + "end": 1329, + "start": 1309 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1347, + "start": 1333 + }, + "target": "下标", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1417, + "start": 1380 + }, + "target": { + "base": { + "kind": "variable", + "name": "数据", + "span": { + "end": 1389, + "start": 1383 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1396, + "start": 1390 + } + }, + "kind": "index", + "span": { + "end": 1397, + "start": 1383 + } + }, + "value": { + "base": { + "kind": "variable", + "name": "字节", + "span": { + "end": 1406, + "start": 1400 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1413, + "start": 1407 + } + }, + "kind": "index", + "span": { + "end": 1414, + "start": 1400 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1442, + "start": 1419 + }, + "target": "下标", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1436, + "start": 1430 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1440, + "start": 1430 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1362, + "start": 1356 + } + }, + "op": "lt", + "right": { + "kind": "variable", + "name": "数据长度", + "span": { + "end": 1377, + "start": 1365 + } + }, + "span": { + "end": 1377, + "start": 1356 + } + }, + "condition_span": { + "end": 1378, + "start": 1349 + }, + "kind": "loop", + "span": { + "end": 1378, + "start": 1349 + } + }, + { + "kind": "assign", + "span": { + "end": 1499, + "start": 1450 + }, + "target": "解码", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1479, + "start": 1473 + }, + "value": { + "kind": "variable", + "name": "数据", + "span": { + "end": 1479, + "start": 1473 + } + } + }, + { + "name": null, + "span": { + "end": 1482, + "start": 1481 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "name": null, + "span": { + "end": 1496, + "start": 1484 + }, + "value": { + "kind": "variable", + "name": "数据长度", + "span": { + "end": 1496, + "start": 1484 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "utf8", + "span": { + "end": 1465, + "start": 1461 + } + }, + "field": "解码", + "kind": "member", + "span": { + "end": 1472, + "start": 1461 + } + }, + "kind": "call", + "span": { + "end": 1497, + "start": 1461 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1536, + "start": 1521 + }, + "value": { + "kind": "variable", + "name": "解码", + "span": { + "end": 1535, + "start": 1529 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "base": { + "kind": "variable", + "name": "解码", + "span": { + "end": 1515, + "start": 1509 + } + }, + "field": "ok", + "kind": "member", + "span": { + "end": 1518, + "start": 1509 + } + }, + "span": { + "end": 1518, + "start": 1505 + } + }, + "condition_span": { + "end": 1519, + "start": 1501 + }, + "span": { + "end": 1519, + "start": 1501 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1596, + "start": 1556 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 1567, + "start": 1565 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "key": "value", + "key_span": { + "end": 1580, + "start": 1575 + }, + "value": { + "base": { + "kind": "variable", + "name": "解码", + "span": { + "end": 1588, + "start": 1582 + } + }, + "field": "value", + "kind": "member", + "span": { + "end": 1594, + "start": 1582 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1554, + "start": 1545 + }, + "span": { + "end": 1554, + "start": 1545 + } + } + ], + "kind": "branch", + "span": { + "end": 1554, + "start": 1545 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1519, + "start": 1501 + }, + "span": { + "end": 1519, + "start": 1501 + } + } + ], + "kind": "branch", + "span": { + "end": 1519, + "start": 1501 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1077, + "start": 1068 + }, + "span": { + "end": 1077, + "start": 1068 + } + } + ], + "kind": "branch", + "span": { + "end": 1077, + "start": 1068 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 996, + "start": 972 + }, + "span": { + "end": 996, + "start": 972 + } + } + ], + "kind": "branch", + "span": { + "end": 996, + "start": 972 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 946, + "start": 928 + }, + "span": { + "end": 946, + "start": 928 + } + } + ], + "kind": "branch", + "span": { + "end": 946, + "start": 928 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 853, + "start": 836 + }, + "span": { + "end": 853, + "start": 836 + } + } + ], + "kind": "branch", + "span": { + "end": 853, + "start": 836 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 130, + "start": 118 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "local_name": "读取行", + "namespace": "console", + "signature": { + "kind": "explicit", + "params": [] + }, + "span": { + "end": 1633, + "start": 118 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/读取行" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1716, + "start": 1660 + }, + "target": "结果", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1713, + "start": 1688 + }, + "value": { + "kind": "binary", + "left": { + "args": [ + { + "name": null, + "span": { + "end": 1705, + "start": 1702 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 1705, + "start": 1702 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "format", + "span": { + "end": 1694, + "start": 1688 + } + }, + "field": "显示", + "kind": "member", + "span": { + "end": 1701, + "start": 1688 + } + }, + "kind": "call", + "span": { + "end": 1706, + "start": 1688 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "\n" + }, + "span": { + "end": 1713, + "start": 1688 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "stream", + "span": { + "end": 1677, + "start": 1671 + } + }, + "field": "写文本", + "kind": "member", + "span": { + "end": 1687, + "start": 1671 + } + }, + "kind": "call", + "span": { + "end": 1714, + "start": 1671 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1753, + "start": 1738 + }, + "value": { + "kind": "variable", + "name": "结果", + "span": { + "end": 1752, + "start": 1746 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 1732, + "start": 1726 + } + }, + "field": "ok", + "kind": "member", + "span": { + "end": 1735, + "start": 1726 + } + }, + "span": { + "end": 1735, + "start": 1722 + } + }, + "condition_span": { + "end": 1736, + "start": 1718 + }, + "span": { + "end": 1736, + "start": 1718 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1805, + "start": 1773 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 1784, + "start": 1782 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "key": "value", + "key_span": { + "end": 1797, + "start": 1792 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "none" + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1771, + "start": 1762 + }, + "span": { + "end": 1771, + "start": 1762 + } + } + ], + "kind": "branch", + "span": { + "end": 1771, + "start": 1762 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1736, + "start": 1718 + }, + "span": { + "end": 1736, + "start": 1718 + } + } + ], + "kind": "branch", + "span": { + "end": 1736, + "start": 1718 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1643, + "start": 1634 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.打印", + "local_name": "打印", + "namespace": "console", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "值", + "required": true, + "span": { + "end": 1655, + "start": 1652 + }, + "type": null + } + ] + }, + "span": { + "end": 1818, + "start": 1634 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/打印" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 1884, + "start": 1851 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1882, + "start": 1876 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 1882, + "start": 1876 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "stream", + "span": { + "end": 1865, + "start": 1859 + } + }, + "field": "写文本", + "kind": "member", + "span": { + "end": 1875, + "start": 1859 + } + }, + "kind": "call", + "span": { + "end": 1883, + "start": 1859 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1831, + "start": 1819 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.写文本", + "local_name": "写文本", + "namespace": "console", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 1846, + "start": 1840 + }, + "type": null + } + ] + }, + "span": { + "end": 1884, + "start": 1819 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/写文本" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 1993, + "start": 1939 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1967, + "start": 1964 + }, + "value": { + "kind": "variable", + "name": "流", + "span": { + "end": 1967, + "start": 1964 + } + } + }, + { + "name": null, + "span": { + "end": 1975, + "start": 1969 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1975, + "start": 1969 + } + } + }, + { + "name": null, + "span": { + "end": 1983, + "start": 1977 + }, + "value": { + "kind": "variable", + "name": "起点", + "span": { + "end": 1983, + "start": 1977 + } + } + }, + { + "name": null, + "span": { + "end": 1991, + "start": 1985 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1991, + "start": 1985 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "stream", + "span": { + "end": 1953, + "start": 1947 + } + }, + "field": "写全部", + "kind": "member", + "span": { + "end": 1963, + "start": 1947 + } + }, + "kind": "call", + "span": { + "end": 1992, + "start": 1947 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1898, + "start": 1886 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.写全部", + "local_name": "写全部", + "namespace": "console", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "流", + "required": true, + "span": { + "end": 1910, + "start": 1907 + }, + "type": null + }, + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 1918, + "start": 1911 + }, + "type": null + }, + { + "default": null, + "name": "起点", + "required": true, + "span": { + "end": 1926, + "start": 1919 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 1934, + "start": 1927 + }, + "type": null + } + ] + }, + "span": { + "end": 1993, + "start": 1886 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/写全部" + } + ], + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md", + "imports": [ + { + "alias": "format", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md", + "span": { + "end": 99, + "start": 0 + }, + "target": "../format.mq.md" + }, + { + "alias": "stream", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md", + "span": { + "end": 99, + "start": 0 + }, + "target": "./stream.mq.md" + }, + { + "alias": "utf8", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md", + "span": { + "end": 99, + "start": 0 + }, + "target": "../text/utf8.mq.md" + } + ], + "package_instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "references": [], + "relative_path": "io/console.mq.md", + "resources": [], + "source_digest": "f9c2704e1e7dded4554e4be12432966b7653f770f7a2bfea6f9b90a87bd1b998", + "units": [ + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 1993, + "start": 0 + } + }, + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console", + "kind": "namespace", + "level": 1, + "name": "console", + "span": { + "end": 116, + "start": 101 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.读取行", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/读取行", + "kind": "function", + "level": 2, + "name": "读取行", + "span": { + "end": 130, + "start": 118 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.打印", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/打印", + "kind": "function", + "level": 2, + "name": "打印", + "span": { + "end": 1643, + "start": 1634 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.写文本", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/写文本", + "kind": "function", + "level": 2, + "name": "写文本", + "span": { + "end": 1831, + "start": 1819 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md::console.写全部", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/console.mq.md#console/写全部", + "kind": "function", + "level": 2, + "name": "写全部", + "span": { + "end": 1898, + "start": 1886 + } + } + ] + }, + { + "calls": [ + { + "callee": { + "base": { + "kind": "ident", + "name": "resource" + }, + "field": "write", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写全部", + "span": { + "end": 730, + "start": 678 + }, + "state": "builtin", + "target": "resource.write" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "format" + }, + "field": "字节长度", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1418, + "start": 1391 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md::format.字节长度" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "memory" + }, + "field": "new", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1481, + "start": 1433 + }, + "state": "builtin", + "target": "memory.new" + }, + { + "callee": { + "kind": "ident", + "name": "页数" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1461, + "start": 1444 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.页数" + }, + { + "callee": { + "kind": "ident", + "name": "页数" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1480, + "start": 1463 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.页数" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "utf8" + }, + "field": "编码", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1526, + "start": 1496 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.编码" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "resource" + }, + "field": "open", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1581, + "start": 1538 + }, + "state": "builtin", + "target": "resource.open" + }, + { + "callee": { + "kind": "ident", + "name": "写全部" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1632, + "start": 1599 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写全部" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "resource" + }, + "field": "close", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "span": { + "end": 1666, + "start": 1647 + }, + "state": "builtin", + "target": "resource.close" + } + ], + "functions": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 154, + "start": 119 + }, + "target": "页", + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "字节", + "span": { + "end": 134, + "start": 128 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "65535" + }, + "span": { + "end": 142, + "start": 128 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "65536" + }, + "span": { + "end": 152, + "start": 127 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 181, + "start": 171 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "页", + "span": { + "end": 163, + "start": 160 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 168, + "start": 160 + } + }, + "condition_span": { + "end": 169, + "start": 156 + }, + "span": { + "end": 169, + "start": 156 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 213, + "start": 201 + }, + "value": { + "kind": "variable", + "name": "页", + "span": { + "end": 212, + "start": 209 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 199, + "start": 190 + }, + "span": { + "end": 199, + "start": 190 + } + } + ], + "kind": "branch", + "span": { + "end": 199, + "start": 190 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 169, + "start": 156 + }, + "span": { + "end": 169, + "start": 156 + } + } + ], + "kind": "branch", + "span": { + "end": 169, + "start": 156 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 99, + "start": 90 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.页数", + "local_name": "页数", + "namespace": "stream", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "字节", + "required": true, + "span": { + "end": 114, + "start": 108 + }, + "type": null + } + ] + }, + "span": { + "end": 226, + "start": 90 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#stream/页数" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 447, + "start": 433 + }, + "target": "已写", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "kind": "assign", + "span": { + "end": 467, + "start": 449 + }, + "target": "失败", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": false + } + }, + { + "kind": "assign", + "span": { + "end": 511, + "start": 469 + }, + "target": "本次", + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 483, + "start": 481 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "key": "value", + "key_span": { + "end": 496, + "start": 491 + }, + "value": { + "entries": [ + { + "key": "count", + "key_span": { + "end": 504, + "start": 499 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + }, + { + "kind": "assign", + "span": { + "end": 610, + "start": 513 + }, + "target": "错误结果", + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 533, + "start": 531 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": false + } + }, + { + "key": "code", + "key_span": { + "end": 546, + "start": 542 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "io.write_zero" + } + }, + { + "key": "message", + "key_span": { + "end": 572, + "start": 565 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "resource.write made no progress" + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 665, + "start": 637 + }, + "target": "剩余", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "长度", + "span": { + "end": 654, + "start": 648 + } + }, + "op": "sub", + "right": { + "kind": "variable", + "name": "已写", + "span": { + "end": 663, + "start": 657 + } + }, + "span": { + "end": 663, + "start": 648 + } + } + }, + { + "kind": "assign", + "span": { + "end": 732, + "start": 667 + }, + "target": "本次", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 696, + "start": 693 + }, + "value": { + "kind": "variable", + "name": "流", + "span": { + "end": 696, + "start": 693 + } + } + }, + { + "name": null, + "span": { + "end": 704, + "start": 698 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 704, + "start": 698 + } + } + }, + { + "name": null, + "span": { + "end": 721, + "start": 706 + }, + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "起点", + "span": { + "end": 712, + "start": 706 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "已写", + "span": { + "end": 721, + "start": 715 + } + }, + "span": { + "end": 721, + "start": 706 + } + } + }, + { + "name": null, + "span": { + "end": 729, + "start": 723 + }, + "value": { + "kind": "variable", + "name": "剩余", + "span": { + "end": 729, + "start": 723 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "resource", + "span": { + "end": 686, + "start": 678 + } + }, + "field": "write", + "kind": "member", + "span": { + "end": 692, + "start": 678 + } + }, + "kind": "call", + "span": { + "end": 730, + "start": 678 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 771, + "start": 754 + }, + "target": "失败", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "kind": "assign", + "span": { + "end": 798, + "start": 773 + }, + "target": "错误结果", + "value": { + "kind": "variable", + "name": "本次", + "span": { + "end": 796, + "start": 790 + } + } + }, + { + "kind": "assign", + "span": { + "end": 819, + "start": 800 + }, + "target": "已写", + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 817, + "start": 811 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "base": { + "kind": "variable", + "name": "本次", + "span": { + "end": 748, + "start": 742 + } + }, + "field": "ok", + "kind": "member", + "span": { + "end": 751, + "start": 742 + } + }, + "span": { + "end": 751, + "start": 738 + } + }, + "condition_span": { + "end": 752, + "start": 734 + }, + "span": { + "end": 752, + "start": 734 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 875, + "start": 858 + }, + "target": "失败", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "kind": "assign", + "span": { + "end": 896, + "start": 877 + }, + "target": "已写", + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 894, + "start": 888 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "base": { + "base": { + "kind": "variable", + "name": "本次", + "span": { + "end": 838, + "start": 832 + } + }, + "field": "value", + "kind": "member", + "span": { + "end": 844, + "start": 832 + } + }, + "field": "count", + "kind": "member", + "span": { + "end": 850, + "start": 832 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 855, + "start": 832 + } + }, + "condition_span": { + "end": 856, + "start": 828 + }, + "span": { + "end": 856, + "start": 828 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 956, + "start": 916 + }, + "target": "已写", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "已写", + "span": { + "end": 933, + "start": 927 + } + }, + "op": "add", + "right": { + "base": { + "base": { + "kind": "variable", + "name": "本次", + "span": { + "end": 942, + "start": 936 + } + }, + "field": "value", + "kind": "member", + "span": { + "end": 948, + "start": 936 + } + }, + "field": "count", + "kind": "member", + "span": { + "end": 954, + "start": 936 + } + }, + "span": { + "end": 954, + "start": 927 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 914, + "start": 905 + }, + "span": { + "end": 914, + "start": 905 + } + } + ], + "kind": "branch", + "span": { + "end": 914, + "start": 905 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 856, + "start": 828 + }, + "span": { + "end": 856, + "start": 828 + } + } + ], + "kind": "branch", + "span": { + "end": 856, + "start": 828 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 752, + "start": 734 + }, + "span": { + "end": 752, + "start": 734 + } + } + ], + "kind": "branch", + "span": { + "end": 752, + "start": 734 + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "已写", + "span": { + "end": 625, + "start": 619 + } + }, + "op": "lt", + "right": { + "kind": "variable", + "name": "长度", + "span": { + "end": 634, + "start": 628 + } + }, + "span": { + "end": 634, + "start": 619 + } + }, + "condition_span": { + "end": 635, + "start": 612 + }, + "kind": "loop", + "span": { + "end": 635, + "start": 612 + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1016, + "start": 995 + }, + "value": { + "kind": "variable", + "name": "错误结果", + "span": { + "end": 1015, + "start": 1003 + } + } + } + ], + "condition": { + "kind": "variable", + "name": "失败", + "span": { + "end": 992, + "start": 986 + } + }, + "condition_span": { + "end": 993, + "start": 982 + }, + "span": { + "end": 993, + "start": 982 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1068, + "start": 1047 + }, + "value": { + "kind": "variable", + "name": "错误结果", + "span": { + "end": 1067, + "start": 1055 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "已写", + "span": { + "end": 1035, + "start": 1029 + } + }, + "op": "lt", + "right": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1044, + "start": 1038 + } + }, + "span": { + "end": 1044, + "start": 1029 + } + }, + "condition_span": { + "end": 1045, + "start": 1025 + }, + "span": { + "end": 1045, + "start": 1025 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1131, + "start": 1088 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 1099, + "start": 1097 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "key": "value", + "key_span": { + "end": 1112, + "start": 1107 + }, + "value": { + "entries": [ + { + "key": "count", + "key_span": { + "end": 1120, + "start": 1115 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1128, + "start": 1122 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1086, + "start": 1077 + }, + "span": { + "end": 1086, + "start": 1077 + } + } + ], + "kind": "branch", + "span": { + "end": 1086, + "start": 1077 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1045, + "start": 1025 + }, + "span": { + "end": 1045, + "start": 1025 + } + } + ], + "kind": "branch", + "span": { + "end": 1045, + "start": 1025 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 993, + "start": 982 + }, + "span": { + "end": 993, + "start": 982 + } + } + ], + "kind": "branch", + "span": { + "end": 993, + "start": 982 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 239, + "start": 227 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写全部", + "local_name": "写全部", + "namespace": "stream", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "流", + "required": true, + "span": { + "end": 251, + "start": 248 + }, + "type": null + }, + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 259, + "start": 252 + }, + "type": null + }, + { + "default": null, + "name": "起点", + "required": true, + "span": { + "end": 267, + "start": 260 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 275, + "start": 268 + }, + "type": null + } + ] + }, + "span": { + "end": 1150, + "start": 227 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#stream/写全部" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1420, + "start": 1377 + }, + "target": "字节数", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1417, + "start": 1411 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 1417, + "start": 1411 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "format", + "span": { + "end": 1397, + "start": 1391 + } + }, + "field": "字节长度", + "kind": "member", + "span": { + "end": 1410, + "start": 1391 + } + }, + "kind": "call", + "span": { + "end": 1418, + "start": 1391 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1483, + "start": 1422 + }, + "target": "内存", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1461, + "start": 1444 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1460, + "start": 1451 + }, + "value": { + "kind": "variable", + "name": "字节数", + "span": { + "end": 1460, + "start": 1451 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "页数", + "span": { + "end": 1450, + "start": 1444 + } + }, + "kind": "call", + "span": { + "end": 1461, + "start": 1444 + } + } + }, + { + "name": null, + "span": { + "end": 1480, + "start": 1463 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1479, + "start": 1470 + }, + "value": { + "kind": "variable", + "name": "字节数", + "span": { + "end": 1479, + "start": 1470 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "页数", + "span": { + "end": 1469, + "start": 1463 + } + }, + "kind": "call", + "span": { + "end": 1480, + "start": 1463 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "memory", + "span": { + "end": 1439, + "start": 1433 + } + }, + "field": "new", + "kind": "member", + "span": { + "end": 1443, + "start": 1433 + } + }, + "kind": "call", + "span": { + "end": 1481, + "start": 1433 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1528, + "start": 1485 + }, + "target": "长度", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1514, + "start": 1508 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 1514, + "start": 1508 + } + } + }, + { + "name": null, + "span": { + "end": 1522, + "start": 1516 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1522, + "start": 1516 + } + } + }, + { + "name": null, + "span": { + "end": 1525, + "start": 1524 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "utf8", + "span": { + "end": 1500, + "start": 1496 + } + }, + "field": "编码", + "kind": "member", + "span": { + "end": 1507, + "start": 1496 + } + }, + "kind": "call", + "span": { + "end": 1526, + "start": 1496 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1583, + "start": 1530 + }, + "target": "流", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1559, + "start": 1552 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "stdio" + } + }, + { + "name": null, + "span": { + "end": 1569, + "start": 1561 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "stdout" + } + }, + { + "name": null, + "span": { + "end": 1580, + "start": 1571 + }, + "value": { + "items": [ + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "write" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "resource", + "span": { + "end": 1546, + "start": 1538 + } + }, + "field": "open", + "kind": "member", + "span": { + "end": 1551, + "start": 1538 + } + }, + "kind": "call", + "span": { + "end": 1581, + "start": 1538 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1634, + "start": 1585 + }, + "target": "写结果", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1612, + "start": 1609 + }, + "value": { + "kind": "variable", + "name": "流", + "span": { + "end": 1612, + "start": 1609 + } + } + }, + { + "name": null, + "span": { + "end": 1620, + "start": 1614 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1620, + "start": 1614 + } + } + }, + { + "name": null, + "span": { + "end": 1623, + "start": 1622 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "name": null, + "span": { + "end": 1631, + "start": 1625 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1631, + "start": 1625 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "写全部", + "span": { + "end": 1608, + "start": 1599 + } + }, + "kind": "call", + "span": { + "end": 1632, + "start": 1599 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1668, + "start": 1636 + }, + "target": "关闭", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 1665, + "start": 1662 + }, + "value": { + "kind": "variable", + "name": "流", + "span": { + "end": 1665, + "start": 1662 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "resource", + "span": { + "end": 1655, + "start": 1647 + } + }, + "field": "close", + "kind": "member", + "span": { + "end": 1661, + "start": 1647 + } + }, + "kind": "call", + "span": { + "end": 1666, + "start": 1647 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1711, + "start": 1693 + }, + "value": { + "kind": "variable", + "name": "写结果", + "span": { + "end": 1710, + "start": 1701 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "base": { + "kind": "variable", + "name": "写结果", + "span": { + "end": 1687, + "start": 1678 + } + }, + "field": "ok", + "kind": "member", + "span": { + "end": 1690, + "start": 1678 + } + }, + "span": { + "end": 1690, + "start": 1674 + } + }, + "condition_span": { + "end": 1691, + "start": 1670 + }, + "span": { + "end": 1691, + "start": 1670 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1755, + "start": 1740 + }, + "value": { + "kind": "variable", + "name": "关闭", + "span": { + "end": 1754, + "start": 1748 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "base": { + "kind": "variable", + "name": "关闭", + "span": { + "end": 1734, + "start": 1728 + } + }, + "field": "ok", + "kind": "member", + "span": { + "end": 1737, + "start": 1728 + } + }, + "span": { + "end": 1737, + "start": 1724 + } + }, + "condition_span": { + "end": 1738, + "start": 1720 + }, + "span": { + "end": 1738, + "start": 1720 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1818, + "start": 1775 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 1786, + "start": 1784 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "key": "value", + "key_span": { + "end": 1799, + "start": 1794 + }, + "value": { + "entries": [ + { + "key": "count", + "key_span": { + "end": 1807, + "start": 1802 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1815, + "start": 1809 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1773, + "start": 1764 + }, + "span": { + "end": 1773, + "start": 1764 + } + } + ], + "kind": "branch", + "span": { + "end": 1773, + "start": 1764 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1738, + "start": 1720 + }, + "span": { + "end": 1738, + "start": 1720 + } + } + ], + "kind": "branch", + "span": { + "end": 1738, + "start": 1720 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1691, + "start": 1670 + }, + "span": { + "end": 1691, + "start": 1670 + } + } + ], + "kind": "branch", + "span": { + "end": 1691, + "start": 1670 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1163, + "start": 1151 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "local_name": "写文本", + "namespace": "stream", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 1178, + "start": 1172 + }, + "type": null + } + ] + }, + "span": { + "end": 1836, + "start": 1151 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#stream/写文本" + } + ], + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md", + "imports": [ + { + "alias": "format", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::format.mq.md", + "span": { + "end": 72, + "start": 0 + }, + "target": "../format.mq.md" + }, + { + "alias": "utf8", + "resolved": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md", + "span": { + "end": 72, + "start": 0 + }, + "target": "../text/utf8.mq.md" + } + ], + "package_instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "references": [], + "relative_path": "io/stream.mq.md", + "resources": [], + "source_digest": "ad7c65d6425282cbccba54367446e6ae7bee335058db85c3b86460886852ab00", + "units": [ + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 1836, + "start": 0 + } + }, + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#stream", + "kind": "namespace", + "level": 1, + "name": "stream", + "span": { + "end": 88, + "start": 74 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.页数", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#stream/页数", + "kind": "function", + "level": 2, + "name": "页数", + "span": { + "end": 99, + "start": 90 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写全部", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#stream/写全部", + "kind": "function", + "level": 2, + "name": "写全部", + "span": { + "end": 239, + "start": 227 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md::stream.写文本", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::io/stream.mq.md#stream/写文本", + "kind": "function", + "level": 2, + "name": "写文本", + "span": { + "end": 1163, + "start": 1151 + } + } + ] + }, + { + "calls": [ + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "codepoints", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.编码", + "span": { + "end": 464, + "start": 441 + }, + "state": "builtin", + "target": "text.codepoints" + }, + { + "callee": { + "kind": "ident", + "name": "长度" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.编码", + "span": { + "end": 527, + "start": 516 + }, + "state": "builtin", + "target": "长度" + }, + { + "callee": { + "kind": "ident", + "name": "续字节" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码2", + "span": { + "end": 1571, + "start": 1558 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "from_codepoint", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码2", + "span": { + "end": 1820, + "start": 1793 + }, + "state": "builtin", + "target": "text.from_codepoint" + }, + { + "callee": { + "kind": "ident", + "name": "续字节" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码3", + "span": { + "end": 2078, + "start": 2065 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节" + }, + { + "callee": { + "kind": "ident", + "name": "续字节" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码3", + "span": { + "end": 2096, + "start": 2083 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "from_codepoint", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码3", + "span": { + "end": 2408, + "start": 2381 + }, + "state": "builtin", + "target": "text.from_codepoint" + }, + { + "callee": { + "kind": "ident", + "name": "续字节" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码4", + "span": { + "end": 2704, + "start": 2691 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节" + }, + { + "callee": { + "kind": "ident", + "name": "续字节" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码4", + "span": { + "end": 2722, + "start": 2709 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节" + }, + { + "callee": { + "kind": "ident", + "name": "续字节" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码4", + "span": { + "end": 2740, + "start": 2727 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "from_codepoint", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码4", + "span": { + "end": 3054, + "start": 3027 + }, + "state": "builtin", + "target": "text.from_codepoint" + }, + { + "callee": { + "base": { + "kind": "ident", + "name": "text" + }, + "field": "from_codepoint", + "kind": "member" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "span": { + "end": 3306, + "start": 3282 + }, + "state": "builtin", + "target": "text.from_codepoint" + }, + { + "callee": { + "kind": "ident", + "name": "解码2" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "span": { + "end": 3473, + "start": 3426 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码2" + }, + { + "callee": { + "kind": "ident", + "name": "解码3" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "span": { + "end": 3630, + "start": 3583 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码3" + }, + { + "callee": { + "kind": "ident", + "name": "解码4" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "span": { + "end": 3787, + "start": 3740 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码4" + }, + { + "callee": { + "kind": "ident", + "name": "成功" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "span": { + "end": 3998, + "start": 3984 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.成功" + }, + { + "callee": { + "kind": "ident", + "name": "失败" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "span": { + "end": 4063, + "start": 4027 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.失败" + }, + { + "callee": { + "kind": "ident", + "name": "编码" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.utf8编码", + "span": { + "end": 4165, + "start": 4135 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.编码" + }, + { + "callee": { + "kind": "ident", + "name": "解码" + }, + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.utf8解码", + "span": { + "end": 4255, + "start": 4225 + }, + "state": "function", + "target": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码" + } + ], + "functions": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 71, + "start": 40 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 51, + "start": 49 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + } + }, + { + "key": "value", + "key_span": { + "end": 64, + "start": 59 + }, + "value": { + "kind": "variable", + "name": "值", + "span": { + "end": 69, + "start": 66 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 23, + "start": 14 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.成功", + "local_name": "成功", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "值", + "required": true, + "span": { + "end": 35, + "start": 32 + }, + "type": null + } + ] + }, + "span": { + "end": 71, + "start": 14 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/成功" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 161, + "start": 110 + }, + "value": { + "entries": [ + { + "key": "ok", + "key_span": { + "end": 121, + "start": 119 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": false + } + }, + { + "key": "code", + "key_span": { + "end": 134, + "start": 130 + }, + "value": { + "kind": "variable", + "name": "代码", + "span": { + "end": 142, + "start": 136 + } + } + }, + { + "key": "message", + "key_span": { + "end": 151, + "start": 144 + }, + "value": { + "kind": "variable", + "name": "消息", + "span": { + "end": 159, + "start": 153 + } + } + } + ], + "kind": "record", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 82, + "start": 73 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.失败", + "local_name": "失败", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "代码", + "required": true, + "span": { + "end": 97, + "start": 91 + }, + "type": null + }, + { + "default": null, + "name": "消息", + "required": true, + "span": { + "end": 105, + "start": 98 + }, + "type": null + } + ] + }, + "span": { + "end": 161, + "start": 73 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/失败" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 234, + "start": 195 + }, + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "字节", + "span": { + "end": 209, + "start": 203 + } + }, + "op": "ge", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 216, + "start": 203 + } + }, + "op": "and", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "字节", + "span": { + "end": 227, + "start": 221 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "192" + }, + "span": { + "end": 233, + "start": 221 + } + }, + "span": { + "end": 233, + "start": 203 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 175, + "start": 163 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节", + "local_name": "续字节", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "字节", + "required": true, + "span": { + "end": 190, + "start": 184 + }, + "type": null + } + ] + }, + "span": { + "end": 234, + "start": 163 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/续字节" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 466, + "start": 433 + }, + "target": "点", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 463, + "start": 457 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 463, + "start": 457 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 445, + "start": 441 + } + }, + "field": "codepoints", + "kind": "member", + "span": { + "end": 456, + "start": 441 + } + }, + "kind": "call", + "span": { + "end": 464, + "start": 441 + } + } + }, + { + "kind": "assign", + "span": { + "end": 482, + "start": 468 + }, + "target": "下标", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "kind": "assign", + "span": { + "end": 498, + "start": 484 + }, + "target": "偏移", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 554, + "start": 530 + }, + "target": "码点", + "value": { + "base": { + "kind": "variable", + "name": "点", + "span": { + "end": 544, + "start": 541 + } + }, + "index": { + "kind": "variable", + "name": "下标", + "span": { + "end": 551, + "start": 545 + } + }, + "kind": "index", + "span": { + "end": 552, + "start": 541 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 613, + "start": 575 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 584, + "start": 578 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 591, + "start": 585 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 600, + "start": 594 + } + }, + "span": { + "end": 600, + "start": 585 + } + }, + "kind": "index", + "span": { + "end": 601, + "start": 578 + } + }, + "value": { + "kind": "variable", + "name": "码点", + "span": { + "end": 610, + "start": 604 + } + } + }, + { + "kind": "assign", + "span": { + "end": 638, + "start": 615 + }, + "target": "偏移", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 632, + "start": 626 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 636, + "start": 626 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 566, + "start": 560 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 572, + "start": 560 + } + }, + "condition_span": { + "end": 573, + "start": 556 + }, + "span": { + "end": 573, + "start": 556 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 717, + "start": 667 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 676, + "start": 670 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 683, + "start": 677 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 692, + "start": 686 + } + }, + "span": { + "end": 692, + "start": 677 + } + }, + "kind": "index", + "span": { + "end": 693, + "start": 670 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "192" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 708, + "start": 702 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 714, + "start": 702 + } + }, + "span": { + "end": 714, + "start": 696 + } + } + }, + { + "kind": "assign", + "span": { + "end": 772, + "start": 719 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 728, + "start": 722 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 735, + "start": 729 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 744, + "start": 738 + } + }, + "span": { + "end": 744, + "start": 729 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 748, + "start": 729 + } + }, + "kind": "index", + "span": { + "end": 749, + "start": 722 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 764, + "start": 758 + } + }, + "op": "mod", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 769, + "start": 758 + } + }, + "span": { + "end": 769, + "start": 752 + } + } + }, + { + "kind": "assign", + "span": { + "end": 797, + "start": 774 + }, + "target": "偏移", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 791, + "start": 785 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 795, + "start": 785 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 657, + "start": 651 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2048" + }, + "span": { + "end": 664, + "start": 651 + } + }, + "condition_span": { + "end": 665, + "start": 647 + }, + "span": { + "end": 665, + "start": 647 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 879, + "start": 827 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 836, + "start": 830 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 843, + "start": 837 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 852, + "start": 846 + } + }, + "span": { + "end": 852, + "start": 837 + } + }, + "kind": "index", + "span": { + "end": 853, + "start": 830 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "224" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 868, + "start": 862 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "4096" + }, + "span": { + "end": 876, + "start": 862 + } + }, + "span": { + "end": 876, + "start": 856 + } + } + }, + { + "kind": "assign", + "span": { + "end": 940, + "start": 881 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 890, + "start": 884 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 897, + "start": 891 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 906, + "start": 900 + } + }, + "span": { + "end": 906, + "start": 891 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 910, + "start": 891 + } + }, + "kind": "index", + "span": { + "end": 911, + "start": 884 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 926, + "start": 920 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 932, + "start": 920 + } + }, + "op": "mod", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 937, + "start": 920 + } + }, + "span": { + "end": 937, + "start": 914 + } + } + }, + { + "kind": "assign", + "span": { + "end": 995, + "start": 942 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 951, + "start": 945 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 958, + "start": 952 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 967, + "start": 961 + } + }, + "span": { + "end": 967, + "start": 952 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 971, + "start": 952 + } + }, + "kind": "index", + "span": { + "end": 972, + "start": 945 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 987, + "start": 981 + } + }, + "op": "mod", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 992, + "start": 981 + } + }, + "span": { + "end": 992, + "start": 975 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1020, + "start": 997 + }, + "target": "偏移", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1014, + "start": 1008 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + }, + "span": { + "end": 1018, + "start": 1008 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 816, + "start": 810 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "65536" + }, + "span": { + "end": 824, + "start": 810 + } + }, + "condition_span": { + "end": 825, + "start": 806 + }, + "span": { + "end": 825, + "start": 806 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 1094, + "start": 1040 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1049, + "start": 1043 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 1056, + "start": 1050 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1065, + "start": 1059 + } + }, + "span": { + "end": 1065, + "start": 1050 + } + }, + "kind": "index", + "span": { + "end": 1066, + "start": 1043 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "240" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 1081, + "start": 1075 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "262144" + }, + "span": { + "end": 1091, + "start": 1075 + } + }, + "span": { + "end": 1091, + "start": 1069 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1157, + "start": 1096 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1105, + "start": 1099 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 1112, + "start": 1106 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1121, + "start": 1115 + } + }, + "span": { + "end": 1121, + "start": 1106 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1125, + "start": 1106 + } + }, + "kind": "index", + "span": { + "end": 1126, + "start": 1099 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 1141, + "start": 1135 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "4096" + }, + "span": { + "end": 1149, + "start": 1135 + } + }, + "op": "mod", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 1154, + "start": 1135 + } + }, + "span": { + "end": 1154, + "start": 1129 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1218, + "start": 1159 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1168, + "start": 1162 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 1175, + "start": 1169 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1184, + "start": 1178 + } + }, + "span": { + "end": 1184, + "start": 1169 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 1188, + "start": 1169 + } + }, + "kind": "index", + "span": { + "end": 1189, + "start": 1162 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 1204, + "start": 1198 + } + }, + "op": "floor_div", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 1210, + "start": 1198 + } + }, + "op": "mod", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 1215, + "start": 1198 + } + }, + "span": { + "end": 1215, + "start": 1192 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1273, + "start": 1220 + }, + "target": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1229, + "start": 1223 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 1236, + "start": 1230 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1245, + "start": 1239 + } + }, + "span": { + "end": 1245, + "start": 1230 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + }, + "span": { + "end": 1249, + "start": 1230 + } + }, + "kind": "index", + "span": { + "end": 1250, + "start": 1223 + } + }, + "value": { + "kind": "binary", + "left": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 1265, + "start": 1259 + } + }, + "op": "mod", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 1270, + "start": 1259 + } + }, + "span": { + "end": 1270, + "start": 1253 + } + } + }, + { + "kind": "assign", + "span": { + "end": 1298, + "start": 1275 + }, + "target": "偏移", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1292, + "start": 1286 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "4" + }, + "span": { + "end": 1296, + "start": 1286 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 1038, + "start": 1029 + }, + "span": { + "end": 1038, + "start": 1029 + } + } + ], + "kind": "branch", + "span": { + "end": 1038, + "start": 1029 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 825, + "start": 806 + }, + "span": { + "end": 825, + "start": 806 + } + } + ], + "kind": "branch", + "span": { + "end": 825, + "start": 806 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 665, + "start": 647 + }, + "span": { + "end": 665, + "start": 647 + } + } + ], + "kind": "branch", + "span": { + "end": 665, + "start": 647 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 573, + "start": 556 + }, + "span": { + "end": 573, + "start": 556 + } + } + ], + "kind": "branch", + "span": { + "end": 573, + "start": 556 + } + }, + { + "kind": "assign", + "span": { + "end": 1347, + "start": 1324 + }, + "target": "下标", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 1341, + "start": 1335 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1345, + "start": 1335 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "下标", + "span": { + "end": 513, + "start": 507 + } + }, + "op": "lt", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 526, + "start": 523 + }, + "value": { + "kind": "variable", + "name": "点", + "span": { + "end": 526, + "start": 523 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "长度", + "span": { + "end": 522, + "start": 516 + } + }, + "kind": "call", + "span": { + "end": 527, + "start": 516 + } + }, + "span": { + "end": 527, + "start": 507 + } + }, + "condition_span": { + "end": 528, + "start": 500 + }, + "kind": "loop", + "span": { + "end": 528, + "start": 500 + } + }, + { + "kind": "return", + "span": { + "end": 1370, + "start": 1355 + }, + "value": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1369, + "start": 1363 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 245, + "start": 236 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.编码", + "local_name": "编码", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 260, + "start": 254 + }, + "type": null + }, + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 268, + "start": 261 + }, + "type": null + }, + { + "default": null, + "name": "基址", + "required": true, + "span": { + "end": 276, + "start": 269 + }, + "type": null + } + ] + }, + "span": { + "end": 1370, + "start": 236 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/编码" + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1504, + "start": 1461 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 1476, + "start": 1470 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1484, + "start": 1478 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.truncated" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1444, + "start": 1438 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1448, + "start": 1438 + } + }, + "op": "ge", + "right": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1458, + "start": 1452 + } + }, + "span": { + "end": 1458, + "start": 1438 + } + }, + "condition_span": { + "end": 1459, + "start": 1434 + }, + "span": { + "end": 1459, + "start": 1434 + } + } + ], + "kind": "branch", + "span": { + "end": 1459, + "start": 1434 + } + }, + { + "kind": "assign", + "span": { + "end": 1548, + "start": 1512 + }, + "target": "b1", + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1525, + "start": 1519 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 1532, + "start": 1526 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1541, + "start": 1535 + } + }, + "span": { + "end": 1541, + "start": 1526 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 1545, + "start": 1526 + } + }, + "kind": "index", + "span": { + "end": 1546, + "start": 1519 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1628, + "start": 1574 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 1589, + "start": 1583 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1597, + "start": 1591 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_continuation" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "args": [ + { + "name": null, + "span": { + "end": 1570, + "start": 1568 + }, + "value": { + "kind": "variable", + "name": "b1", + "span": { + "end": 1570, + "start": 1568 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "续字节", + "span": { + "end": 1567, + "start": 1558 + } + }, + "kind": "call", + "span": { + "end": 1571, + "start": 1558 + } + }, + "span": { + "end": 1571, + "start": 1554 + } + }, + "condition_span": { + "end": 1572, + "start": 1550 + }, + "span": { + "end": 1572, + "start": 1550 + } + } + ], + "kind": "branch", + "span": { + "end": 1572, + "start": 1550 + } + }, + { + "kind": "assign", + "span": { + "end": 1698, + "start": 1636 + }, + "target": "码点", + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1654, + "start": 1648 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 1661, + "start": 1655 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1670, + "start": 1664 + } + }, + "span": { + "end": 1670, + "start": 1655 + } + }, + "kind": "index", + "span": { + "end": 1671, + "start": 1648 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "192" + }, + "span": { + "end": 1677, + "start": 1648 + } + }, + "op": "mul", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 1683, + "start": 1647 + } + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "b1", + "span": { + "end": 1689, + "start": 1687 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 1695, + "start": 1687 + } + }, + "span": { + "end": 1696, + "start": 1647 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1767, + "start": 1719 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 1734, + "start": 1728 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1742, + "start": 1736 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_scalar" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 1710, + "start": 1704 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 1716, + "start": 1704 + } + }, + "condition_span": { + "end": 1717, + "start": 1700 + }, + "span": { + "end": 1717, + "start": 1700 + } + } + ], + "kind": "branch", + "span": { + "end": 1717, + "start": 1700 + } + }, + { + "kind": "return", + "span": { + "end": 1838, + "start": 1775 + }, + "value": { + "items": [ + { + "kind": "binary", + "left": { + "kind": "variable", + "name": "文本", + "span": { + "end": 1790, + "start": 1784 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 1819, + "start": 1813 + }, + "value": { + "kind": "variable", + "name": "码点", + "span": { + "end": 1819, + "start": 1813 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 1797, + "start": 1793 + } + }, + "field": "from_codepoint", + "kind": "member", + "span": { + "end": 1812, + "start": 1793 + } + }, + "kind": "call", + "span": { + "end": 1820, + "start": 1793 + } + }, + "span": { + "end": 1820, + "start": 1784 + } + }, + { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1828, + "start": 1822 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 1832, + "start": 1822 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1382, + "start": 1372 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码2", + "local_name": "解码2", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 1397, + "start": 1391 + }, + "type": null + }, + { + "default": null, + "name": "基址", + "required": true, + "span": { + "end": 1405, + "start": 1398 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 1413, + "start": 1406 + }, + "type": null + }, + { + "default": null, + "name": "偏移", + "required": true, + "span": { + "end": 1421, + "start": 1414 + }, + "type": null + }, + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 1429, + "start": 1422 + }, + "type": null + } + ] + }, + "span": { + "end": 1838, + "start": 1372 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码2" + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 1972, + "start": 1929 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 1944, + "start": 1938 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1952, + "start": 1946 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.truncated" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 1912, + "start": 1906 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 1916, + "start": 1906 + } + }, + "op": "ge", + "right": { + "kind": "variable", + "name": "长度", + "span": { + "end": 1926, + "start": 1920 + } + }, + "span": { + "end": 1926, + "start": 1906 + } + }, + "condition_span": { + "end": 1927, + "start": 1902 + }, + "span": { + "end": 1927, + "start": 1902 + } + } + ], + "kind": "branch", + "span": { + "end": 1927, + "start": 1902 + } + }, + { + "kind": "assign", + "span": { + "end": 2016, + "start": 1980 + }, + "target": "b1", + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 1993, + "start": 1987 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 2000, + "start": 1994 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2009, + "start": 2003 + } + }, + "span": { + "end": 2009, + "start": 1994 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 2013, + "start": 1994 + } + }, + "kind": "index", + "span": { + "end": 2014, + "start": 1987 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2054, + "start": 2018 + }, + "target": "b2", + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 2031, + "start": 2025 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 2038, + "start": 2032 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2047, + "start": 2041 + } + }, + "span": { + "end": 2047, + "start": 2032 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 2051, + "start": 2032 + } + }, + "kind": "index", + "span": { + "end": 2052, + "start": 2025 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 2154, + "start": 2100 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 2115, + "start": 2109 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2123, + "start": 2117 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_continuation" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "kind": "binary", + "left": { + "args": [ + { + "name": null, + "span": { + "end": 2077, + "start": 2075 + }, + "value": { + "kind": "variable", + "name": "b1", + "span": { + "end": 2077, + "start": 2075 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "续字节", + "span": { + "end": 2074, + "start": 2065 + } + }, + "kind": "call", + "span": { + "end": 2078, + "start": 2065 + } + }, + "op": "and", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2095, + "start": 2093 + }, + "value": { + "kind": "variable", + "name": "b2", + "span": { + "end": 2095, + "start": 2093 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "续字节", + "span": { + "end": 2092, + "start": 2083 + } + }, + "kind": "call", + "span": { + "end": 2096, + "start": 2083 + } + }, + "span": { + "end": 2096, + "start": 2065 + } + }, + "span": { + "end": 2097, + "start": 2060 + } + }, + "condition_span": { + "end": 2098, + "start": 2056 + }, + "span": { + "end": 2098, + "start": 2056 + } + } + ], + "kind": "branch", + "span": { + "end": 2098, + "start": 2056 + } + }, + { + "kind": "assign", + "span": { + "end": 2244, + "start": 2162 + }, + "target": "码点", + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 2180, + "start": 2174 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 2187, + "start": 2181 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2196, + "start": 2190 + } + }, + "span": { + "end": 2196, + "start": 2181 + } + }, + "kind": "index", + "span": { + "end": 2197, + "start": 2174 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "224" + }, + "span": { + "end": 2203, + "start": 2174 + } + }, + "op": "mul", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "4096" + }, + "span": { + "end": 2211, + "start": 2173 + } + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "b1", + "span": { + "end": 2217, + "start": 2215 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 2223, + "start": 2215 + } + }, + "op": "mul", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 2229, + "start": 2214 + } + }, + "span": { + "end": 2229, + "start": 2173 + } + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "b2", + "span": { + "end": 2235, + "start": 2233 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 2241, + "start": 2233 + } + }, + "span": { + "end": 2242, + "start": 2173 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 2355, + "start": 2307 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 2322, + "start": 2316 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2330, + "start": 2324 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_scalar" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 2256, + "start": 2250 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2048" + }, + "span": { + "end": 2263, + "start": 2250 + } + }, + "op": "or", + "right": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 2274, + "start": 2268 + } + }, + "op": "ge", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "55296" + }, + "span": { + "end": 2283, + "start": 2268 + } + }, + "op": "and", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 2294, + "start": 2288 + } + }, + "op": "le", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "57343" + }, + "span": { + "end": 2303, + "start": 2288 + } + }, + "span": { + "end": 2303, + "start": 2268 + } + }, + "span": { + "end": 2304, + "start": 2250 + } + }, + "condition_span": { + "end": 2305, + "start": 2246 + }, + "span": { + "end": 2305, + "start": 2246 + } + } + ], + "kind": "branch", + "span": { + "end": 2305, + "start": 2246 + } + }, + { + "kind": "return", + "span": { + "end": 2426, + "start": 2363 + }, + "value": { + "items": [ + { + "kind": "binary", + "left": { + "kind": "variable", + "name": "文本", + "span": { + "end": 2378, + "start": 2372 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2407, + "start": 2401 + }, + "value": { + "kind": "variable", + "name": "码点", + "span": { + "end": 2407, + "start": 2401 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 2385, + "start": 2381 + } + }, + "field": "from_codepoint", + "kind": "member", + "span": { + "end": 2400, + "start": 2381 + } + }, + "kind": "call", + "span": { + "end": 2408, + "start": 2381 + } + }, + "span": { + "end": 2408, + "start": 2372 + } + }, + { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2416, + "start": 2410 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + }, + "span": { + "end": 2420, + "start": 2410 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 1850, + "start": 1840 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码3", + "local_name": "解码3", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 1865, + "start": 1859 + }, + "type": null + }, + { + "default": null, + "name": "基址", + "required": true, + "span": { + "end": 1873, + "start": 1866 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 1881, + "start": 1874 + }, + "type": null + }, + { + "default": null, + "name": "偏移", + "required": true, + "span": { + "end": 1889, + "start": 1882 + }, + "type": null + }, + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 1897, + "start": 1890 + }, + "type": null + } + ] + }, + "span": { + "end": 2426, + "start": 1840 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码3" + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 2560, + "start": 2517 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 2532, + "start": 2526 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2540, + "start": 2534 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.truncated" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2500, + "start": 2494 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + }, + "span": { + "end": 2504, + "start": 2494 + } + }, + "op": "ge", + "right": { + "kind": "variable", + "name": "长度", + "span": { + "end": 2514, + "start": 2508 + } + }, + "span": { + "end": 2514, + "start": 2494 + } + }, + "condition_span": { + "end": 2515, + "start": 2490 + }, + "span": { + "end": 2515, + "start": 2490 + } + } + ], + "kind": "branch", + "span": { + "end": 2515, + "start": 2490 + } + }, + { + "kind": "assign", + "span": { + "end": 2604, + "start": 2568 + }, + "target": "b1", + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 2581, + "start": 2575 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 2588, + "start": 2582 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2597, + "start": 2591 + } + }, + "span": { + "end": 2597, + "start": 2582 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 2601, + "start": 2582 + } + }, + "kind": "index", + "span": { + "end": 2602, + "start": 2575 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2642, + "start": 2606 + }, + "target": "b2", + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 2619, + "start": 2613 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 2626, + "start": 2620 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2635, + "start": 2629 + } + }, + "span": { + "end": 2635, + "start": 2620 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 2639, + "start": 2620 + } + }, + "kind": "index", + "span": { + "end": 2640, + "start": 2613 + } + } + }, + { + "kind": "assign", + "span": { + "end": 2680, + "start": 2644 + }, + "target": "b3", + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 2657, + "start": 2651 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 2664, + "start": 2658 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2673, + "start": 2667 + } + }, + "span": { + "end": 2673, + "start": 2658 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "3" + }, + "span": { + "end": 2677, + "start": 2658 + } + }, + "kind": "index", + "span": { + "end": 2678, + "start": 2651 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 2798, + "start": 2744 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 2759, + "start": 2753 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2767, + "start": 2761 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_continuation" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "unary", + "op": "not", + "operand": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "args": [ + { + "name": null, + "span": { + "end": 2703, + "start": 2701 + }, + "value": { + "kind": "variable", + "name": "b1", + "span": { + "end": 2703, + "start": 2701 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "续字节", + "span": { + "end": 2700, + "start": 2691 + } + }, + "kind": "call", + "span": { + "end": 2704, + "start": 2691 + } + }, + "op": "and", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2721, + "start": 2719 + }, + "value": { + "kind": "variable", + "name": "b2", + "span": { + "end": 2721, + "start": 2719 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "续字节", + "span": { + "end": 2718, + "start": 2709 + } + }, + "kind": "call", + "span": { + "end": 2722, + "start": 2709 + } + }, + "span": { + "end": 2722, + "start": 2691 + } + }, + "op": "and", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 2739, + "start": 2737 + }, + "value": { + "kind": "variable", + "name": "b3", + "span": { + "end": 2739, + "start": 2737 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "续字节", + "span": { + "end": 2736, + "start": 2727 + } + }, + "kind": "call", + "span": { + "end": 2740, + "start": 2727 + } + }, + "span": { + "end": 2740, + "start": 2691 + } + }, + "span": { + "end": 2741, + "start": 2686 + } + }, + "condition_span": { + "end": 2742, + "start": 2682 + }, + "span": { + "end": 2742, + "start": 2682 + } + } + ], + "kind": "branch", + "span": { + "end": 2742, + "start": 2682 + } + }, + { + "kind": "assign", + "span": { + "end": 2910, + "start": 2806 + }, + "target": "码点", + "value": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 2824, + "start": 2818 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 2831, + "start": 2825 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2840, + "start": 2834 + } + }, + "span": { + "end": 2840, + "start": 2825 + } + }, + "kind": "index", + "span": { + "end": 2841, + "start": 2818 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "240" + }, + "span": { + "end": 2847, + "start": 2818 + } + }, + "op": "mul", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "262144" + }, + "span": { + "end": 2857, + "start": 2817 + } + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "b1", + "span": { + "end": 2863, + "start": 2861 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 2869, + "start": 2861 + } + }, + "op": "mul", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "4096" + }, + "span": { + "end": 2877, + "start": 2860 + } + }, + "span": { + "end": 2877, + "start": 2817 + } + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "b2", + "span": { + "end": 2883, + "start": 2881 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 2889, + "start": 2881 + } + }, + "op": "mul", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "64" + }, + "span": { + "end": 2895, + "start": 2880 + } + }, + "span": { + "end": 2895, + "start": 2817 + } + }, + "op": "add", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "b3", + "span": { + "end": 2901, + "start": 2899 + } + }, + "op": "sub", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 2907, + "start": 2899 + } + }, + "span": { + "end": 2908, + "start": 2817 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 3001, + "start": 2953 + }, + "value": { + "items": [ + { + "kind": "variable", + "name": "文本", + "span": { + "end": 2968, + "start": 2962 + } + }, + { + "kind": "variable", + "name": "偏移", + "span": { + "end": 2976, + "start": 2970 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_scalar" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 2922, + "start": 2916 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "65536" + }, + "span": { + "end": 2930, + "start": 2916 + } + }, + "op": "or", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "码点", + "span": { + "end": 2940, + "start": 2934 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1114111" + }, + "span": { + "end": 2950, + "start": 2934 + } + }, + "span": { + "end": 2950, + "start": 2916 + } + }, + "condition_span": { + "end": 2951, + "start": 2912 + }, + "span": { + "end": 2951, + "start": 2912 + } + } + ], + "kind": "branch", + "span": { + "end": 2951, + "start": 2912 + } + }, + { + "kind": "return", + "span": { + "end": 3072, + "start": 3009 + }, + "value": { + "items": [ + { + "kind": "binary", + "left": { + "kind": "variable", + "name": "文本", + "span": { + "end": 3024, + "start": 3018 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 3053, + "start": 3047 + }, + "value": { + "kind": "variable", + "name": "码点", + "span": { + "end": 3053, + "start": 3047 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 3031, + "start": 3027 + } + }, + "field": "from_codepoint", + "kind": "member", + "span": { + "end": 3046, + "start": 3027 + } + }, + "kind": "call", + "span": { + "end": 3054, + "start": 3027 + } + }, + "span": { + "end": 3054, + "start": 3018 + } + }, + { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 3062, + "start": 3056 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "4" + }, + "span": { + "end": 3066, + "start": 3056 + } + }, + { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + } + ], + "kind": "list", + "span": { + "end": 0, + "start": 0 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 2438, + "start": 2428 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码4", + "local_name": "解码4", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 2453, + "start": 2447 + }, + "type": null + }, + { + "default": null, + "name": "基址", + "required": true, + "span": { + "end": 2461, + "start": 2454 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 2469, + "start": 2462 + }, + "type": null + }, + { + "default": null, + "name": "偏移", + "required": true, + "span": { + "end": 2477, + "start": 2470 + }, + "type": null + }, + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 2485, + "start": 2478 + }, + "type": null + } + ] + }, + "span": { + "end": 3072, + "start": 2428 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码4" + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3133, + "start": 3119 + }, + "target": "偏移", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + }, + { + "kind": "assign", + "span": { + "end": 3150, + "start": 3135 + }, + "target": "文本", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + } + }, + { + "kind": "assign", + "span": { + "end": 3167, + "start": 3152 + }, + "target": "错误", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + } + }, + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3244, + "start": 3211 + }, + "target": "首", + "value": { + "base": { + "kind": "variable", + "name": "内存", + "span": { + "end": 3225, + "start": 3219 + } + }, + "index": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "基址", + "span": { + "end": 3232, + "start": 3226 + } + }, + "op": "add", + "right": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 3241, + "start": 3235 + } + }, + "span": { + "end": 3241, + "start": 3226 + } + }, + "kind": "index", + "span": { + "end": 3242, + "start": 3219 + } + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3308, + "start": 3262 + }, + "target": "文本", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "文本", + "span": { + "end": 3279, + "start": 3273 + } + }, + "op": "add", + "right": { + "args": [ + { + "name": null, + "span": { + "end": 3305, + "start": 3302 + }, + "value": { + "kind": "variable", + "name": "首", + "span": { + "end": 3305, + "start": 3302 + } + } + } + ], + "callee": { + "base": { + "kind": "variable", + "name": "text", + "span": { + "end": 3286, + "start": 3282 + } + }, + "field": "from_codepoint", + "kind": "member", + "span": { + "end": 3301, + "start": 3282 + } + }, + "kind": "call", + "span": { + "end": 3306, + "start": 3282 + } + }, + "span": { + "end": 3306, + "start": 3273 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3333, + "start": 3310 + }, + "target": "偏移", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 3327, + "start": 3321 + } + }, + "op": "add", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "span": { + "end": 3331, + "start": 3321 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "首", + "span": { + "end": 3253, + "start": 3250 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "128" + }, + "span": { + "end": 3259, + "start": 3250 + } + }, + "condition_span": { + "end": 3260, + "start": 3246 + }, + "span": { + "end": 3260, + "start": 3246 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3390, + "start": 3358 + }, + "target": "错误", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_lead" + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "首", + "span": { + "end": 3349, + "start": 3346 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "194" + }, + "span": { + "end": 3355, + "start": 3346 + } + }, + "condition_span": { + "end": 3356, + "start": 3342 + }, + "span": { + "end": 3356, + "start": 3342 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3475, + "start": 3415 + }, + "target": "结果", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3440, + "start": 3434 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 3440, + "start": 3434 + } + } + }, + { + "name": null, + "span": { + "end": 3448, + "start": 3442 + }, + "value": { + "kind": "variable", + "name": "基址", + "span": { + "end": 3448, + "start": 3442 + } + } + }, + { + "name": null, + "span": { + "end": 3456, + "start": 3450 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 3456, + "start": 3450 + } + } + }, + { + "name": null, + "span": { + "end": 3464, + "start": 3458 + }, + "value": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 3464, + "start": 3458 + } + } + }, + { + "name": null, + "span": { + "end": 3472, + "start": 3466 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 3472, + "start": 3466 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "解码2", + "span": { + "end": 3433, + "start": 3426 + } + }, + "kind": "call", + "span": { + "end": 3473, + "start": 3426 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3499, + "start": 3477 + }, + "target": "文本", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3494, + "start": 3488 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "kind": "index", + "span": { + "end": 3497, + "start": 3488 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3523, + "start": 3501 + }, + "target": "偏移", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3518, + "start": 3512 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "kind": "index", + "span": { + "end": 3521, + "start": 3512 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3547, + "start": 3525 + }, + "target": "错误", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3542, + "start": 3536 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "kind": "index", + "span": { + "end": 3545, + "start": 3536 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "首", + "span": { + "end": 3406, + "start": 3403 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "224" + }, + "span": { + "end": 3412, + "start": 3403 + } + }, + "condition_span": { + "end": 3413, + "start": 3399 + }, + "span": { + "end": 3413, + "start": 3399 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3632, + "start": 3572 + }, + "target": "结果", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3597, + "start": 3591 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 3597, + "start": 3591 + } + } + }, + { + "name": null, + "span": { + "end": 3605, + "start": 3599 + }, + "value": { + "kind": "variable", + "name": "基址", + "span": { + "end": 3605, + "start": 3599 + } + } + }, + { + "name": null, + "span": { + "end": 3613, + "start": 3607 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 3613, + "start": 3607 + } + } + }, + { + "name": null, + "span": { + "end": 3621, + "start": 3615 + }, + "value": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 3621, + "start": 3615 + } + } + }, + { + "name": null, + "span": { + "end": 3629, + "start": 3623 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 3629, + "start": 3623 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "解码3", + "span": { + "end": 3590, + "start": 3583 + } + }, + "kind": "call", + "span": { + "end": 3630, + "start": 3583 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3656, + "start": 3634 + }, + "target": "文本", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3651, + "start": 3645 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "kind": "index", + "span": { + "end": 3654, + "start": 3645 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3680, + "start": 3658 + }, + "target": "偏移", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3675, + "start": 3669 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "kind": "index", + "span": { + "end": 3678, + "start": 3669 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3704, + "start": 3682 + }, + "target": "错误", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3699, + "start": 3693 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "kind": "index", + "span": { + "end": 3702, + "start": 3693 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "首", + "span": { + "end": 3563, + "start": 3560 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "240" + }, + "span": { + "end": 3569, + "start": 3560 + } + }, + "condition_span": { + "end": 3570, + "start": 3556 + }, + "span": { + "end": 3570, + "start": 3556 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3789, + "start": 3729 + }, + "target": "结果", + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3754, + "start": 3748 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 3754, + "start": 3748 + } + } + }, + { + "name": null, + "span": { + "end": 3762, + "start": 3756 + }, + "value": { + "kind": "variable", + "name": "基址", + "span": { + "end": 3762, + "start": 3756 + } + } + }, + { + "name": null, + "span": { + "end": 3770, + "start": 3764 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 3770, + "start": 3764 + } + } + }, + { + "name": null, + "span": { + "end": 3778, + "start": 3772 + }, + "value": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 3778, + "start": 3772 + } + } + }, + { + "name": null, + "span": { + "end": 3786, + "start": 3780 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 3786, + "start": 3780 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "解码4", + "span": { + "end": 3747, + "start": 3740 + } + }, + "kind": "call", + "span": { + "end": 3787, + "start": 3740 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3813, + "start": 3791 + }, + "target": "文本", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3808, + "start": 3802 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "kind": "index", + "span": { + "end": 3811, + "start": 3802 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3837, + "start": 3815 + }, + "target": "偏移", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3832, + "start": 3826 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "1" + }, + "kind": "index", + "span": { + "end": 3835, + "start": 3826 + } + } + }, + { + "kind": "assign", + "span": { + "end": 3861, + "start": 3839 + }, + "target": "错误", + "value": { + "base": { + "kind": "variable", + "name": "结果", + "span": { + "end": 3856, + "start": 3850 + } + }, + "index": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "kind": "index", + "span": { + "end": 3859, + "start": 3850 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "首", + "span": { + "end": 3720, + "start": 3717 + } + }, + "op": "lt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "245" + }, + "span": { + "end": 3726, + "start": 3717 + } + }, + "condition_span": { + "end": 3727, + "start": 3713 + }, + "span": { + "end": 3727, + "start": 3713 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 3913, + "start": 3881 + }, + "target": "错误", + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "utf8.invalid_lead" + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3879, + "start": 3870 + }, + "span": { + "end": 3879, + "start": 3870 + } + } + ], + "kind": "branch", + "span": { + "end": 3879, + "start": 3870 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3727, + "start": 3713 + }, + "span": { + "end": 3727, + "start": 3713 + } + } + ], + "kind": "branch", + "span": { + "end": 3727, + "start": 3713 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3570, + "start": 3556 + }, + "span": { + "end": 3570, + "start": 3556 + } + } + ], + "kind": "branch", + "span": { + "end": 3570, + "start": 3556 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3413, + "start": 3399 + }, + "span": { + "end": 3413, + "start": 3399 + } + } + ], + "kind": "branch", + "span": { + "end": 3413, + "start": 3399 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3356, + "start": 3342 + }, + "span": { + "end": 3356, + "start": 3342 + } + } + ], + "kind": "branch", + "span": { + "end": 3356, + "start": 3342 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3260, + "start": 3246 + }, + "span": { + "end": 3260, + "start": 3246 + } + } + ], + "kind": "branch", + "span": { + "end": 3260, + "start": 3246 + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "偏移", + "span": { + "end": 3182, + "start": 3176 + } + }, + "op": "lt", + "right": { + "kind": "variable", + "name": "长度", + "span": { + "end": 3191, + "start": 3185 + } + }, + "span": { + "end": 3191, + "start": 3176 + } + }, + "op": "and", + "right": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "错误", + "span": { + "end": 3202, + "start": 3196 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + }, + "span": { + "end": 3208, + "start": 3196 + } + }, + "span": { + "end": 3208, + "start": 3176 + } + }, + "condition_span": { + "end": 3209, + "start": 3169 + }, + "kind": "loop", + "span": { + "end": 3209, + "start": 3169 + } + }, + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 3999, + "start": 3976 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 3997, + "start": 3991 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 3997, + "start": 3991 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "成功", + "span": { + "end": 3990, + "start": 3984 + } + }, + "kind": "call", + "span": { + "end": 3998, + "start": 3984 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "错误", + "span": { + "end": 3967, + "start": 3961 + } + }, + "op": "eq", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "" + }, + "span": { + "end": 3973, + "start": 3961 + } + }, + "condition_span": { + "end": 3974, + "start": 3957 + }, + "span": { + "end": 3974, + "start": 3957 + } + }, + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "return", + "span": { + "end": 4064, + "start": 4019 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 4040, + "start": 4034 + }, + "value": { + "kind": "variable", + "name": "错误", + "span": { + "end": 4040, + "start": 4034 + } + } + }, + { + "name": null, + "span": { + "end": 4062, + "start": 4042 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "text", + "value": "UTF-8 解码失败" + } + } + ], + "callee": { + "kind": "variable", + "name": "失败", + "span": { + "end": 4033, + "start": 4027 + } + }, + "kind": "call", + "span": { + "end": 4063, + "start": 4027 + } + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 4017, + "start": 4008 + }, + "span": { + "end": 4017, + "start": 4008 + } + } + ], + "kind": "branch", + "span": { + "end": 4017, + "start": 4008 + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 3974, + "start": 3957 + }, + "span": { + "end": 3974, + "start": 3957 + } + } + ], + "kind": "branch", + "span": { + "end": 3974, + "start": 3957 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 3083, + "start": 3074 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "local_name": "解码", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 3098, + "start": 3092 + }, + "type": null + }, + { + "default": null, + "name": "基址", + "required": true, + "span": { + "end": 3106, + "start": 3099 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 3114, + "start": 3107 + }, + "type": null + } + ] + }, + "span": { + "end": 4077, + "start": 3074 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 4166, + "start": 4127 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 4148, + "start": 4142 + }, + "value": { + "kind": "variable", + "name": "文本", + "span": { + "end": 4148, + "start": 4142 + } + } + }, + { + "name": null, + "span": { + "end": 4156, + "start": 4150 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 4156, + "start": 4150 + } + } + }, + { + "name": null, + "span": { + "end": 4164, + "start": 4158 + }, + "value": { + "kind": "variable", + "name": "基址", + "span": { + "end": 4164, + "start": 4158 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "编码", + "span": { + "end": 4141, + "start": 4135 + } + }, + "kind": "call", + "span": { + "end": 4165, + "start": 4135 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 4091, + "start": 4078 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.utf8编码", + "local_name": "utf8编码", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "文本", + "required": true, + "span": { + "end": 4106, + "start": 4100 + }, + "type": null + }, + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 4114, + "start": 4107 + }, + "type": null + }, + { + "default": null, + "name": "基址", + "required": true, + "span": { + "end": 4122, + "start": 4115 + }, + "type": null + } + ] + }, + "span": { + "end": 4166, + "start": 4078 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/utf8编码" + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 4256, + "start": 4217 + }, + "value": { + "args": [ + { + "name": null, + "span": { + "end": 4238, + "start": 4232 + }, + "value": { + "kind": "variable", + "name": "内存", + "span": { + "end": 4238, + "start": 4232 + } + } + }, + { + "name": null, + "span": { + "end": 4246, + "start": 4240 + }, + "value": { + "kind": "variable", + "name": "基址", + "span": { + "end": 4246, + "start": 4240 + } + } + }, + { + "name": null, + "span": { + "end": 4254, + "start": 4248 + }, + "value": { + "kind": "variable", + "name": "长度", + "span": { + "end": 4254, + "start": 4248 + } + } + } + ], + "callee": { + "kind": "variable", + "name": "解码", + "span": { + "end": 4231, + "start": 4225 + } + }, + "kind": "call", + "span": { + "end": 4255, + "start": 4225 + } + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 4181, + "start": 4168 + }, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.utf8解码", + "local_name": "utf8解码", + "namespace": "utf8", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "内存", + "required": true, + "span": { + "end": 4196, + "start": 4190 + }, + "type": null + }, + { + "default": null, + "name": "基址", + "required": true, + "span": { + "end": 4204, + "start": 4197 + }, + "type": null + }, + { + "default": null, + "name": "长度", + "required": true, + "span": { + "end": 4212, + "start": 4205 + }, + "type": null + } + ] + }, + "span": { + "end": 4256, + "start": 4168 + }, + "unit_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/utf8解码" + } + ], + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md", + "imports": [], + "package_instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "references": [], + "relative_path": "text/utf8.mq.md", + "resources": [], + "source_digest": "14a476a1ad41fa28b5c16b24f4cf2517da554edeb5677220e387d35d7e24ada6", + "units": [ + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 4256, + "start": 0 + } + }, + { + "function": null, + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8", + "kind": "namespace", + "level": 1, + "name": "utf8", + "span": { + "end": 13, + "start": 1 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.成功", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/成功", + "kind": "function", + "level": 2, + "name": "成功", + "span": { + "end": 23, + "start": 14 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.失败", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/失败", + "kind": "function", + "level": 2, + "name": "失败", + "span": { + "end": 82, + "start": 73 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.续字节", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/续字节", + "kind": "function", + "level": 2, + "name": "续字节", + "span": { + "end": 175, + "start": 163 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.编码", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/编码", + "kind": "function", + "level": 2, + "name": "编码", + "span": { + "end": 245, + "start": 236 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码2", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码2", + "kind": "function", + "level": 2, + "name": "解码2", + "span": { + "end": 1382, + "start": 1372 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码3", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码3", + "kind": "function", + "level": 2, + "name": "解码3", + "span": { + "end": 1850, + "start": 1840 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码4", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码4", + "kind": "function", + "level": 2, + "name": "解码4", + "span": { + "end": 2438, + "start": 2428 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.解码", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/解码", + "kind": "function", + "level": 2, + "name": "解码", + "span": { + "end": 3083, + "start": 3074 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.utf8编码", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/utf8编码", + "kind": "function", + "level": 2, + "name": "utf8编码", + "span": { + "end": 4091, + "start": 4078 + } + }, + { + "function": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md::utf8.utf8解码", + "id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713::text/utf8.mq.md#utf8/utf8解码", + "kind": "function", + "level": 2, + "name": "utf8解码", + "span": { + "end": 4181, + "start": 4168 + } + } + ] + } + ], + "producer": { + "markdown_profile": "marqdo.md.v1", + "name": "marqdo", + "version": "3.0.0-beta.1" + }, + "project": { + "identity_kind": "manifest", + "lock_digest": "", + "root_id": "root:control-flow@0.1.0", + "stdlib": { + "digest": "sha256:5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "version": "0.1.0" + } + }, + "schema": "marqdo.analysis", + "schema_version": 2 +} \ No newline at end of file diff --git a/tests/golden/analysis-v2/mixed-modes.json b/tests/golden/analysis-v2/mixed-modes.json new file mode 100644 index 0000000..2c51f11 --- /dev/null +++ b/tests/golden/analysis-v2/mixed-modes.json @@ -0,0 +1,278 @@ +{ + "diagnostics": [], + "modules": [ + { + "calls": [], + "functions": [ + { + "body": [ + { + "arms": [ + { + "body": [ + { + "kind": "assign", + "span": { + "end": 422, + "start": 406 + }, + "target": "result", + "value": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "n", + "span": { + "end": 417, + "start": 416 + } + }, + "op": "mul", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "2" + }, + "span": { + "end": 421, + "start": 416 + } + } + }, + { + "kind": "return", + "span": { + "end": 439, + "start": 424 + }, + "value": { + "kind": "variable", + "name": "result", + "span": { + "end": 438, + "start": 432 + } + } + } + ], + "condition": { + "kind": "binary", + "left": { + "kind": "variable", + "name": "n", + "span": { + "end": 398, + "start": 397 + } + }, + "op": "gt", + "right": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + }, + "span": { + "end": 402, + "start": 397 + } + }, + "condition_span": { + "end": 404, + "start": 392 + }, + "span": { + "end": 404, + "start": 392 + } + }, + { + "body": [ + { + "kind": "return", + "span": { + "end": 461, + "start": 451 + }, + "value": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "int", + "value": "0" + } + } + ], + "condition": { + "kind": "literal", + "span": { + "end": 0, + "start": 0 + }, + "type": "bool", + "value": true + }, + "condition_span": { + "end": 404, + "start": 392 + }, + "span": { + "end": 404, + "start": 392 + } + } + ], + "kind": "branch", + "span": { + "end": 404, + "start": 392 + } + } + ], + "effects": [ + "unknown" + ], + "heading_span": { + "end": 259, + "start": 246 + }, + "id": "root:mixed-modes@0.1.0::index.mq.md::演示.main", + "local_name": "main", + "namespace": "演示", + "signature": { + "kind": "explicit", + "params": [ + { + "default": null, + "name": "n", + "required": true, + "span": { + "end": 274, + "start": 268 + }, + "type": "Int" + } + ] + }, + "span": { + "end": 470, + "start": 246 + }, + "unit_id": "root:mixed-modes@0.1.0::index.mq.md#演示/main" + } + ], + "id": "root:mixed-modes@0.1.0::index.mq.md", + "imports": [], + "package_instance_id": "root:mixed-modes@0.1.0", + "references": [], + "relative_path": "index.mq.md", + "resources": [], + "source_digest": "c5fed57a716e06a29b669c334d475ec03bf08442e27983451ec8dd791dc999ea", + "units": [ + { + "function": null, + "id": "root:mixed-modes@0.1.0::index.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 470, + "start": 0 + } + }, + { + "function": null, + "id": "root:mixed-modes@0.1.0::index.mq.md#计算笔记", + "kind": "namespace", + "level": 1, + "name": "计算笔记", + "span": { + "end": 25, + "start": 0 + } + }, + { + "function": null, + "id": "root:mixed-modes@0.1.0::index.mq.md#计算笔记/算法说明", + "kind": "knowledge", + "level": 2, + "name": "算法说明", + "span": { + "end": 149, + "start": 123 + } + }, + { + "function": null, + "id": "root:mixed-modes@0.1.0::index.mq.md#演示", + "kind": "namespace", + "level": 1, + "name": "演示", + "span": { + "end": 244, + "start": 230 + } + }, + { + "function": "root:mixed-modes@0.1.0::index.mq.md::演示.main", + "id": "root:mixed-modes@0.1.0::index.mq.md#演示/main", + "kind": "function", + "level": 2, + "name": "main", + "span": { + "end": 259, + "start": 246 + } + }, + { + "function": null, + "id": "root:mixed-modes@0.1.0::index.mq.md#演示/main/用法", + "kind": "section", + "level": 3, + "name": "用法", + "span": { + "end": 300, + "start": 279 + } + }, + { + "function": "root:mixed-modes@0.1.0::index.mq.md::演示.main", + "id": "root:mixed-modes@0.1.0::index.mq.md#演示/main/计算", + "kind": "section", + "level": 3, + "name": "计算", + "span": { + "end": 390, + "start": 374 + } + } + ] + } + ], + "producer": { + "markdown_profile": "marqdo.md.v1", + "name": "marqdo", + "version": "3.0.0-beta.1" + }, + "project": { + "identity_kind": "manifest", + "lock_digest": "", + "root_id": "root:mixed-modes@0.1.0", + "stdlib": { + "digest": "sha256:5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "version": "0.1.0" + } + }, + "schema": "marqdo.analysis", + "schema_version": 2 +} \ No newline at end of file diff --git a/tests/golden/analysis-v2/tables-math.json b/tests/golden/analysis-v2/tables-math.json new file mode 100644 index 0000000..3c18784 --- /dev/null +++ b/tests/golden/analysis-v2/tables-math.json @@ -0,0 +1,108 @@ +{ + "diagnostics": [], + "modules": [ + { + "calls": [], + "functions": [], + "id": "root:tables-math@0.1.0::index.mq.md", + "imports": [], + "package_instance_id": "root:tables-math@0.1.0", + "references": [ + { + "source": "root:tables-math@0.1.0::index.mq.md", + "span": { + "end": 403, + "start": 354 + }, + "state": "external", + "target_module": null, + "target_unit": null, + "url": "https://github.com/cflmy/marqdo-cli" + } + ], + "relative_path": "index.mq.md", + "resources": [ + { + "content_digest": "2820951a377c18ce3e89093ca7c31c204b1196a7e571781c6080f8207524a8dc", + "display": false, + "id": "root:tables-math@0.1.0::index.mq.md#resource:formula-1", + "kind": "formula", + "language": null, + "module_id": "root:tables-math@0.1.0::index.mq.md", + "span": { + "end": 164, + "start": 154 + }, + "unit_id": "root:tables-math@0.1.0::index.mq.md#表格、公式与惰性资源" + }, + { + "content_digest": "8b1e8a7ed159e8223af79e768681907870ae7143f0b16001091377f9ff018db2", + "display": true, + "id": "root:tables-math@0.1.0::index.mq.md#resource:formula-2", + "kind": "formula", + "language": null, + "module_id": "root:tables-math@0.1.0::index.mq.md", + "span": { + "end": 222, + "start": 181 + }, + "unit_id": "root:tables-math@0.1.0::index.mq.md#表格、公式与惰性资源" + }, + { + "content_digest": "a0d49e456637468d7f594f4e2bb513321875855c1fe85d28e0ca62f1e9180d15", + "id": "root:tables-math@0.1.0::index.mq.md#resource:code-1", + "kind": "code", + "language": "python", + "module_id": "root:tables-math@0.1.0::index.mq.md", + "span": { + "end": 280, + "start": 224 + }, + "unit_id": "root:tables-math@0.1.0::index.mq.md#表格、公式与惰性资源" + } + ], + "source_digest": "66ce180252d201ff0f3f831d47f7a58d7f6804cb9655898cc80ef6d2262f1ce6", + "units": [ + { + "function": null, + "id": "root:tables-math@0.1.0::index.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 406, + "start": 0 + } + }, + { + "function": null, + "id": "root:tables-math@0.1.0::index.mq.md#表格、公式与惰性资源", + "kind": "namespace", + "level": 1, + "name": "表格、公式与惰性资源", + "span": { + "end": 43, + "start": 0 + } + } + ] + } + ], + "producer": { + "markdown_profile": "marqdo.md.v1", + "name": "marqdo", + "version": "3.0.0-beta.1" + }, + "project": { + "identity_kind": "manifest", + "lock_digest": "", + "root_id": "root:tables-math@0.1.0", + "stdlib": { + "digest": "sha256:5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "version": "0.1.0" + } + }, + "schema": "marqdo.analysis", + "schema_version": 2 +} \ No newline at end of file diff --git a/tests/golden/analysis-v2/welcome.json b/tests/golden/analysis-v2/welcome.json new file mode 100644 index 0000000..9ac3912 --- /dev/null +++ b/tests/golden/analysis-v2/welcome.json @@ -0,0 +1,69 @@ +{ + "diagnostics": [], + "modules": [ + { + "calls": [], + "functions": [], + "id": "root:welcome-demo@0.1.0::00-welcome.mq.md", + "imports": [], + "package_instance_id": "root:welcome-demo@0.1.0", + "references": [ + { + "source": "root:welcome-demo@0.1.0::00-welcome.mq.md", + "span": { + "end": 536, + "start": 507 + }, + "state": "resolved", + "target_module": "root:welcome-demo@0.1.0::guide.mq.md", + "target_unit": null, + "url": "./guide.mq.md" + } + ], + "relative_path": "00-welcome.mq.md", + "resources": [], + "source_digest": "879215bf0dc432b78924800a08eac37d353a9694652c5542294f4ce7fe6da173", + "units": [ + { + "function": null, + "id": "root:welcome-demo@0.1.0::00-welcome.mq.md#", + "kind": "root", + "level": 0, + "name": "", + "span": { + "end": 659, + "start": 0 + } + }, + { + "function": null, + "id": "root:welcome-demo@0.1.0::00-welcome.mq.md#欢迎来到 Marqdo", + "kind": "namespace", + "level": 1, + "name": "欢迎来到 Marqdo", + "span": { + "end": 32, + "start": 0 + } + } + ] + } + ], + "producer": { + "markdown_profile": "marqdo.md.v1", + "name": "marqdo", + "version": "3.0.0-beta.1" + }, + "project": { + "identity_kind": "manifest", + "lock_digest": "", + "root_id": "root:welcome-demo@0.1.0", + "stdlib": { + "digest": "sha256:5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "instance_id": "std:marqdo-stdlib@0.1.0#5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713", + "version": "0.1.0" + } + }, + "schema": "marqdo.analysis", + "schema_version": 2 +} \ No newline at end of file diff --git a/tests/http_live.rs b/tests/http_live.rs new file mode 100644 index 0000000..3945e20 --- /dev/null +++ b/tests/http_live.rs @@ -0,0 +1,230 @@ +//! Live server smoke tests over a raw TCP HTTP/1.1 client (no extra deps). +//! The server is a real child process so startup, URL output, routing and +//! security headers are all exercised end to end. + +mod common; + +use common::{run_view, FakeCore}; +use std::io::{BufRead, BufReader, Read, Write}; +use std::net::TcpStream; +use std::process::{Child, Command, Stdio}; +use std::time::{Duration, Instant}; + +struct LiveServer { + child: Child, + port: u16, + _core: FakeCore, +} + +impl Drop for LiveServer { + fn drop(&mut self) { + let _ = self.child.kill(); + let _ = self.child.wait(); + } +} + +fn start_server() -> LiveServer { + use std::sync::atomic::{AtomicUsize, Ordering}; + static NEXT: AtomicUsize = AtomicUsize::new(0); + let seq = NEXT.fetch_add(1, Ordering::Relaxed); + let repo_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let core = FakeCore::new(&format!("live-core-{seq}")); + let golden = std::fs::read(repo_root.join("tests/golden/analysis-v2/welcome.json")).unwrap(); + core.set_analysis(std::str::from_utf8(&golden).unwrap()); + + let mut child = Command::new(common::view_bin()) + .current_dir(&repo_root) + .args([ + "examples/welcome", + "--port", + "0", + "--no-open", + "--marqdo-bin", + ]) + .arg(&core.script) + .env_remove("MARQDO_BIN") + .env_remove("MARQDO_TOOL_PROTOCOL") + .env_remove("MARQDO_PROTOCOL_ANALYSIS") + .env_remove("MARQDO_PROTOCOL_TRACE") + .stdout(Stdio::null()) + .stderr(Stdio::piped()) + .spawn() + .expect("spawn marqdo-view"); + + let stderr = child.stderr.take().expect("piped stderr"); + let mut reader = BufReader::new(stderr); + let deadline = Instant::now() + Duration::from_secs(10); + let mut url: Option = None; + while Instant::now() < deadline { + let mut line = String::new(); + if reader.read_line(&mut line).unwrap_or(0) == 0 { + break; + } + if let Some(rest) = line.trim().strip_prefix("marqdo view: ") { + url = Some(rest.to_string()); + break; + } + } + let url = url.expect("server printed its URL"); + let port: u16 = url + .trim_end_matches('/') + .rsplit(':') + .next() + .expect("port in url") + .parse() + .expect("numeric port"); + // Keep draining stderr so the child never blocks on a full pipe. + std::thread::spawn(move || { + let mut sink = String::new(); + let _ = reader.read_to_string(&mut sink); + }); + + LiveServer { + child, + port, + _core: core, + } +} + +struct HttpResponse { + status: u16, + headers: String, + body: String, +} + +fn http_get(port: u16, host: Option<&str>, path: &str) -> HttpResponse { + let mut stream = TcpStream::connect(("127.0.0.1", port)).expect("connect"); + let host = host + .map(str::to_string) + .unwrap_or_else(|| format!("127.0.0.1:{port}")); + let request = + format!("GET {path} HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\nAccept: */*\r\n\r\n"); + stream.write_all(request.as_bytes()).expect("write request"); + let mut raw = Vec::new(); + stream.read_to_end(&mut raw).expect("read response"); + let text = String::from_utf8_lossy(&raw).to_string(); + let (head, body) = text.split_once("\r\n\r\n").unwrap_or((&text, "")); + let status = head + .lines() + .next() + .and_then(|line| line.split_whitespace().nth(1)) + .and_then(|code| code.parse().ok()) + .unwrap_or(0); + HttpResponse { + status, + headers: head.to_string(), + body: body.to_string(), + } +} + +#[test] +fn live_server_serves_pages_assets_and_health() { + let server = start_server(); + let page = http_get(server.port, None, "/"); + assert_eq!(page.status, 200); + assert!(page.headers.contains("Content-Type: text/html")); + assert!(page.headers.contains("Content-Security-Policy")); + assert!(page.headers.contains("X-Content-Type-Options: nosniff")); + assert!(page.body.contains("mq-reader")); + assert!(page.body.contains("欢迎来到 Marqdo")); + assert!(!page.body.contains("data-live=\"false\"")); + // CSRF token meta is present for the future explicit-run API. + assert!(page.body.contains("mq-csrf-token")); + + let css_path = page + .body + .split("href=\"/assets/") + .nth(1) + .and_then(|rest| rest.split('"').next()) + .expect("css link"); + let css = http_get(server.port, None, &format!("/assets/{css_path}")); + assert_eq!(css.status, 200); + assert!(css.headers.contains("text/css")); + assert!(css.body.contains("@layer tokens")); + assert!(css.headers.contains("immutable")); + + let health = http_get(server.port, None, "/api/health"); + assert_eq!(health.status, 200); + assert!(health.body.contains("\"schema\": \"marqdo.view-health\"")); + assert!(health.body.contains("\"analysis\": 2")); + + let document = http_get(server.port, None, "/file?path=guide.mq.md"); + assert_eq!(document.status, 200); + assert!(document.body.contains("阅读指南")); +} + +#[test] +fn live_server_rejects_dns_rebinding_and_path_escape() { + let server = start_server(); + let bad_host = http_get(server.port, Some("attacker.example"), "/"); + assert_eq!(bad_host.status, 400); + + for path in [ + "/file?path=../secret.mq.md", + "/file?path=%2e%2e%2fsecret.mq.md", + "/file?path=/etc/passwd", + "/file?path=..%2f..%2fetc%2fpasswd", + ] { + let response = http_get(server.port, None, path); + assert!( + response.status == 403 || response.status == 404, + "path {path} returned {}", + response.status + ); + } + + let missing = http_get(server.port, None, "/file?path=missing.mq.md"); + assert_eq!(missing.status, 404); + + let unknown = http_get(server.port, None, "/api/run"); + assert_eq!(unknown.status, 404); +} + +#[test] +fn live_server_rejects_unknown_methods_and_bad_assets() { + let server = start_server(); + // POST is not exposed yet. + let mut stream = TcpStream::connect(("127.0.0.1", server.port)).expect("connect"); + let request = format!( + "POST /api/run HTTP/1.1\r\nHost: 127.0.0.1:{}\r\nContent-Type: application/json\r\nContent-Length: 2\r\nConnection: close\r\n\r\n{{}}", + server.port + ); + stream.write_all(request.as_bytes()).unwrap(); + let mut raw = Vec::new(); + stream.read_to_end(&mut raw).unwrap(); + let text = String::from_utf8_lossy(&raw); + assert!(text.starts_with("HTTP/1.1 405"), "{text}"); + + let bad_asset = http_get(server.port, None, "/assets/../../etc/passwd"); + assert_eq!(bad_asset.status, 404); +} + +#[test] +fn cli_verify_output_contract_still_holds_for_installed_style_invocation() { + // Regression guard: `view verify` must remain a pure static check. + let repo_root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let core = FakeCore::new("verify-core-contract"); + let golden = std::fs::read(repo_root.join("tests/golden/analysis-v2/welcome.json")).unwrap(); + core.set_analysis(std::str::from_utf8(&golden).unwrap()); + let output = run_view( + &[ + "verify", + "examples/welcome/00-welcome.mq.md", + "--json", + "--marqdo-bin", + core.script.to_str().unwrap(), + ], + &repo_root, + &[("MARQDO_BIN", None)], + ); + assert_eq!( + output.status.code(), + Some(0), + "stderr: {}", + String::from_utf8_lossy(&output.stderr) + ); + let json: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output"); + assert_eq!(json["result"], "PASS"); + assert_eq!(json["executed"], false); + assert_eq!(json["analysis"]["schema_version"], 2); +} diff --git a/tests/no_coupling.rs b/tests/no_coupling.rs index 72bd93d..76e9833 100644 --- a/tests/no_coupling.rs +++ b/tests/no_coupling.rs @@ -135,8 +135,8 @@ fn exactly_one_reader_theme_and_script_entry() { let mut js = Vec::new(); collect_files(&assets, "css", &mut css); collect_files(&assets, "js", &mut js); - assert!(css.len() <= 1, "more than one CSS entry: {css:?}"); - assert!(js.len() <= 1, "more than one JS entry: {js:?}"); + assert_eq!(css.len(), 1, "exactly one CSS entry: {css:?}"); + assert_eq!(js.len(), 1, "exactly one JS entry: {js:?}"); for path in &css { assert_eq!( path.file_name().and_then(|n| n.to_str()), diff --git a/tests/rendering.rs b/tests/rendering.rs new file mode 100644 index 0000000..aa8d8d3 --- /dev/null +++ b/tests/rendering.rs @@ -0,0 +1,250 @@ +//! Rendering contract tests: one renderer, safe Markdown, exact source view, +//! verified semantic annotations and Live/Export link differences. + +mod common; + +use marqdo_view::document::{DocumentIdentity, DocumentModel}; +use marqdo_view::presentation::{self, BuildInput, Navigation, SourceStatus}; +use marqdo_view::project::{Project, SafeRelativePath, ViewConfig}; +use marqdo_view::render::{ReaderRenderer, RenderContext}; +use marqdo_view::semantic; + +fn example(name: &str) -> (marqdo_view::presentation::PresentationModel, String) { + let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("examples") + .join(name); + let project = Project::open(&root).unwrap(); + let entry = project.entry().relative.clone(); + let source = project.read_source_text(&entry).unwrap(); + let document = DocumentModel::parse(source.clone(), DocumentIdentity::placeholder(&entry)); + let golden_name = name; + let golden = std::fs::read( + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("tests/golden/analysis-v2") + .join(format!("{golden_name}.json")), + ) + .unwrap_or_else(|err| panic!("missing golden for {name}: {err}")); + let verified = + semantic::verify_analysis(&golden, &source, &document.source_index, entry.as_str()) + .unwrap_or_else(|err| panic!("golden does not verify for {name}: {err}")); + let config = ViewConfig::load(project.root()).unwrap_or_default(); + let navigation = Navigation::from_project(&project, &config, &entry); + let model = presentation::build(BuildInput { + document, + analysis: Some(&verified), + status: SourceStatus::StaticOk, + status_note: None, + diagnostics: Vec::new(), + navigation, + core_version: Some("3.0.0-beta.1".to_string()), + }); + (model, source) +} + +fn render_live(model: &marqdo_view::presentation::PresentationModel) -> String { + ReaderRenderer::new() + .render(model, &RenderContext::live()) + .html +} + +fn render_static(model: &marqdo_view::presentation::PresentationModel, depth: usize) -> String { + ReaderRenderer::new() + .render(model, &RenderContext::static_site(depth)) + .html +} + +fn heading_ids(html: &str) -> Vec { + let mut ids = Vec::new(); + for part in html.split("")); + assert!(html.contains("mq-table-wrap")); + assert!(html.contains("mq-math-block")); + assert!(html.contains("代码围栏永远是惰性资源")); + assert!(html.contains("mq-codeblock")); + // Inert resources are never executed: no run controls are enabled. + assert!(html.contains("data-live=\"true\"")); + assert!(!html.contains("RUNNING")); + // Source is preserved exactly in the textarea (escaped only). + assert!(source.contains("```python")); + assert!(html.contains("mq-raw-source")); +} + +#[test] +fn welcome_hero_only_when_configured() { + let (welcome, _) = example("welcome"); + let html = render_live(&welcome); + assert!(welcome.navigation.welcome); + assert!(html.contains("mq-welcome")); + assert!(html.contains("WELCOME TO")); + assert!(html.contains("代码即文档 · 文档即知识库 · 知识即可执行")); + + let (ordinary, _) = example("tables-math"); + let html = render_live(&ordinary); + assert!(!ordinary.navigation.welcome); + assert!(!html.contains("mq-welcome")); +} + +#[test] +fn live_and_static_share_content_but_rewrite_links() { + let (model, _) = example("welcome"); + let live = render_live(&model); + let static_site = render_static(&model, 0); + assert!(live.contains("/file?path=guide.mq.md")); + assert!(static_site.contains("pages/guide.mq.md.html")); + assert!(!static_site.contains("/file?path=")); + // Same prose and semantics. + for needle in ["欢迎来到 Marqdo", "代码即文档", "mq-document"] { + assert!(live.contains(needle)); + assert!(static_site.contains(needle)); + } + // Assets are relative from the site root. + assert!(static_site.contains("href=\"assets/reader.")); + assert!(live.contains("href=\"/assets/reader.")); +} + +#[test] +fn static_pages_use_parent_relative_assets_and_links() { + let (model, _) = example("welcome"); + let html = render_static(&model, 1); + assert!(html.contains("href=\"../assets/reader.")); + assert!(html.contains("../pages/guide.mq.md.html")); +} + +#[test] +fn malicious_markdown_cannot_inject_markup_or_scripts() { + let source = r#"# 安全测试 + + + + + +[危险链接](javascript:alert(1)) + +[数据链接](data:text/html;base64,PHNjcmlwdD4=) + +[正常链接](https://example.com/ok) + + + +正常 **正文** 与 `代码`。 +"# + .to_string(); + let document = DocumentModel::parse( + source, + DocumentIdentity { + project_root_id: String::new(), + module_id: String::new(), + relative_path: "index.mq.md".into(), + source_sha256: String::new(), + }, + ); + let project = Project::open( + &std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/tables-math"), + ) + .unwrap(); + let config = ViewConfig::default(); + let navigation = Navigation::from_project( + &project, + &config, + &SafeRelativePath::parse("index.mq.md").unwrap(), + ); + let model = presentation::build(BuildInput { + document, + analysis: None, + status: SourceStatus::CoreUnavailable, + status_note: Some("test".into()), + diagnostics: Vec::new(), + navigation, + core_version: None, + }); + let html = render_live(&model); + assert!(!html.contains("