feat(stdlib): add table GFM rendering and an HTTP/1.1 parser fixture
- stdlib/data/table.mq.md adds 连接片段/连接行/转义单元格/转GFM; logical Table renders as a GFM pipe table with pipe/newline escaping (CM-A08 P4 gate). - Add semantic fixture 71: HTTP/1.1 status/header/chunked response parsing and request construction in .mq.md; no host HTTP/TLS implementation (C10). - Update table CLI test, golden count 71, specs/status/README/changelog and evidence. Gate: fmt, clippy -D warnings, 426 tests passed; bundle digest refreshed.
This commit is contained in:
1 parent
67a6d35daf
commit
69a28ed1e1
12 files changed
+492
-9
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ no test commits, copies or rewrites files outside a throw-away temp directory.
|
||||
tests/
|
||||
├── conformance/
|
||||
│ ├── ast/ 160 × *.mq.md + sibling *.ast.json goldens
|
||||
│ └── semantics/ 70 × *.mq.md + sibling *.expected.json goldens
|
||||
│ └── semantics/ 71 × *.mq.md + sibling *.expected.json goldens
|
||||
├── negative/
|
||||
│ ├── *.mq.md 52 × compile-time hard-error fixtures + *.expected.json
|
||||
│ ├── warnings/ 6 × inert-executable warning fixtures + *.expected.json
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"args": {},
|
||||
"function": "main",
|
||||
"stdout": "",
|
||||
"value": {
|
||||
"items": [
|
||||
{
|
||||
"decimal": "200",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "OK"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "text/plain"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "hello world"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "GET /health HTTP/1.1\r\nAccept: text/plain\r\nHost: example.test\r\n\r\n"
|
||||
}
|
||||
],
|
||||
"type": "list"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
## 切片
|
||||
|
||||
`(点, 起, 止)`
|
||||
|
||||
**结果 = ""**
|
||||
|
||||
**下标 = 起**
|
||||
|
||||
- `下标 < 止`
|
||||
|
||||
**结果 = 结果 + text.from_codepoint(点[下标])**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
|
||||
## 找子串
|
||||
|
||||
`(点, 子点, 起点)`
|
||||
|
||||
**结果 = 0 - 1**
|
||||
|
||||
**下标 = 起点**
|
||||
|
||||
- `下标 + 长度(子点) <= 长度(点) and 结果 < 0`
|
||||
|
||||
**偏移 = 0**
|
||||
|
||||
**匹配 = true**
|
||||
|
||||
- `偏移 < 长度(子点) and 匹配`
|
||||
|
||||
1. `点[下标 + 偏移] != 子点[偏移]`
|
||||
|
||||
**匹配 = false**
|
||||
|
||||
2. `true`
|
||||
|
||||
**忽略 = 0**
|
||||
|
||||
**偏移 = 偏移 + 1**
|
||||
|
||||
1. `匹配`
|
||||
|
||||
**结果 = 下标**
|
||||
|
||||
2. `true`
|
||||
|
||||
**忽略 = 0**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
|
||||
## 找字符
|
||||
|
||||
`(点, 码点, 起点)`
|
||||
|
||||
**结果 = 0 - 1**
|
||||
|
||||
**下标 = 起点**
|
||||
|
||||
- `下标 < 长度(点) and 结果 < 0`
|
||||
|
||||
1. `点[下标] == 码点`
|
||||
|
||||
**结果 = 下标**
|
||||
|
||||
2. `true`
|
||||
|
||||
**忽略 = 0**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
|
||||
## 十六进制值
|
||||
|
||||
`(点)`
|
||||
|
||||
**数值 = 0**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(点)`
|
||||
|
||||
**码点 = 点[下标]**
|
||||
|
||||
1. `码点 >= 48 and 码点 <= 57`
|
||||
|
||||
**数值 = 数值 * 16 + 码点 - 48**
|
||||
|
||||
2. `码点 >= 65 and 码点 <= 70`
|
||||
|
||||
**数值 = 数值 * 16 + 码点 - 55**
|
||||
|
||||
3. `码点 >= 97 and 码点 <= 102`
|
||||
|
||||
**数值 = 数值 * 16 + 码点 - 87**
|
||||
|
||||
4. `true`
|
||||
|
||||
**忽略 = 0**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*数值*
|
||||
|
||||
## 解码分块
|
||||
|
||||
`(体)`
|
||||
|
||||
**点 = text.codepoints(体)**
|
||||
|
||||
**结果 = ""**
|
||||
|
||||
**位置 = 0**
|
||||
|
||||
- `位置 < 长度(点)`
|
||||
|
||||
**行尾 = 找子串(点, text.codepoints("\r\n"), 位置)**
|
||||
|
||||
- `行尾 < 0`
|
||||
|
||||
*""*
|
||||
|
||||
**大小文本 = 切片(点, 位置, 行尾)**
|
||||
|
||||
**大小 = 十六进制值(text.codepoints(大小文本))**
|
||||
|
||||
1. `大小 == 0`
|
||||
|
||||
**位置 = 长度(点)**
|
||||
|
||||
2. `true`
|
||||
|
||||
**结果 = 结果 + 切片(点, 行尾 + 2, 行尾 + 2 + 大小)**
|
||||
|
||||
**位置 = 行尾 + 2 + 大小 + 2**
|
||||
|
||||
*结果*
|
||||
|
||||
## 解析响应
|
||||
|
||||
`(文本)`
|
||||
|
||||
**点 = text.codepoints(文本)**
|
||||
|
||||
**分隔 = text.codepoints("\r\n\r\n")**
|
||||
|
||||
**头部结束 = 找子串(点, 分隔, 0)**
|
||||
|
||||
**头部 = 切片(点, 0, 头部结束)**
|
||||
|
||||
**体 = 切片(点, 头部结束 + 4, 长度(点))**
|
||||
|
||||
**头部点 = text.codepoints(头部)**
|
||||
|
||||
**行列表 = []**
|
||||
|
||||
**行起 = 0**
|
||||
|
||||
**下一行 = 找子串(头部点, text.codepoints("\r\n"), 0)**
|
||||
|
||||
- `下一行 >= 0`
|
||||
|
||||
**行列表 = list.append(行列表, 切片(头部点, 行起, 下一行))**
|
||||
|
||||
**行起 = 下一行 + 2**
|
||||
|
||||
**下一行 = 找子串(头部点, text.codepoints("\r\n"), 行起)**
|
||||
|
||||
**行列表 = list.append(行列表, 切片(头部点, 行起, 长度(头部点)))**
|
||||
|
||||
**状态行 = 行列表[0]**
|
||||
|
||||
**状态点 = text.codepoints(状态行)**
|
||||
|
||||
**第一空格 = 找字符(状态点, 32, 0)**
|
||||
|
||||
**第二空格 = 找字符(状态点, 32, 第一空格 + 1)**
|
||||
|
||||
**状态 = 整数(切片(状态点, 第一空格 + 1, 第二空格))**
|
||||
|
||||
**原因 = 切片(状态点, 第二空格 + 1, 长度(状态点))**
|
||||
|
||||
**头 = {}**
|
||||
|
||||
**行号 = 1**
|
||||
|
||||
- `行号 < 长度(行列表)`
|
||||
|
||||
**行点 = text.codepoints(行列表[行号])**
|
||||
|
||||
**冒号 = 找字符(行点, 58, 0)**
|
||||
|
||||
1. `冒号 >= 0`
|
||||
|
||||
**名 = 切片(行点, 0, 冒号)**
|
||||
|
||||
**值 = 切片(行点, 冒号 + 2, 长度(行点))**
|
||||
|
||||
**头 = map.set(头, 名, 值)**
|
||||
|
||||
2. `true`
|
||||
|
||||
**忽略 = 0**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
**传输 = map.get(头, "Transfer-Encoding")**
|
||||
|
||||
**解码后 = 体**
|
||||
|
||||
1. `传输 == "chunked"`
|
||||
|
||||
**解码后 = 解码分块(体)**
|
||||
|
||||
2. `true`
|
||||
|
||||
**解码后 = 体**
|
||||
|
||||
*{状态: 状态, 原因: 原因, 头: 头, 体: 解码后}*
|
||||
|
||||
## 构建请求
|
||||
|
||||
`(方法, 路径, 头列表, 体)`
|
||||
|
||||
**请求 = 方法 + " " + 路径 + " HTTP/1.1\r\n"**
|
||||
|
||||
**行号 = 0**
|
||||
|
||||
- `行号 < 长度(头列表)`
|
||||
|
||||
**请求 = 请求 + 头列表[行号][0] + ": " + 头列表[行号][1] + "\r\n"**
|
||||
|
||||
**行号 = 行号 + 1**
|
||||
|
||||
*请求 + "\r\n" + 体*
|
||||
|
||||
## main
|
||||
|
||||
**响应文本 = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n6\r\n world\r\n0\r\n\r\n"**
|
||||
|
||||
**响应 = 解析响应(响应文本)**
|
||||
|
||||
**请求 = 构建请求("GET", "/health", [["Accept", "text/plain"], ["Host", "example.test"]], "")**
|
||||
|
||||
*[响应.状态, 响应.原因, 响应.头["Content-Type"], 响应.体, 请求]*
|
||||
|
||||
Reference in new issue
Block a user