Add host stdlib modules and unify view/run capabilities.
Ship fs/time/sys/json/net L1 libs (plus existing text/table), default-on host caps with soft exit under view, bilingual public/stdlib docs, and design notes for deferred math/foreign. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a5d30c00b3
commit
a53ebb65ee
66 files changed
+2703
-45
No files matched your search
@@ -9,7 +9,7 @@ Hi — thanks for opening this site. Marqdo is a language where **code is docume
|
||||
|
||||
AI already prefers Markdown. Marqdo asks: why keep docs and code as two worlds? A `.mq.md` file is both. The longer ambition includes OKF-style knowledge YAML and more; for now the focus is a solid interpreter and this site (yes — generated by Marqdo itself).
|
||||
|
||||
The language is young. You get structure markers, a small bilingual core (`print` / `打印`, …), optional stdlib files (`lib/text.mq.md` vs `lib/文本.mq.md`), local `view`, and static export. Contribute on [GitHub](https://github.com/cflmy/marqdo).
|
||||
The language is young. You get structure markers, a small bilingual core (`print` / `打印`, …), optional stdlib files under `lib/` (see [`stdlib/`](stdlib/) on this site), local `view`, and static export. Contribute on [GitHub](https://github.com/cflmy/marqdo).
|
||||
|
||||
中文文档请看同目录的 [`00-欢迎.mq.md`](00-欢迎.mq.md)(叙述与内置均用中文)。
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ description: 用户文档首页 — 代码即文档(中文版)
|
||||
|
||||
AI 输出本就偏爱 Markdown。作者的念头是:何必再把文档和代码拆成两套?`.mq.md` 双后缀保证它仍是合法 Markdown。更长远的目标包括 OKF 式知识清单等;眼下先把解释器与本站做好——对,这个站点就是 Marqdo 生成的。
|
||||
|
||||
语言仍在起步:结构标记、中英内核双名(`打印` / `print` …)、可导入的标准库(`lib/文本.mq.md` 与 `lib/text.mq.md`)、本地 `view` 与静态导出。欢迎到 [GitHub](https://github.com/cflmy/marqdo) 一起做。
|
||||
语言仍在起步:结构标记、中英内核双名(`打印` / `print` …)、可导入的标准库(见本站 [`stdlib/`](stdlib/))、本地 `view` 与静态导出。欢迎到 [GitHub](https://github.com/cflmy/marqdo) 一起做。
|
||||
|
||||
English docs: [`00-welcome.mq.md`](00-welcome.mq.md) (English prose and English builtins).
|
||||
|
||||
|
||||
+9
-11
@@ -2,28 +2,26 @@
|
||||
|
||||
本目录即面向访客的 Marqdo 介绍:每个 `.mq.md` 既是文稿也能 `marqdo run`,并随仓库 / 静态站一起下载。
|
||||
|
||||
**双语约定:** 拉丁文件名 → 英文叙述与英文内置;中文文件名 → 中文叙述与中文编程(`打印`、`长度` …)。成对放在同一目录(如 `structure/01-hello.mq.md` 与 `structure/01-你好.mq.md`)。标准库按路径选 API:`lib/text.mq.md` vs `lib/文本.mq.md`。
|
||||
**双语约定:** 拉丁文件名 → 英文叙述与英文内置;中文文件名 → 中文叙述与中文编程。成对放在同一目录。标准库:拉丁路径用英文 API,中文路径用中文 API;JSON 仅 `lib/json.mq.md`。
|
||||
|
||||
| 路径 | 内容 |
|
||||
|------|------|
|
||||
| [`00-welcome.mq.md`](00-welcome.mq.md) / [`00-欢迎.mq.md`](00-欢迎.mq.md) | 首页(英 / 中) |
|
||||
| [`structure/`](structure/) | 基本结构(英 / 中并列) |
|
||||
| [`keywords/`](keywords/) | 关键字与内置(英 / 中并列) |
|
||||
| [`features/`](features/) | 特性迭代(英 / 中并列) |
|
||||
| [`lib-import.mq.md`](lib-import.mq.md) / [`lib-导入.mq.md`](lib-导入.mq.md) | 导入 `lib/text` / `lib/文本` |
|
||||
| [`structure/`](structure/) | 基本结构 |
|
||||
| [`keywords/`](keywords/) | 关键字与 L0 内置 |
|
||||
| [`stdlib/`](stdlib/) | **标准库**(导入方式 + text/表/文件/时间/系统/json/网络) |
|
||||
| [`features/`](features/) | 特性迭代 |
|
||||
| [`lib-import.mq.md`](lib-import.mq.md) / [`lib-导入.mq.md`](lib-导入.mq.md) | 快速导入示例(text) |
|
||||
|
||||
**不放** `errors/`:失败样例只在 `tests/errors/`,避免用户站出现红色执行失败。
|
||||
**不放** `errors/`:失败样例只在 `tests/errors/`。
|
||||
|
||||
开发文档(语言设计等)在 [`doc/`](../doc/),与本目录分离。
|
||||
开发文档在 [`doc/`](../doc/)。
|
||||
|
||||
## 浏览与生成 HTML
|
||||
|
||||
```bash
|
||||
cargo run -- view public
|
||||
cargo run -- view output public -o public
|
||||
# 或
|
||||
./scripts/build-public.sh
|
||||
powershell -File ./scripts/build-public.ps1
|
||||
```
|
||||
|
||||
生成的 `index.html` 与 `pages/` 默认被 ignore;CI 构建后推到 `gh-pages`。详见 [user-site.md](../doc/design/user-site.md)。
|
||||
详见 [user-site.md](../doc/design/user-site.md)。
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: Standard library — overview
|
||||
description: How to import official lib modules
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Official libraries live under lib/ (alias std/). Import them in YAML frontmatter with a greater-than line, for example lib/text.mq.md or lib/fs.mq.md.
|
||||
|
||||
English-named files export English APIs; Chinese-named files export Chinese APIs. JSON is special: only lib/json.mq.md (shared by both languages).
|
||||
|
||||
No extra allow flags: importing a module means you intend to use it. Under marqdo view or static export, exit soft-fails and long sleeps are clamped so the console stays up.
|
||||
|
||||
Modules: text (text / 文本), table (table / 表), files (fs / 文件), time (time / 时间), system (sys / 系统), json (json only), net (net / 网络).
|
||||
|
||||
Sibling pages in this folder document each module. Chinese overview: 00-索引.mq.md.
|
||||
|
||||
> print text=stdlib overview ok
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: 标准库 — 总览
|
||||
description: 如何导入官方 lib 模块
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
官方库在仓库 lib/(别名 std/)。在 YAML frontmatter 用大于号行导入,例如 lib/文本.mq.md 或 lib/文件.mq.md。
|
||||
|
||||
拉丁文件名导出英文 API;中文文件名导出中文 API。JSON 特例:只有 lib/json.mq.md(中英共用)。
|
||||
|
||||
导入即表示要用对应能力,无需再加允许旗标。marqdo view 或静态导出里,退出会软失败、长睡眠会被钳制,以免拖垮控制台。
|
||||
|
||||
模块:文本(text / 文本)、表(table / 表)、文件(fs / 文件)、时间(time / 时间)、系统(sys / 系统)、json(仅 json)、网络(net / 网络)。
|
||||
|
||||
各模块说明见本目录其它页。English: 00-overview.mq.md.
|
||||
|
||||
> 打印 内容=标准库总览就绪
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: lib/fs — files
|
||||
description: Read and write text under the sandbox
|
||||
> lib/fs.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Import lib/fs.mq.md. Functions: read_text, write_text, append_text, exists, list_dir, make_dir, remove (path / text params).
|
||||
|
||||
Bare path words must not contain a slash character (parsed as division). Prefer a same-folder name or a variable.
|
||||
|
||||
*`ok` = > exists path=demo.txt *
|
||||
|
||||
+ `ok`
|
||||
> print text=demo-present
|
||||
+ *
|
||||
> print text=demo-missing
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: lib/json — JSON
|
||||
description: Shared EN/ZH path; parse and stringify
|
||||
> lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Import lib/json.mq.md from both English and Chinese docs (no translated twin). Functions: parse(text), stringify(value), get(value, key), keys(value). Objects become the map runtime type.
|
||||
|
||||
*`obj` = > parse text={} *
|
||||
|
||||
*`ty` = > type `obj` *
|
||||
|
||||
> print text=`ty`
|
||||
|
||||
*`out` = > stringify value=`obj` *
|
||||
|
||||
> print text=`out`
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: lib/net — HTTP
|
||||
description: Minimal HTTP client and URL encode
|
||||
> lib/net.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Import lib/net.mq.md. Functions: http_get(url) returns map status/body, http_post(url, body), url_encode(text). v1 speaks cleartext http only.
|
||||
|
||||
*`e` = > url_encode text=hello world *
|
||||
|
||||
> print text=`e`
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: lib/sys — process
|
||||
description: Env, cwd, args, exit, exec
|
||||
> lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Import lib/sys.mq.md. Functions: env_get, env_set, args, cwd, exit(code), exec(cmd). Under view, exit soft-fails instead of killing the process.
|
||||
|
||||
*`d` = > cwd *
|
||||
|
||||
*`n` = > len `d` *
|
||||
|
||||
+ `n` > 0
|
||||
> print text=cwd-ok
|
||||
+ *
|
||||
> print text=cwd-empty
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: lib/table — lists
|
||||
description: Row count and index helpers
|
||||
> lib/table.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Import lib/table.mq.md. Functions: rows(xs), row_at(xs, i). Single-column Markdown tables are lists at runtime.
|
||||
|
||||
`xs` =
|
||||
|
||||
| v |
|
||||
|---|
|
||||
| a |
|
||||
| b |
|
||||
|
||||
*`n` = > rows xs=`xs`*
|
||||
|
||||
> print text=`n`
|
||||
|
||||
*`r` = > row_at xs=`xs` i=0*
|
||||
|
||||
> print text=`r`
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: lib/text — strings
|
||||
description: Trim, split, join wrappers
|
||||
> lib/text.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Import lib/text.mq.md. Functions: str_trim(s), str_split(s, sep), str_join(xs, sep).
|
||||
|
||||
*`t` = > str_trim s= marqdo *
|
||||
|
||||
> print text=`t`
|
||||
|
||||
*`parts` = > str_split s=a,b,c sep=,*
|
||||
|
||||
*`j` = > str_join xs=`parts` sep=-*
|
||||
|
||||
> print text=`j`
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: lib/time — clock
|
||||
description: Unix time, format, parse, sleep
|
||||
> lib/time.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Import lib/time.mq.md. Functions: now_unix, now_ms, format(unix, pattern), parse(text, pattern), sleep_ms(ms). Patterns use strftime.
|
||||
|
||||
*`s` = > format unix=0 pattern=%Y-%m-%d *
|
||||
|
||||
> print text=`s`
|
||||
|
||||
*`u` = > parse text=1970-01-01 00:00:00 pattern=%Y-%m-%d %H:%M:%S *
|
||||
|
||||
> print text=`u`
|
||||
|
||||
> sleep_ms ms=0
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: lib/文件 — 文件系统
|
||||
description: 沙箱内读写文本
|
||||
> lib/文件.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
导入 lib/文件.mq.md。函数:读文本、写文本、追加文本、存在、列目录、建目录、删除。
|
||||
|
||||
裸路径字面量不要写斜杠(会被当成除法)。可用同目录文件名或变量。
|
||||
|
||||
*`ok` = > 存在 路径=demo.txt *
|
||||
|
||||
+ `ok`
|
||||
> 打印 内容=有演示文件
|
||||
+ *
|
||||
> 打印 内容=无演示文件
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: lib/文本 — 字符串
|
||||
description: 去空白、拆分、拼接
|
||||
> lib/文本.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
导入 lib/文本.mq.md。函数:去空白(s)、拆分(s, sep)、拼接(xs, sep)。
|
||||
|
||||
*`t` = > 去空白 s= marqdo *
|
||||
|
||||
> 打印 内容=`t`
|
||||
|
||||
*`parts` = > 拆分 s=甲,乙,丙 sep=,*
|
||||
|
||||
*`j` = > 拼接 xs=`parts` sep=-*
|
||||
|
||||
> 打印 内容=`j`
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: lib/时间 — 时钟
|
||||
description: Unix 时间、格式化、解析、睡眠
|
||||
> lib/时间.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
导入 lib/时间.mq.md。函数:此刻秒、此刻毫秒、格式化(秒, 格式)、解析时间(内容, 格式)、睡眠毫秒(毫秒)。格式为 strftime。
|
||||
|
||||
*`s` = > 格式化 秒=0 格式=%Y-%m-%d *
|
||||
|
||||
> 打印 内容=`s`
|
||||
|
||||
*`u` = > 解析时间 内容=1970-01-01 00:00:00 格式=%Y-%m-%d %H:%M:%S *
|
||||
|
||||
> 打印 内容=`u`
|
||||
|
||||
> 睡眠毫秒 毫秒=0
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: lib/系统 — 进程
|
||||
description: 环境变量、工作目录、参数、退出、执行
|
||||
> lib/系统.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
导入 lib/系统.mq.md。函数:取环境、设环境、参数表、工作目录、退出(码)、执行(命令)。view 下退出会软失败,不结束进程。
|
||||
|
||||
*`d` = > 工作目录 *
|
||||
|
||||
*`n` = > 长度 值=`d` *
|
||||
|
||||
+ `n` > 0
|
||||
> 打印 内容=工作目录就绪
|
||||
+ *
|
||||
> 打印 内容=工作目录空
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: lib/网络 — HTTP
|
||||
description: 简易 HTTP 与地址编码
|
||||
> lib/网络.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
导入 lib/网络.mq.md。函数:获取(地址) 返回 map status/body、提交(地址, 内容)、编码地址(内容)。本波仅明文 http。
|
||||
|
||||
*`e` = > 编码地址 内容=你好 *
|
||||
|
||||
> 打印 内容=`e`
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: lib/表 — 列表
|
||||
description: 行数与取行
|
||||
> lib/表.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
导入 lib/表.mq.md。函数:行数(xs)、取行(xs, i)。单列表在运行时是列表。
|
||||
|
||||
`xs` =
|
||||
|
||||
| v |
|
||||
|---|
|
||||
| 甲 |
|
||||
| 乙 |
|
||||
|
||||
*`n` = > 行数 xs=`xs`*
|
||||
|
||||
> 打印 内容=`n`
|
||||
|
||||
*`r` = > 取行 xs=`xs` i=0*
|
||||
|
||||
> 打印 内容=`r`
|
||||
Reference in new issue
Block a user