Implement table semantic T0-T4: map/records/footnote get

- 1-col table stays a List; >=2-col becomes a column-oriented Map
  (1 data row -> scalar values, >=2 -> Map of Lists).
- First header @ / 行 / row opts into row-oriented List of Maps
  (marker column excluded); missing field cols is a diagnostic.
- Footnote index: `xs`[^1] (1-based list), `m`[^key] (map key), chained.
  Errors for [^0], out-of-range, missing key, duplicate headers.
- foreach walks list items or map keys; Map values now display as {k: v}.
- Sync both tree and bytecode backends; new gold + error fixtures, docs
  (markdown-mapping, roadmap, skill, public), and public 07/08 pages.
- Fix subtask-spawn fixture return value to child_ok (child-ok parses as
  subtraction).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-10 09:50:21 +08:00
1 parent 3463628165
commit a23fdedfa2
37 files changed
+846 -51

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
---
title: footnote missing map key
---
# main
`分类` =
| 苹果 | 黄瓜 |
|------|------|
| 水果 | 蔬菜 |
*`x` = `分类`[^香蕉] *
> print text=`x`
+15
View File
@@ -0,0 +1,15 @@
---
title: footnote list out of range
---
# main
`篮子` =
| 果 |
|----|
| 苹果 |
*`x` = `篮子`[^2] *
> print text=`x`
+15
View File
@@ -0,0 +1,15 @@
---
title: footnote [^0] invalid
---
# main
`篮子` =
| 果 |
|----|
| 苹果 |
*`x` = `篮子`[^0] *
> print text=`x`
+13
View File
@@ -0,0 +1,13 @@
---
title: duplicate table header
---
# main
`t` =
| a | a |
|---|---|
| 1 | 2 |
> print text=nope
+13
View File
@@ -0,0 +1,13 @@
---
title: row marker without field columns
---
# main
`t` =
| 行 |
|----|
| 1 |
> print text=nope
+159 -1
View File
@@ -112,6 +112,60 @@ fn structure_collection() {
桃");
}
#[test]
fn structure_collection_map() {
assert_out(
"tests/structure/collection-map.mq.md",
"水果
蔬菜
数码用品
苹果
黄瓜
鼠标",
);
}
#[test]
fn structure_collection_map_list() {
assert_out(
"tests/structure/collection-map-list.mq.md",
"红富士
[红富士, 嘎啦]
黄瓜条",
);
}
#[test]
fn structure_footnote_index() {
assert_out(
"tests/structure/footnote-index.mq.md",
"苹果
梨
桃",
);
}
#[test]
fn structure_collection_records() {
assert_out(
"tests/structure/collection-records.mq.md",
"{品名: 苹果, 数量: 2}
苹果
3
{品名: 苹果, 数量: 2}
{品名: 梨, 数量: 3}",
);
}
#[test]
fn structure_collection_records_at() {
assert_out(
"tests/structure/collection-records-at.mq.md",
"apple
3",
);
}
#[test]
fn structure_import() {
assert_out(
@@ -358,6 +412,51 @@ fn error_div_zero() {
assert_err("tests/errors/div-zero.mq.md", "7:1", "division by zero");
}
#[test]
fn error_footnote_zero() {
assert_err(
"tests/errors/footnote-zero.mq.md",
"13:1",
"`[^0]` is invalid",
);
}
#[test]
fn error_footnote_oob() {
assert_err(
"tests/errors/footnote-oob.mq.md",
"13:1",
"out of range",
);
}
#[test]
fn error_footnote_missing_key() {
assert_err(
"tests/errors/footnote-missing-key.mq.md",
"13:1",
"missing map key",
);
}
#[test]
fn error_table_dup_header() {
assert_err(
"tests/errors/table-dup-header.mq.md",
"9:1",
"duplicate table header",
);
}
#[test]
fn error_table_row_marker_only() {
assert_err(
"tests/errors/table-row-marker-only.mq.md",
"9:1",
"row-oriented table needs field columns",
);
}
#[test]
fn error_bad_int() {
assert_err(
@@ -493,6 +592,65 @@ fn bytecode_collection() {
);
}
#[test]
fn bytecode_collection_map() {
assert_out_backend(
"tests/structure/collection-map.mq.md",
"bytecode",
"水果
蔬菜
数码用品
苹果
黄瓜
鼠标",
);
}
#[test]
fn bytecode_collection_map_list() {
assert_out_backend(
"tests/structure/collection-map-list.mq.md",
"bytecode",
"红富士
[红富士, 嘎啦]
黄瓜条",
);
}
#[test]
fn bytecode_footnote_index() {
assert_out_backend(
"tests/structure/footnote-index.mq.md",
"bytecode",
"苹果
梨
桃",
);
}
#[test]
fn bytecode_collection_records() {
assert_out_backend(
"tests/structure/collection-records.mq.md",
"bytecode",
"{品名: 苹果, 数量: 2}
苹果
3
{品名: 苹果, 数量: 2}
{品名: 梨, 数量: 3}",
);
}
#[test]
fn bytecode_collection_records_at() {
assert_out_backend(
"tests/structure/collection-records-at.mq.md",
"bytecode",
"apple
3",
);
}
#[test]
fn bytecode_print_keyword() {
assert_out_backend(
@@ -786,7 +944,7 @@ fn lib_writeback_get() {
#[test]
fn lib_subtask_spawn() {
assert_out("tests/lib/subtask-spawn.mq.md", "child-ok\ndone\nquiet-ok");
assert_out("tests/lib/subtask-spawn.mq.md", "child_ok\ndone\nquiet-ok");
}
#[test]
+1 -1
View File
@@ -26,7 +26,7 @@ title: subtask spawn join
*`val2` = > json.get value=`waited2` key=value *
1. `code2` == 0
1. `val2` == "child-ok"
1. `val2` == "child_ok"
> print text=quiet-ok
2. *
> print text=quiet-bad-value
+24
View File
@@ -0,0 +1,24 @@
---
title: 横表多行 → 字典套列表
---
# main
`货架` =
| 苹果 | 黄瓜 |
|------|------|
| 红富士 | 青瓜 |
| 嘎啦 | 黄瓜条 |
*`第一种苹果` = `货架`[^苹果][^1] *
> print text=`第一种苹果`
*`列` = `货架`[^苹果] *
> print text=`列`
*`第二种黄瓜` = `货架`[^黄瓜][^2] *
> print text=`第二种黄瓜`
+26
View File
@@ -0,0 +1,26 @@
---
title: 横表单行 → 字典
---
# main
`分类` =
| 苹果 | 黄瓜 | 鼠标 |
|------|------|------|
| 水果 | 蔬菜 | 数码用品 |
*`种` = `分类`[^苹果] *
> print text=`种`
*`种` = `分类`[^黄瓜] *
> print text=`种`
*`种` = `分类`[^鼠标] *
> print text=`种`
- [`键`](`分类`)
> print text=`键`
@@ -0,0 +1,20 @@
---
title: row records with @ marker
---
# main
`orders` =
| @ | name | qty |
|---|------|-----|
| 1 | apple | 2 |
| 2 | pear | 3 |
*`n` = `orders`[^1][^name] *
> print text=`n`
*`q` = `orders`[^2][^qty] *
> print text=`q`
+27
View File
@@ -0,0 +1,27 @@
---
title: 行向记录表(首列 行 / @)
---
# main
`订单` =
| 行 | 品名 | 数量 |
|----|------|------|
| 1 | 苹果 | 2 |
| 2 | 梨 | 3 |
*`第一` = `订单`[^1] *
> print text=`第一`
*`名` = `订单`[^1][^品名] *
> print text=`名`
*`量` = `订单`[^2][^数量] *
> print text=`量`
- [`记录`](`订单`)
> print text=`记录`
+25
View File
@@ -0,0 +1,25 @@
---
title: 脚注取元(列表下标)
---
# main
`篮子` =
| 果 |
|----|
| 苹果 |
| 梨 |
| 桃 |
*`第一` = `篮子`[^1] *
> print text=`第一`
*`第二` = `篮子`[^2] *
> print text=`第二`
*`第三` = `篮子`[^3] *
> print text=`第三`