diff --git a/CHANGELOG.md b/CHANGELOG.md index 59e2d68..4099c56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added ### Fixed +- 未绑定的 GFM 表格不再报 `unrecognized statement`:作为集合值求值后丢弃(文档中可写表)。 ### Changed diff --git a/doc/design/markdown-mapping-v0.3.md b/doc/design/markdown-mapping-v0.3.md index 2623403..eed873c 100644 --- a/doc/design/markdown-mapping-v0.3.md +++ b/doc/design/markdown-mapping-v0.3.md @@ -211,7 +211,7 @@ v0.3: | 体内 `1.` `2.` … | 分支 | | 体内 `-` | 循环 | | `N. *` | else 臂(此处 `*` 仍是「空条件」标记,**不是**返回值;见 §7.3) | -| GFM 表格 | 集合(不变) | +| GFM 表格 | 集合;`` `名` = `` 后绑定,或**未绑定**时求值后丢弃(文档中可写表) | | 表达式 `[键](集合)` | **取元**(与 foreach 同形;见 [collection-access-link.md](collection-access-link.md)) | | `修饰… [函数名] 实参…` | **方括号标记调用**(前置修饰 → `名=True`;见 [bracket-call-modifiers.md](bracket-call-modifiers.md)) | | `` 集合[^键] `` | **过渡**:旧脚注取元(仍可用) | diff --git a/public/00-welcome.mq.md b/public/00-welcome.mq.md index 723fa12..061d067 100644 --- a/public/00-welcome.mq.md +++ b/public/00-welcome.mq.md @@ -15,13 +15,13 @@ The language is still young: structure markers, bilingual core names (`print` / ## Install -Pick one way to get the CLI (not a Markdown table — tables are collections in Marqdo): +Pick one way to get the CLI: -Ubuntu PPA — `sudo add-apt-repository ppa:cflmy/marqdo` then `sudo apt install marqdo`. - -GitHub Releases — prebuilt Windows / Linux zips at [releases](https://github.com/cflmy/marqdo/releases). - -From source — `cargo build --release` (needs Rust). +| Method | Notes | +|--------|-------| +| Ubuntu PPA | `sudo add-apt-repository ppa:cflmy/marqdo` then `sudo apt install marqdo` | +| GitHub Releases | Prebuilt Windows / Linux zips at [releases](https://github.com/cflmy/marqdo/releases) | +| From source | `cargo build --release` (needs Rust) | Official extensions version independently of the CLI: diff --git a/public/00-欢迎.mq.md b/public/00-欢迎.mq.md index d1acc75..f109480 100644 --- a/public/00-欢迎.mq.md +++ b/public/00-欢迎.mq.md @@ -15,13 +15,13 @@ AI 偏爱 Markdown结构的输出。作者的念头是:何必再把文档和 ## 安装 -解释器(CLI)任选其一(不用 Markdown 表格——在 Marqdo 里表格是集合): +解释器(CLI)任选其一: -Ubuntu PPA — `sudo add-apt-repository ppa:cflmy/marqdo` 后 `sudo apt install marqdo`。 - -GitHub Releases — [releases](https://github.com/cflmy/marqdo/releases) 下载 Windows / Linux 预编译包。 - -源码 — `cargo build --release`(需本机 Rust)。 +| 方式 | 说明 | +|------|------| +| Ubuntu PPA | `sudo add-apt-repository ppa:cflmy/marqdo` 后 `sudo apt install marqdo` | +| GitHub Releases | [releases](https://github.com/cflmy/marqdo/releases) 下载 Windows / Linux 预编译包 | +| 源码 | `cargo build --release`(需本机 Rust) | 官方扩展与 CLI 可分开更新。安装扩展: diff --git a/src/parse/mod.rs b/src/parse/mod.rs index d972eed..df5559f 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -323,6 +323,16 @@ impl<'a> Cursor<'a> { fun.body.push(self.parse_loop_or_err()?); continue; } + // Unbound GFM table = collection value (not assigned); evaluate and discard. + if trimmed.starts_with('|') { + let span = Span { + line: l.line_no, + col: 1, + }; + let value = self.consume_table()?; + fun.body.push(Stmt::Expr { value, span }); + continue; + } let stmt = self.parse_simple_stmt()?; let end_body = matches!(stmt, Stmt::Return { .. }) && level >= 2; @@ -382,6 +392,13 @@ impl<'a> Cursor<'a> { return Ok(Stmt::Call { call, span }); } + // Unbound GFM table (header already consumed by bump above). + if trimmed.starts_with('|') { + self.i -= 1; + let value = self.consume_table()?; + return Ok(Stmt::Expr { value, span }); + } + // Bare assign `` `x` = … `` if trimmed.starts_with('`') { if let Some(stmt) = self.parse_backtick_assign(trimmed, span.clone())? { @@ -695,6 +712,8 @@ impl<'a> Cursor<'a> { /// - first header `@` / `行` / `row` → List of row Maps (marker col excluded) /// - else ≥2-col → Map (column-oriented) /// + /// Also used for **unbound** tables in a function body (value computed, not stored). + /// /// Data cells are expressions ([`parse_call_arg_value`]); headers stay key text. fn consume_table(&mut self) -> Result { self.skip_noise(); diff --git a/tests/gold.rs b/tests/gold.rs index 6e8c3cf..b664b9d 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -132,6 +132,11 @@ fn structure_hello() { assert_out("tests/structure/hello.mq.md", "Hello World!"); } +#[test] +fn structure_unbound_table() { + assert_out("tests/structure/unbound-table.mq.md", "ok"); +} + #[test] fn structure_object_handle() { assert_out("tests/structure/object-handle.mq.md", "counter\n3\n4"); diff --git a/tests/structure/unbound-table.mq.md b/tests/structure/unbound-table.mq.md new file mode 100644 index 0000000..1b30228 --- /dev/null +++ b/tests/structure/unbound-table.mq.md @@ -0,0 +1,15 @@ +--- +title: Unbound GFM table is a discarded value +--- + +# main + +Documentation may include a table that is not bound to a name. It is still a +collection value; evaluating it must not error. + +| Method | Notes | +|--------|-------| +| PPA | apt | +| Source | cargo | + +> print text=ok