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 结果`
|
||||
Reference in new issue
Block a user