feat(lang): implement RFC-LANG-0002 unified semantics (breaking)
One Markdown-to-program mapping, no version selector or legacy mapper. Frontend/runtime: - resolve @exec/@knowledge heading declarations with nearest-ancestor inheritance; only an Exec H2 is callable; add UnitKind::Knowledge and sem.* diagnostics (mode marker, unit name, exec-without-function, payload nesting/empty, syntax, control stack, params position, version directive, inferred-signature lint) - extract Strong/Emph/inline Code as one-statement carriers, refuse nested carriers, and honour heading segment boundaries so an if/while cannot be closed across a heading - lower if/else/while/end to the existing Branch/Loop/Return IR with a compile-time control stack; keep payload-relative source spans through expression parsing and rewrite them onto the file - accept params(...) only as the first direct Exec H2 payload; keep the existing free-variable inference and named-only rule for inferred signatures; fix duplicate-mode/else/end and Knowledge-body inertness - reject marqdo_semantics/syntax front matter directives Data and tests: - migrate stdlib/**/*.mq.md, regenerate stdlib.json digest - migrate examples and the full semantics/negative/runtime corpus to the only current syntax; expected values/runtime codes preserved - migrate Rust-embedded .mq.md fixtures, init template, CLI help and security-lane fixtures Verified: cargo fmt --check, cargo clippy -D warnings and cargo test --workspace --locked (green).
This commit is contained in:
1 parent
49835424ee
commit
e029853e32
375 files changed
+6591
-4790
No files matched your search
+179
-116
@@ -1,20 +1,22 @@
|
||||
|
||||
# @exec csv
|
||||
## 成功
|
||||
|
||||
`(值)`
|
||||
`params(值)`
|
||||
|
||||
*{ok: true, value: 值}*
|
||||
`return {ok: true, value: 值}`
|
||||
|
||||
## 失败
|
||||
|
||||
`(代码, 消息)`
|
||||
`params(代码, 消息)`
|
||||
|
||||
*{ok: false, code: 代码, message: 消息}*
|
||||
`return {ok: false, code: 代码, message: 消息}`
|
||||
|
||||
## 解析行
|
||||
|
||||
`(文本)`
|
||||
`params(文本)`
|
||||
|
||||
解析单行 CSV:逗号分隔、双引号包裹、`""` 表示一个字面双引号。
|
||||
解析单行 CSV:逗号分隔、双引号包裹、"" 表示一个字面双引号。
|
||||
不处理换行、多行字段或首尾空白。未闭合引号和未加引号字段中的双引号
|
||||
返回可恢复错误。
|
||||
|
||||
@@ -30,71 +32,90 @@
|
||||
|
||||
**错误 = ""**
|
||||
|
||||
- `下标 < 长度(点) and 错误 == ""`
|
||||
`while 下标 < 长度(点) and 错误 == ""`
|
||||
|
||||
**字符 = text.from_codepoint(点[下标])**
|
||||
**字符 = text.from_codepoint(点[下标])**
|
||||
|
||||
1. `引号内 and 字符 == "\""`
|
||||
`if 引号内 and 字符 == "\""`
|
||||
|
||||
1. `下标 + 1 < 长度(点) and text.from_codepoint(点[下标 + 1]) == "\""`
|
||||
`if 下标 + 1 < 长度(点) and text.from_codepoint(点[下标 + 1]) == "\""`
|
||||
|
||||
**`字段 = 字段 + "\""`**
|
||||
**`字段 = 字段 + "\""`**
|
||||
|
||||
**下标 = 下标 + 2**
|
||||
**下标 = 下标 + 2**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**引号内 = false**
|
||||
**引号内 = false**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
2. `引号内`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if 引号内`
|
||||
|
||||
**字段 = 字段 + 字符**
|
||||
**字段 = 字段 + 字符**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
3. `字符 == "\""`
|
||||
`else`
|
||||
`if 字符 == "\""`
|
||||
|
||||
1. `字段 == ""`
|
||||
`if 字段 == ""`
|
||||
|
||||
**引号内 = true**
|
||||
**引号内 = true**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**错误 = "csv.invalid_quote"**
|
||||
**错误 = "csv.invalid_quote"**
|
||||
|
||||
4. `字符 == ","`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if 字符 == ","`
|
||||
|
||||
**字段表 = list.append(字段表, 字段)**
|
||||
**字段表 = list.append(字段表, 字段)**
|
||||
|
||||
**字段 = ""**
|
||||
**字段 = ""**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
5. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**字段 = 字段 + 字符**
|
||||
**字段 = 字段 + 字符**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
1. `错误 != ""`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`if 错误 != ""`
|
||||
|
||||
*失败(错误, "未加引号字段中出现双引号")*
|
||||
`return 失败(错误, "未加引号字段中出现双引号")`
|
||||
|
||||
1. `引号内`
|
||||
`else`
|
||||
`if 引号内`
|
||||
|
||||
*失败("csv.unterminated_quote", "引号未闭合")*
|
||||
`return 失败("csv.unterminated_quote", "引号未闭合")`
|
||||
|
||||
*成功(list.concat(字段表, [字段]))*
|
||||
`end`
|
||||
`end`
|
||||
`return 成功(list.concat(字段表, [字段]))`
|
||||
|
||||
## 格式化字段
|
||||
|
||||
`(文本)`
|
||||
`params(文本)`
|
||||
|
||||
含逗号、双引号、换行或回车的字段加引号,内部双引号写成 `""`。
|
||||
含逗号、双引号、换行或回车的字段加引号,内部双引号写成 ""。
|
||||
|
||||
**点 = text.codepoints(文本)**
|
||||
|
||||
@@ -102,72 +123,85 @@
|
||||
|
||||
**需要引号 = false**
|
||||
|
||||
- `下标 < 长度(点) and not 需要引号`
|
||||
`while 下标 < 长度(点) and not 需要引号`
|
||||
|
||||
**码点 = 点[下标]**
|
||||
**码点 = 点[下标]**
|
||||
|
||||
1. `码点 == 34 or 码点 == 44 or 码点 == 10 or 码点 == 13`
|
||||
`if 码点 == 34 or 码点 == 44 or 码点 == 10 or 码点 == 13`
|
||||
|
||||
**需要引号 = true**
|
||||
**需要引号 = true**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
1. `not 需要引号`
|
||||
`end`
|
||||
`if not 需要引号`
|
||||
|
||||
*文本*
|
||||
`return 文本`
|
||||
|
||||
`end`
|
||||
**`结果 = "\""`**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(点)`
|
||||
`while 下标 < 长度(点)`
|
||||
|
||||
1. `点[下标] == 34`
|
||||
`if 点[下标] == 34`
|
||||
|
||||
**`结果 = 结果 + "\"\""`**
|
||||
**`结果 = 结果 + "\"\""`**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**结果 = 结果 + text.from_codepoint(点[下标])**
|
||||
**结果 = 结果 + text.from_codepoint(点[下标])**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*`结果 + "\""`*
|
||||
`end`
|
||||
``return 结果 + "\""``
|
||||
|
||||
## 格式化行
|
||||
|
||||
`(列表)`
|
||||
`params(列表)`
|
||||
|
||||
**结果 = ""**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(列表)`
|
||||
`while 下标 < 长度(列表)`
|
||||
|
||||
1. `下标 > 0`
|
||||
`if 下标 > 0`
|
||||
|
||||
**结果 = 结果 + ","**
|
||||
**结果 = 结果 + ","**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**结果 = 结果 + 格式化字段(文本(列表[下标]))**
|
||||
`end`
|
||||
`end`
|
||||
**结果 = 结果 + 格式化字段(文本(列表[下标]))**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 解析
|
||||
|
||||
`(文本)`
|
||||
`params(文本)`
|
||||
|
||||
解析多行 CSV(逗号分隔、双引号、`""` 转义、CRLF/LF 行尾,引号内可含
|
||||
换行)。返回 `{ok:true, value:List<List<Text>>}`;未闭合引号和不合法
|
||||
解析多行 CSV(逗号分隔、双引号、"" 转义、CRLF/LF 行尾,引号内可含
|
||||
换行)。返回 {ok:true, value:List<List<Text>>};未闭合引号和不合法
|
||||
引号返回可恢复错误。
|
||||
|
||||
**点 = text.codepoints(文本)**
|
||||
@@ -184,108 +218,137 @@
|
||||
|
||||
**错误 = ""**
|
||||
|
||||
- `下标 < 长度(点) and 错误 == ""`
|
||||
`while 下标 < 长度(点) and 错误 == ""`
|
||||
|
||||
**字符 = text.from_codepoint(点[下标])**
|
||||
**字符 = text.from_codepoint(点[下标])**
|
||||
|
||||
1. `引号内 and 字符 == "\""`
|
||||
`if 引号内 and 字符 == "\""`
|
||||
|
||||
1. `下标 + 1 < 长度(点) and text.from_codepoint(点[下标 + 1]) == "\""`
|
||||
`if 下标 + 1 < 长度(点) and text.from_codepoint(点[下标 + 1]) == "\""`
|
||||
|
||||
**`字段 = 字段 + "\""`**
|
||||
**`字段 = 字段 + "\""`**
|
||||
|
||||
**下标 = 下标 + 2**
|
||||
**下标 = 下标 + 2**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**引号内 = false**
|
||||
**引号内 = false**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
2. `引号内`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if 引号内`
|
||||
|
||||
**字段 = 字段 + 字符**
|
||||
**字段 = 字段 + 字符**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
3. `字符 == "\""`
|
||||
`else`
|
||||
`if 字符 == "\""`
|
||||
|
||||
1. `字段 == ""`
|
||||
`if 字段 == ""`
|
||||
|
||||
**引号内 = true**
|
||||
**引号内 = true**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**错误 = "csv.invalid_quote"**
|
||||
**错误 = "csv.invalid_quote"**
|
||||
|
||||
4. `字符 == ","`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if 字符 == ","`
|
||||
|
||||
**当前行 = list.append(当前行, 字段)**
|
||||
**当前行 = list.append(当前行, 字段)**
|
||||
|
||||
**字段 = ""**
|
||||
**字段 = ""**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
5. `字符 == "\n"`
|
||||
`else`
|
||||
`if 字符 == "\n"`
|
||||
|
||||
**当前行 = list.append(当前行, 字段)**
|
||||
**当前行 = list.append(当前行, 字段)**
|
||||
|
||||
**行 = list.append(行, 当前行)**
|
||||
**行 = list.append(行, 当前行)**
|
||||
|
||||
**当前行 = []**
|
||||
**当前行 = []**
|
||||
|
||||
**字段 = ""**
|
||||
**字段 = ""**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
6. `字符 == "\r"`
|
||||
`else`
|
||||
`if 字符 == "\r"`
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
7. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**字段 = 字段 + 字符**
|
||||
**字段 = 字段 + 字符**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
1. `错误 != ""`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`if 错误 != ""`
|
||||
|
||||
*失败(错误, "未加引号字段中出现双引号")*
|
||||
`return 失败(错误, "未加引号字段中出现双引号")`
|
||||
|
||||
1. `引号内`
|
||||
`else`
|
||||
`if 引号内`
|
||||
|
||||
*失败("csv.unterminated_quote", "引号未闭合")*
|
||||
`return 失败("csv.unterminated_quote", "引号未闭合")`
|
||||
|
||||
1. `字段 != "" or 长度(当前行) > 0`
|
||||
`else`
|
||||
`if 字段 != "" or 长度(当前行) > 0`
|
||||
|
||||
**当前行 = list.append(当前行, 字段)**
|
||||
**当前行 = list.append(当前行, 字段)**
|
||||
|
||||
**行 = list.append(行, 当前行)**
|
||||
**行 = list.append(行, 当前行)**
|
||||
|
||||
*成功(行)*
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`return 成功(行)`
|
||||
|
||||
## 格式化
|
||||
|
||||
`(行列表)`
|
||||
`params(行列表)`
|
||||
|
||||
**结果 = ""**
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(行列表)`
|
||||
`while 行号 < 长度(行列表)`
|
||||
|
||||
1. `行号 > 0`
|
||||
`if 行号 > 0`
|
||||
|
||||
**结果 = 结果 + "\n"**
|
||||
**结果 = 结果 + "\n"**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**结果 = 结果 + 格式化行(行列表[行号])**
|
||||
`end`
|
||||
`end`
|
||||
**结果 = 结果 + 格式化行(行列表[行号])**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
+468
-292
File diff suppressed because it is too large.
Load diff
+181
-130
@@ -1,6 +1,8 @@
|
||||
|
||||
# @exec table
|
||||
## 选择列
|
||||
|
||||
`(数据, 列)`
|
||||
`params(数据, 列)`
|
||||
|
||||
**列名 = table.columns(数据)**
|
||||
|
||||
@@ -8,19 +10,20 @@
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(数据)`
|
||||
`while 行号 < 长度(数据)`
|
||||
|
||||
**行 = table.row(数据, 行号)**
|
||||
**行 = table.row(数据, 行号)**
|
||||
|
||||
**结果行 = list.append(结果行, [行[列]])**
|
||||
**结果行 = list.append(结果行, [行[列]])**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*表([列名[列]], 结果行)*
|
||||
`end`
|
||||
`return 表([列名[列]], 结果行)`
|
||||
|
||||
## 过滤数值大于
|
||||
|
||||
`(数据, 列, 阈值)`
|
||||
`params(数据, 列, 阈值)`
|
||||
|
||||
**列名 = table.columns(数据)**
|
||||
|
||||
@@ -28,25 +31,29 @@
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(数据)`
|
||||
`while 行号 < 长度(数据)`
|
||||
|
||||
**行 = table.row(数据, 行号)**
|
||||
**行 = table.row(数据, 行号)**
|
||||
|
||||
1. `行[列] > 阈值`
|
||||
`if 行[列] > 阈值`
|
||||
|
||||
**结果行 = list.append(结果行, 行)**
|
||||
**结果行 = list.append(结果行, 行)**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*表(列名, 结果行)*
|
||||
`end`
|
||||
`return 表(列名, 结果行)`
|
||||
|
||||
## 插入有序
|
||||
|
||||
`(已排序, 行, 列)`
|
||||
`params(已排序, 行, 列)`
|
||||
|
||||
**新列表 = []**
|
||||
|
||||
@@ -54,37 +61,44 @@
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(已排序)`
|
||||
`while 下标 < 长度(已排序)`
|
||||
|
||||
**当前行 = 已排序[下标]**
|
||||
**当前行 = 已排序[下标]**
|
||||
|
||||
1. `not 已插入 and 当前行[列] > 行[列]`
|
||||
`if not 已插入 and 当前行[列] > 行[列]`
|
||||
|
||||
**新列表 = list.append(新列表, 行)**
|
||||
**新列表 = list.append(新列表, 行)**
|
||||
|
||||
**新列表 = list.append(新列表, 当前行)**
|
||||
**新列表 = list.append(新列表, 当前行)**
|
||||
|
||||
**已插入 = true**
|
||||
**已插入 = true**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**新列表 = list.append(新列表, 当前行)**
|
||||
**新列表 = list.append(新列表, 当前行)**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
1. `not 已插入`
|
||||
`end`
|
||||
`if not 已插入`
|
||||
|
||||
**新列表 = list.append(新列表, 行)**
|
||||
**新列表 = list.append(新列表, 行)**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
*新列表*
|
||||
`end`
|
||||
`end`
|
||||
`return 新列表`
|
||||
|
||||
## 排序
|
||||
|
||||
`(数据, 列)`
|
||||
`params(数据, 列)`
|
||||
|
||||
**列名 = table.columns(数据)**
|
||||
|
||||
@@ -94,17 +108,18 @@
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 行数`
|
||||
`while 下标 < 行数`
|
||||
|
||||
**已排序 = 插入有序(已排序, table.row(数据, 下标), 列)**
|
||||
**已排序 = 插入有序(已排序, table.row(数据, 下标), 列)**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*表(列名, 已排序)*
|
||||
`end`
|
||||
`return 表(列名, 已排序)`
|
||||
|
||||
## 追加行
|
||||
|
||||
`(数据, 行)`
|
||||
`params(数据, 行)`
|
||||
|
||||
**列名 = table.columns(数据)**
|
||||
|
||||
@@ -112,17 +127,18 @@
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(数据)`
|
||||
`while 行号 < 长度(数据)`
|
||||
|
||||
**所有行 = list.append(所有行, table.row(数据, 行号))**
|
||||
**所有行 = list.append(所有行, table.row(数据, 行号))**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*表(列名, list.append(所有行, 行))*
|
||||
`end`
|
||||
`return 表(列名, list.append(所有行, 行))`
|
||||
|
||||
## 设置单元格
|
||||
|
||||
`(数据, 目标行, 目标列, 值)`
|
||||
`params(数据, 目标行, 目标列, 值)`
|
||||
|
||||
**列名 = table.columns(数据)**
|
||||
|
||||
@@ -130,41 +146,49 @@
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(数据)`
|
||||
`while 行号 < 长度(数据)`
|
||||
|
||||
**行 = table.row(数据, 行号)**
|
||||
**行 = table.row(数据, 行号)**
|
||||
|
||||
1. `行号 == 目标行`
|
||||
`if 行号 == 目标行`
|
||||
|
||||
**新行 = []**
|
||||
**新行 = []**
|
||||
|
||||
**列号 = 0**
|
||||
**列号 = 0**
|
||||
|
||||
- `列号 < 长度(行)`
|
||||
`while 列号 < 长度(行)`
|
||||
|
||||
1. `列号 == 目标列`
|
||||
`if 列号 == 目标列`
|
||||
|
||||
**新行 = list.append(新行, 值)**
|
||||
**新行 = list.append(新行, 值)**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**新行 = list.append(新行, 行[列号])**
|
||||
**新行 = list.append(新行, 行[列号])**
|
||||
|
||||
**列号 = 列号 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**列号 = 列号 + 1**
|
||||
|
||||
**新行表 = list.append(新行表, 新行)**
|
||||
`end`
|
||||
**新行表 = list.append(新行表, 新行)**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**新行表 = list.append(新行表, 行)**
|
||||
**新行表 = list.append(新行表, 行)**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*表(列名, 新行表)*
|
||||
`end`
|
||||
`return 表(列名, 新行表)`
|
||||
|
||||
## 连接
|
||||
|
||||
`(左, 右, 左列, 右列)`
|
||||
`params(左, 右, 左列, 右列)`
|
||||
|
||||
**表头 = list.concat(table.columns(左), table.columns(右))**
|
||||
|
||||
@@ -172,117 +196,134 @@
|
||||
|
||||
**左行号 = 0**
|
||||
|
||||
- `左行号 < 长度(左)`
|
||||
`while 左行号 < 长度(左)`
|
||||
|
||||
**左行 = table.row(左, 左行号)**
|
||||
**左行 = table.row(左, 左行号)**
|
||||
|
||||
**键 = 左行[左列]**
|
||||
**键 = 左行[左列]**
|
||||
|
||||
**右行号 = 0**
|
||||
**右行号 = 0**
|
||||
|
||||
- `右行号 < 长度(右)`
|
||||
`while 右行号 < 长度(右)`
|
||||
|
||||
**右行 = table.row(右, 右行号)**
|
||||
**右行 = table.row(右, 右行号)**
|
||||
|
||||
1. `右行[右列] == 键`
|
||||
`if 右行[右列] == 键`
|
||||
|
||||
**结果行 = list.append(结果行, list.concat(左行, 右行))**
|
||||
**结果行 = list.append(结果行, list.concat(左行, 右行))**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**右行号 = 右行号 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**右行号 = 右行号 + 1**
|
||||
|
||||
**左行号 = 左行号 + 1**
|
||||
`end`
|
||||
**左行号 = 左行号 + 1**
|
||||
|
||||
*表(表头, 结果行)*
|
||||
`end`
|
||||
`return 表(表头, 结果行)`
|
||||
|
||||
## 分组
|
||||
|
||||
`(数据, 键列, 值列)`
|
||||
`params(数据, 键列, 值列)`
|
||||
|
||||
**结果 = {}**
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(数据)`
|
||||
`while 行号 < 长度(数据)`
|
||||
|
||||
**行 = table.row(数据, 行号)**
|
||||
**行 = table.row(数据, 行号)**
|
||||
|
||||
**键 = 行[键列]**
|
||||
**键 = 行[键列]**
|
||||
|
||||
**当前 = map.get(结果, 键)**
|
||||
**当前 = map.get(结果, 键)**
|
||||
|
||||
**列表 = []**
|
||||
**列表 = []**
|
||||
|
||||
1. `map.has(结果, 键)`
|
||||
`if map.has(结果, 键)`
|
||||
|
||||
**列表 = 当前**
|
||||
**列表 = 当前**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**列表 = list.append(列表, 行[值列])**
|
||||
`end`
|
||||
`end`
|
||||
**列表 = list.append(列表, 行[值列])**
|
||||
|
||||
**结果 = map.set(结果, 键, 列表)**
|
||||
**结果 = map.set(结果, 键, 列表)**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 连接片段
|
||||
|
||||
`(片段)`
|
||||
`params(片段)`
|
||||
|
||||
**结果 = ""**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(片段)`
|
||||
`while 下标 < 长度(片段)`
|
||||
|
||||
1. `下标 > 0`
|
||||
`if 下标 > 0`
|
||||
|
||||
**结果 = 结果 + " | "**
|
||||
**结果 = 结果 + " | "**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**结果 = 结果 + 片段[下标]**
|
||||
`end`
|
||||
`end`
|
||||
**结果 = 结果 + 片段[下标]**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 连接行
|
||||
|
||||
`(行列表)`
|
||||
`params(行列表)`
|
||||
|
||||
**结果 = ""**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(行列表)`
|
||||
`while 下标 < 长度(行列表)`
|
||||
|
||||
1. `下标 > 0`
|
||||
`if 下标 > 0`
|
||||
|
||||
**结果 = 结果 + "\n"**
|
||||
**结果 = 结果 + "\n"**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**结果 = 结果 + 行列表[下标]**
|
||||
`end`
|
||||
`end`
|
||||
**结果 = 结果 + 行列表[下标]**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 转义单元格
|
||||
|
||||
`(值)`
|
||||
`params(值)`
|
||||
|
||||
**文本值 = 文本(值)**
|
||||
|
||||
@@ -292,27 +333,33 @@
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(点)`
|
||||
`while 下标 < 长度(点)`
|
||||
|
||||
1. `点[下标] == 124`
|
||||
`if 点[下标] == 124`
|
||||
|
||||
**结果 = 结果 + text.from_codepoint(92) + "|"**
|
||||
**结果 = 结果 + text.from_codepoint(92) + "|"**
|
||||
|
||||
2. `点[下标] == 10 or 点[下标] == 13`
|
||||
`else`
|
||||
`if 点[下标] == 10 or 点[下标] == 13`
|
||||
|
||||
**结果 = 结果 + " "**
|
||||
**结果 = 结果 + " "**
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**结果 = 结果 + text.from_codepoint(点[下标])**
|
||||
**结果 = 结果 + text.from_codepoint(点[下标])**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 转GFM
|
||||
|
||||
`(数据)`
|
||||
`params(数据)`
|
||||
|
||||
**列名 = table.columns(数据)**
|
||||
|
||||
@@ -320,12 +367,13 @@
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(列名)`
|
||||
`while 下标 < 长度(列名)`
|
||||
|
||||
**表头 = list.append(表头, 转义单元格(列名[下标]))**
|
||||
**表头 = list.append(表头, 转义单元格(列名[下标]))**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
`end`
|
||||
**行列表 = []**
|
||||
|
||||
**行列表 = list.append(行列表, "| " + 连接片段(表头) + " |")**
|
||||
@@ -334,32 +382,35 @@
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(列名)`
|
||||
`while 下标 < 长度(列名)`
|
||||
|
||||
**分隔 = list.append(分隔, "---")**
|
||||
**分隔 = list.append(分隔, "---")**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
`end`
|
||||
**行列表 = list.append(行列表, "| " + 连接片段(分隔) + " |")**
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(数据)`
|
||||
`while 行号 < 长度(数据)`
|
||||
|
||||
**行 = table.row(数据, 行号)**
|
||||
**行 = table.row(数据, 行号)**
|
||||
|
||||
**单元格 = []**
|
||||
**单元格 = []**
|
||||
|
||||
**列号 = 0**
|
||||
**列号 = 0**
|
||||
|
||||
- `列号 < 长度(行)`
|
||||
`while 列号 < 长度(行)`
|
||||
|
||||
**单元格 = list.append(单元格, 转义单元格(行[列号]))**
|
||||
**单元格 = list.append(单元格, 转义单元格(行[列号]))**
|
||||
|
||||
**列号 = 列号 + 1**
|
||||
**列号 = 列号 + 1**
|
||||
|
||||
**行列表 = list.append(行列表, "| " + 连接片段(单元格) + " |")**
|
||||
`end`
|
||||
**行列表 = list.append(行列表, "| " + 连接片段(单元格) + " |")**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*连接行(行列表)*
|
||||
`end`
|
||||
`return 连接行(行列表)`
|
||||
Reference in new issue
Block a user