Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f558c1a47d | ||
|
|
e1b9c05a07 | ||
|
|
c7f358ae53 | ||
|
|
6578bf80a7 | ||
|
|
bcaa3b38a2 | ||
|
|
957edf9b0d | ||
|
|
250633fdca | ||
|
|
3c14251c28 | ||
|
|
b03e08ac20 | ||
|
|
86a2adc25b | ||
|
|
e48275df1c | ||
|
|
0775c1af3c | ||
|
|
b9bf22b19e | ||
|
|
e63ffa3f7c | ||
|
|
a94ebbcd44 | ||
|
|
e922dd6372 | ||
|
|
6f79b1345d |
No files matched your search
@@ -0,0 +1,32 @@
|
||||
# Unified Woodpecker CI for a source-only Marqdo component.
|
||||
#
|
||||
# The published `marqdo-ci-shell` image is the only runtime dependency: one
|
||||
# Ubuntu 24.04 base, the released CLI/Bundle, and common test tools. No image
|
||||
# variance, apt install, Rust toolchain download or sibling checkout.
|
||||
when:
|
||||
event: [push, pull_request, manual]
|
||||
|
||||
steps:
|
||||
test:
|
||||
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.6
|
||||
commands:
|
||||
- sh scripts/test.sh
|
||||
|
||||
package:
|
||||
# Deterministic dual-format (tar.gz + zip) packaging self-check through the
|
||||
# single ecosystem release implementation (marqdo#96/#106). The root
|
||||
# repository no longer builds (marqdo#102); this component lane is the
|
||||
# release verification. Ordinary push/PR receives no publish token.
|
||||
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.6
|
||||
depends_on: [test]
|
||||
commands:
|
||||
- |
|
||||
set -eu
|
||||
kit=$(mktemp -d)
|
||||
trap 'rm -rf "$kit"' EXIT
|
||||
base="https://git.cflmy.cn/cflmy/marqdo/raw/commit/0137baca340eb7fa78adf76d6ef2ba204a4b3ecd"
|
||||
curl -fsSL --retry 3 "$base/scripts/component-release/release.py" -o "$kit/release.py"
|
||||
echo "c57f104423f4965cd35395fe8018c6a9bdfba57c0fc8fc94bc7e5e40100e1081 $kit/release.py" | sha256sum -c -
|
||||
python3 "$kit/release.py" check \
|
||||
--repository "$CI_REPO" --component-id std-data --kind stdlib \
|
||||
--allow modules --allow README.md
|
||||
@@ -0,0 +1,28 @@
|
||||
# Protected publish lane: tag events only.
|
||||
#
|
||||
# Single ecosystem component release implementation (marqdo#96 M1, dual-format
|
||||
# archives per marqdo#106), pinned by root commit and file sha256. All packaging
|
||||
# and publishing happens in this CI/CD lane; maintainer machines never publish.
|
||||
when:
|
||||
event: [tag]
|
||||
|
||||
steps:
|
||||
publish:
|
||||
image: git.cflmy.cn/cflmy/marqdo-ci-shell:3.0.0-rc.6
|
||||
environment:
|
||||
GITEA_PUBLISH_TOKEN:
|
||||
from_secret: gitea_publish_token
|
||||
commands:
|
||||
- |
|
||||
set -eu
|
||||
test -n "${CI_COMMIT_TAG:?publish requires a tag event}"
|
||||
kit=$(mktemp -d)
|
||||
trap 'rm -rf "$kit"' EXIT
|
||||
base="https://git.cflmy.cn/cflmy/marqdo/raw/commit/0137baca340eb7fa78adf76d6ef2ba204a4b3ecd"
|
||||
curl -fsSL --retry 3 "$base/scripts/component-release/release.py" -o "$kit/release.py"
|
||||
echo "c57f104423f4965cd35395fe8018c6a9bdfba57c0fc8fc94bc7e5e40100e1081 $kit/release.py" | sha256sum -c -
|
||||
exec python3 "$kit/release.py" publish \
|
||||
--repository "$CI_REPO" --component-id std-data --kind stdlib \
|
||||
--allow modules --allow README.md --tag "$CI_COMMIT_TAG" \
|
||||
--dependency "id=cli,source_sha=63776735e924ade279cdf59d5c733dc24bfdabbb,asset_sha256=8dc0b006302e03c23451b8ea9f8a0fcdae8bf67c80c546bee2434bf69755bfe3" \
|
||||
--note "Platform-independent artifact: .tar.gz (Linux/POSIX) and .zip (Windows/macOS) contain the same reviewed files byte for byte; both are built and published by this Woodpecker tag lane."
|
||||
@@ -0,0 +1,37 @@
|
||||
<!-- marqdo:repo-conventions v1 -->
|
||||
# AGENTS.md — std-data
|
||||
|
||||
全局规范唯一来源:[marqdo 仓库开发规范](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/REPOSITORY-CONVENTIONS.md)。本文件只写本仓边界,不复制全局规范或合同正文。
|
||||
|
||||
## 1. 本仓定位与唯一权威
|
||||
|
||||
- catalog ID:`std-data`;父级:根;角色:stdlib;状态:active。
|
||||
- 职责/本仓拥有:JSON、CSV、TOML 与 GFM 数据交换;唯一模块源码
|
||||
- 本仓不拥有:CLI 语法/运行时、Bundle 打包实现、其它 stdlib 模块的算法或序列化
|
||||
- 权威输入/合同:真实 CLI `MARQDO_BIN` + 显式 `MARQDO_STDLIB_DIR` Bundle 的公开模块接口;根 Bundle 生产者
|
||||
|
||||
## 2. 必做 / 禁止
|
||||
|
||||
| 必做 | 禁止 |
|
||||
| --- | --- |
|
||||
| 只在本仓职责内修改,先开本仓工单 | 实现其它仓库功能,复制 parser/实现/合同 |
|
||||
| 用真实 CLI/制品与独立期望测试 | mock、字符串检查或原型冒充真实验收/PASS |
|
||||
| 依赖使用固定 SHA/摘要与显式输入 | 依赖父仓 checkout、兄弟仓相对路径、浮动分支 |
|
||||
| 未运行写 `UNVERIFIED` | 伪造 entry/版本/CI 徽章/gitlink/发布资产 |
|
||||
| 记录 SHA、制品摘要、平台、命令、退出码 | 提交密钥、凭证、构建产物或本地绝对路径 |
|
||||
| 跨仓变更走 C2 → B2 → A2 晋升 | 自动 tag/release/合并,或直接改父仓/兄弟仓 |
|
||||
|
||||
- 不新增第二 catalog/manifest/lock/版本表/发布流程;不为单功能拆仓或建空壳仓。
|
||||
- 不在本仓登记其它仓库后代路径;治理树最多两级 gitlink。
|
||||
|
||||
## 3. 构建、测试与证据
|
||||
|
||||
- CI/验收入口:`scripts/test.sh`(非交互、失败非零、不打印秘密、只写声明输出;构建与发布权限分离)。
|
||||
- 输入与依赖:真实 CLI `MARQDO_BIN` + 显式 `MARQDO_STDLIB_DIR` Bundle 的公开模块接口;根 Bundle 生产者
|
||||
- 交付:唯一模块源码 + 断言 + 确定性源码归档/证据(不强制二进制)
|
||||
- 证据:候选 SHA、依赖/制品 SHA-256、平台/工具链、命令与退出码、日志位置、测试范围;FAIL/UNVERIFIED 不得写成 PASS。
|
||||
|
||||
## 4. 工单路由
|
||||
|
||||
- 语言/模块加载/Bundle 协议 → `marqdo-cli`;Bundle 装配/路径 → 根 Bundle 生产者;模块语义 → 本仓。
|
||||
- 模块边界按迁移台账;不复制其它 stdlib 的算法或序列化实现。
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
| 发布路径 | 公开导入 | 职责 |
|
||||
| --- | --- | --- |
|
||||
| `data/json.mq.md` | `std:data/json` | 递归 JSON 解析/格式化(128 层上限、多值) |
|
||||
| `data/json.mq.md` | `std:data/json` | 递归 JSON 解析/格式化(128 层上限、多值);显式严格入口 `json.严格解析` 拒绝同层重复键(按解码后键比较,含转义等价)与无法表示为有限值的数字(`json.duplicate_key` / `json.non_finite_number`),普通 `json.解析` 行为不变。 |
|
||||
| `data/csv.mq.md` | `std:data/csv` | 引号单行/多行 CSV 解析与格式化 |
|
||||
| `data/table.mq.md` | `std:data/table` | Table 序列化:`连接片段`、`连接行`、`转义单元格`、`转GFM` |
|
||||
|
||||
@@ -26,6 +26,12 @@
|
||||
MARQDO_BIN=/path/to/verified/marqdo \
|
||||
MARQDO_STDLIB_DIR=/path/to/installed/bundle \
|
||||
scripts/test.sh
|
||||
|
||||
# Candidate-input strict suite: requires a Bundle built from this component's
|
||||
# current gitlink (the frozen ecosystem Bundle predates `json.严格解析`).
|
||||
MARQDO_BIN=/path/to/verified/marqdo \
|
||||
MARQDO_STDLIB_DIR=/path/to/candidate/bundle \
|
||||
scripts/test-strict.sh
|
||||
```
|
||||
|
||||
期望值取自迁移前基线 Bundle 的真实执行(JSON/CSV 分项断言、Table GFM 输出);修改期望值等于声明公开行为变化,必须单独评审。
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# std-data 严格 JSON 入口 — 2026-11-30
|
||||
|
||||
Issue: [marqdo-std-data#13](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/13)
|
||||
(consumer: `marqdo-ext-ai` AI-U2b). Branch `codex/issue-13-strict-json`.
|
||||
|
||||
## 交付
|
||||
|
||||
* `data/json.mq.md` 新增显式严格入口 `json.严格解析(文本)`:
|
||||
- 同一对象层重复键(按解码后键比较,`"a"` 与 `"\u0061"` 等价)→
|
||||
`json.duplicate_key`;
|
||||
- 无法表示为 binary64 有限值的数字(如 `1e400`、`-1e400`、`1.8e308`)→
|
||||
`json.non_finite_number`;`1e308`、`1.79e308` 仍为有限值;
|
||||
- 复用现有 tokenizer/解析器与 128 层深度上限,不新增第二套 JSON 语法。
|
||||
* 普通 `json.解析` 公开行为不变(默认套件 PASS)。
|
||||
* 候选输入自测:`tests/json-strict.mq.md` + `tests/cases-strict/json-strict.json`
|
||||
+ `scripts/test-strict.sh`。严格入口只存在于本仓当前模块,冻结生态 Bundle
|
||||
尚未含它,因此该套件与默认 `scripts/test.sh` 分离,由调用方显式传入候选
|
||||
Bundle(根 Bundle 生产者/晋升流水线)。
|
||||
* `scripts/run_cases.py` 支持 `MARQDO_STDLIB_CASES_DIR` 选择用例目录(默认不变)。
|
||||
|
||||
## 验证(真实执行)
|
||||
|
||||
环境:Linux x86_64 / glibc 2.43;CLI `marqdo 3.0.0-rc.6`(CLI candidate
|
||||
`0f87f856…` 构建);本仓模块 `sha256:0f099d0279e0ea8c5d40b00ff3f2ff3ff8bccad551d61898f1c995e1d6a29407`。
|
||||
|
||||
候选 Bundle:pinned `marqdo-stdlib 0.2.0` 叠加本仓当前 `modules/` 后重算 tree
|
||||
digest,得到 `sha256:4e47b0ff4b1e17d252cc74f20837014298fed4831050d65ca0c69f9cbdac55e9`
|
||||
(17 个 `.mq.md`;仅本地候选,不是官方 manifest)。
|
||||
|
||||
```text
|
||||
$ MARQDO_BIN=<rc.6> MARQDO_STDLIB_DIR=<candidate-bundle> sh scripts/test.sh
|
||||
PASS csv
|
||||
PASS json
|
||||
PASS table
|
||||
3 cases passed
|
||||
|
||||
$ MARQDO_BIN=<rc.6> MARQDO_STDLIB_DIR=<candidate-bundle> sh scripts/test-strict.sh
|
||||
PASS json-strict
|
||||
1 cases passed
|
||||
```
|
||||
|
||||
严格入口行为(真实 CLI 运行,逐项断言在 `tests/cases-strict/json-strict.json`):
|
||||
|
||||
| 输入 | 结果 |
|
||||
|---|---|
|
||||
| `{"b":3,"c":[1,2.5,true,null]}` | ok |
|
||||
| `[1,2.5,true,null,"x",{"b":3}]` | ok |
|
||||
| `{"a":1,"a":2}` | `json.duplicate_key` |
|
||||
| `{"a":1,"\u0061":2}` | `json.duplicate_key` |
|
||||
| `1e400` / `-1e400` | `json.non_finite_number` |
|
||||
| `1e308` / `1.79e308` | ok |
|
||||
| `1.8e308` | `json.non_finite_number` |
|
||||
| 普通 `json.解析("{\"a\":1,\"a\":2}")` | ok,`value={"a":2}`(行为不变) |
|
||||
|
||||
## 未验证 / 边界
|
||||
|
||||
* 冻结生态 Bundle 0.2.0 不含严格入口,仓库默认 CI 套件不覆盖新入口;候选
|
||||
Bundle 由根生产者/晋升流水线提供,本仓不自建第二份官方 manifest。
|
||||
* 未修改 CLI/其它组件;未新增跨仓依赖;未创建 release/tag。
|
||||
* 转义等价按解码后键比较(`\u0061`);未额外做 Unicode 规范化,与普通键语义一致。
|
||||
@@ -918,3 +918,386 @@ JSON 数字:可选负号、整数位、可选小数位、可选指数;含 ./
|
||||
|
||||
`end`
|
||||
`return {ok: true, value: 结果}`
|
||||
|
||||
## 严格解析
|
||||
|
||||
`params(文本)`
|
||||
|
||||
在普通解析之外显式选择严格语义:拒绝同一对象层内的重复键(按解码后
|
||||
键比较)与无法表示为有限值的数字;普通 json.解析 的公开行为不变。
|
||||
|
||||
**点 = text.codepoints(文本)**
|
||||
|
||||
`if 嵌套深度(文本) > 128`
|
||||
`return 失败("json.depth", "嵌套深度超过 128")`
|
||||
`end`
|
||||
|
||||
**检查 = 严格检查值(点, 0)**
|
||||
|
||||
`if not 检查.ok`
|
||||
`return 检查`
|
||||
`end`
|
||||
|
||||
**位置 = 跳过空白(点, 检查.next)**
|
||||
|
||||
`if 位置 != 长度(点)`
|
||||
`return 失败("json.trailing", "值后存在多余输入")`
|
||||
`end`
|
||||
|
||||
`return 解析(文本)`
|
||||
|
||||
## 严格检查值
|
||||
|
||||
`params(点, 位置)`
|
||||
|
||||
**位置 = 跳过空白(点, 位置)**
|
||||
|
||||
`if 位置 >= 长度(点)`
|
||||
`return 失败("json.unexpected_eof", "需要值")`
|
||||
`end`
|
||||
|
||||
**码点 = 点[位置]**
|
||||
|
||||
`if 码点 == 123`
|
||||
`return 严格检查对象(点, 位置 + 1)`
|
||||
`else`
|
||||
`if 码点 == 91`
|
||||
`return 严格检查数组(点, 位置 + 1)`
|
||||
`else`
|
||||
`if 码点 == 34`
|
||||
**文本结果 = 解析字符串(点, 位置)**
|
||||
`if not 文本结果.ok`
|
||||
`return 文本结果`
|
||||
`end`
|
||||
`return 成功值(None, 文本结果.next)`
|
||||
`else`
|
||||
`if 码点 == 45 or 是数字(码点)`
|
||||
**开始 = 位置**
|
||||
**数字结果 = 解析数字(点, 位置)**
|
||||
`if not 数字结果.ok`
|
||||
`return 数字结果`
|
||||
`end`
|
||||
**原文 = 片段(点, 开始, 数字结果.next)**
|
||||
`if not 有限数字文本(原文)`
|
||||
`return 失败("json.non_finite_number", "数字无法表示为有限值")`
|
||||
`end`
|
||||
`return 成功值(None, 数字结果.next)`
|
||||
`else`
|
||||
`return 解析值(点, 位置)`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
|
||||
## 严格检查对象
|
||||
|
||||
`params(点, 位置)`
|
||||
`return 严格检查对象项(点, 位置, {})`
|
||||
|
||||
## 严格检查对象项
|
||||
|
||||
`params(点, 位置, 已见)`
|
||||
|
||||
**位置 = 跳过空白(点, 位置)**
|
||||
|
||||
`if 位置 >= 长度(点)`
|
||||
`return 失败("json.unexpected_eof", "对象未闭合")`
|
||||
`end`
|
||||
|
||||
**当前 = text.from_codepoint(点[位置])**
|
||||
|
||||
`if 当前 == "}"`
|
||||
`return 成功值(None, 位置 + 1)`
|
||||
`end`
|
||||
|
||||
**键结果 = 解析字符串(点, 位置)**
|
||||
|
||||
`if not 键结果.ok`
|
||||
`return 键结果`
|
||||
`end`
|
||||
|
||||
**键 = 键结果.value**
|
||||
|
||||
`if map.has(已见, 键)`
|
||||
`return 失败("json.duplicate_key", "同一对象层内存在重复键")`
|
||||
`end`
|
||||
|
||||
**更新的已见 = map.set(已见, 键, true)**
|
||||
|
||||
**位置 = 跳过空白(点, 键结果.next)**
|
||||
|
||||
`if 位置 >= 长度(点)`
|
||||
`return 失败("json.unexpected_eof", "对象缺少冒号")`
|
||||
`else`
|
||||
`if text.from_codepoint(点[位置]) != ":"`
|
||||
`return 失败("json.invalid_object", "对象缺少冒号")`
|
||||
`end`
|
||||
`end`
|
||||
|
||||
**值检查 = 严格检查值(点, 位置 + 1)**
|
||||
|
||||
`if not 值检查.ok`
|
||||
`return 值检查`
|
||||
`end`
|
||||
|
||||
**位置 = 跳过空白(点, 值检查.next)**
|
||||
|
||||
`if 位置 >= 长度(点)`
|
||||
`return 失败("json.unexpected_eof", "对象未闭合")`
|
||||
`end`
|
||||
|
||||
**分隔 = text.from_codepoint(点[位置])**
|
||||
|
||||
`if 分隔 == ","`
|
||||
`return 严格检查对象项(点, 位置 + 1, 更新的已见)`
|
||||
`else`
|
||||
`if 分隔 == "}"`
|
||||
`return 成功值(None, 位置 + 1)`
|
||||
`else`
|
||||
`return 失败("json.invalid_object", "对象缺少逗号或 }")`
|
||||
`end`
|
||||
`end`
|
||||
|
||||
## 严格检查数组
|
||||
|
||||
`params(点, 位置)`
|
||||
`return 严格检查数组项(点, 位置)`
|
||||
|
||||
## 严格检查数组项
|
||||
|
||||
`params(点, 位置)`
|
||||
|
||||
**位置 = 跳过空白(点, 位置)**
|
||||
|
||||
`if 位置 >= 长度(点)`
|
||||
`return 失败("json.unexpected_eof", "数组未闭合")`
|
||||
`end`
|
||||
|
||||
**当前 = text.from_codepoint(点[位置])**
|
||||
|
||||
`if 当前 == "]"`
|
||||
`return 成功值(None, 位置 + 1)`
|
||||
`end`
|
||||
|
||||
**项检查 = 严格检查值(点, 位置)**
|
||||
|
||||
`if not 项检查.ok`
|
||||
`return 项检查`
|
||||
`end`
|
||||
|
||||
**位置 = 跳过空白(点, 项检查.next)**
|
||||
|
||||
`if 位置 >= 长度(点)`
|
||||
`return 失败("json.unexpected_eof", "数组未闭合")`
|
||||
`end`
|
||||
|
||||
**分隔 = text.from_codepoint(点[位置])**
|
||||
|
||||
`if 分隔 == ","`
|
||||
`return 严格检查数组项(点, 位置 + 1)`
|
||||
`else`
|
||||
`if 分隔 == "]"`
|
||||
`return 成功值(None, 位置 + 1)`
|
||||
`else`
|
||||
`return 失败("json.invalid_array", "数组缺少逗号或 ]")`
|
||||
`end`
|
||||
`end`
|
||||
|
||||
## 有限数字文本
|
||||
|
||||
`params(原文)`
|
||||
|
||||
判断 JSON 数字原文是否可用 binary64 有限值表示:十进制量级超过 308
|
||||
即溢出;量级正好 308 时与 binary64 最大值 1.7976931348623157e308 的
|
||||
显著数字比较。下溢为 0 仍属有限值。
|
||||
|
||||
**点 = text.codepoints(原文)**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
`if 下标 < 长度(点) and 点[下标] == 45`
|
||||
**下标 = 下标 + 1**
|
||||
`else`
|
||||
`if true`
|
||||
**忽略符号 = 0**
|
||||
`end`
|
||||
`end`
|
||||
|
||||
**整数起 = 下标**
|
||||
|
||||
`while 下标 < 长度(点) and 是数字(点[下标])`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
|
||||
**整数终 = 下标**
|
||||
|
||||
**小数起 = 下标**
|
||||
|
||||
`if 下标 < 长度(点) and 点[下标] == 46`
|
||||
**下标 = 下标 + 1**
|
||||
**小数起 = 下标**
|
||||
`while 下标 < 长度(点) and 是数字(点[下标])`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`else`
|
||||
`if true`
|
||||
**忽略小数 = 0**
|
||||
`end`
|
||||
`end`
|
||||
|
||||
**小数终 = 下标**
|
||||
|
||||
**指数 = 0**
|
||||
|
||||
`if 下标 < 长度(点) and (点[下标] == 101 or 点[下标] == 69)`
|
||||
**下标 = 下标 + 1**
|
||||
**指数负 = false**
|
||||
`if 下标 < 长度(点) and 点[下标] == 43`
|
||||
**下标 = 下标 + 1**
|
||||
`else`
|
||||
`if 下标 < 长度(点) and 点[下标] == 45`
|
||||
**指数负 = true**
|
||||
**下标 = 下标 + 1**
|
||||
`else`
|
||||
`if true`
|
||||
**忽略指数符号 = 0**
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`while 下标 < 长度(点) and 是数字(点[下标])`
|
||||
`if 指数 < 100000`
|
||||
**指数 = 指数 * 10 + (点[下标] - 48)**
|
||||
`else`
|
||||
`if true`
|
||||
**指数 = 100000**
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`if 指数负`
|
||||
**指数 = 0 - 指数**
|
||||
`end`
|
||||
`else`
|
||||
`if true`
|
||||
**忽略指数 = 0**
|
||||
`end`
|
||||
`end`
|
||||
|
||||
**有效 = 严格有效数字(点, 整数起, 整数终, 小数起, 小数终)**
|
||||
|
||||
`if 长度(有效) == 0`
|
||||
`return true`
|
||||
`end`
|
||||
|
||||
**量级 = 0**
|
||||
|
||||
`if 有效首位整数(点, 整数起, 整数终)`
|
||||
**量级 = (整数终 - 有效起点(点, 整数起, 整数终)) - 1 + 指数**
|
||||
`else`
|
||||
**量级 = (0 - (有效起点(点, 小数起, 小数终) - 小数起 + 1)) + 指数**
|
||||
`end`
|
||||
|
||||
`if 量级 > 308`
|
||||
`return false`
|
||||
`end`
|
||||
|
||||
`if 量级 < 308`
|
||||
`return true`
|
||||
`end`
|
||||
|
||||
`return 有效数字不超过上限(有效)`
|
||||
|
||||
## 有效首位整数
|
||||
|
||||
`params(点, 起点, 终点)`
|
||||
|
||||
**下标 = 起点**
|
||||
|
||||
`while 下标 < 终点`
|
||||
`if 点[下标] != 48`
|
||||
`return true`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`return false`
|
||||
|
||||
## 有效起点
|
||||
|
||||
`params(点, 起点, 终点)`
|
||||
|
||||
**下标 = 起点**
|
||||
|
||||
`while 下标 < 终点`
|
||||
`if 点[下标] != 48`
|
||||
`return 下标`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`return 终点`
|
||||
|
||||
## 严格有效数字
|
||||
|
||||
`params(点, 整数起, 整数终, 小数起, 小数终)`
|
||||
|
||||
**有效 = []**
|
||||
|
||||
**开始 = false**
|
||||
|
||||
**下标 = 整数起**
|
||||
|
||||
`while 下标 < 整数终`
|
||||
`if 开始 or 点[下标] != 48`
|
||||
**开始 = true**
|
||||
`if 长度(有效) < 17`
|
||||
**有效 = list.append(有效, 点[下标] - 48)**
|
||||
`else`
|
||||
`if true`
|
||||
**忽略多余 = 0**
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
|
||||
**下标 = 小数起**
|
||||
|
||||
`while 下标 < 小数终`
|
||||
`if 开始 or 点[下标] != 48`
|
||||
**开始 = true**
|
||||
`if 长度(有效) < 17`
|
||||
**有效 = list.append(有效, 点[下标] - 48)**
|
||||
`else`
|
||||
`if true`
|
||||
**忽略多余 = 0**
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
|
||||
`return 有效`
|
||||
|
||||
## 有效数字不超过上限
|
||||
|
||||
`params(有效)`
|
||||
|
||||
**上限 = text.codepoints("17976931348623157")**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
`while 下标 < 17`
|
||||
**数字 = 0**
|
||||
`if 下标 < 长度(有效)`
|
||||
**数字 = 有效[下标]**
|
||||
`end`
|
||||
**限制 = 上限[下标] - 48**
|
||||
`if 数字 > 限制`
|
||||
`return false`
|
||||
`end`
|
||||
`if 数字 < 限制`
|
||||
`return true`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
|
||||
`return true`
|
||||
@@ -157,6 +157,9 @@ def _dig(value, pointer: str):
|
||||
|
||||
|
||||
def main() -> int:
|
||||
global CASES
|
||||
if os.environ.get("MARQDO_STDLIB_CASES_DIR"):
|
||||
CASES = Path(os.environ["MARQDO_STDLIB_CASES_DIR"]).resolve()
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("cases", nargs="*", help="case names to run")
|
||||
args = parser.parse_args()
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# Candidate-input strict-mode self-test.
|
||||
#
|
||||
# Strict JSON rejects duplicate keys and non-finite numbers. Those symbols only
|
||||
# exist in a Bundle that contains this component's current modules, so this
|
||||
# suite is separate from the default `scripts/test.sh` (which must keep running
|
||||
# against the frozen ecosystem Bundle). Callers pass an explicit candidate
|
||||
# Bundle produced from the current component gitlink, e.g. by the root repo's
|
||||
# `scripts/build-stdlib.py` / acceptance pipeline.
|
||||
set -eu
|
||||
: "${MARQDO_BIN:?set MARQDO_BIN to the verified marqdo executable}"
|
||||
: "${MARQDO_STDLIB_DIR:?set MARQDO_STDLIB_DIR to a candidate Bundle containing current modules}"
|
||||
MARQDO_STDLIB_CASES_DIR="$(CDPATH= cd -- "$(dirname -- "$0")/../tests/cases-strict" && pwd)"
|
||||
export MARQDO_STDLIB_CASES_DIR
|
||||
exec python3 "$(dirname "$0")/run_cases.py" "$@"
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"schema": "marqdo.stdlib-test-case",
|
||||
"schema_version": 1,
|
||||
"name": "json-strict",
|
||||
"file": "json-strict.mq.md",
|
||||
"require_module": "data/json.mq.md",
|
||||
"args": [],
|
||||
"stdin": "",
|
||||
"env": {},
|
||||
"expected_stdout": "",
|
||||
"expected_terminal": {
|
||||
"type": "list",
|
||||
"items": [
|
||||
{
|
||||
"type": "bool",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"type": "bool",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"type": "bool",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "json.duplicate_key"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "json.duplicate_key"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "json.non_finite_number"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "json.non_finite_number"
|
||||
},
|
||||
{
|
||||
"type": "bool",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"type": "bool",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"type": "bool",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"type": "map",
|
||||
"entries": {
|
||||
"a": {
|
||||
"type": "int",
|
||||
"decimal": "2"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
import:
|
||||
json: "std:data/json"
|
||||
---
|
||||
|
||||
# @exec 严格解析
|
||||
|
||||
## main
|
||||
|
||||
**`合法对象 = json.严格解析("{\"b\":3,\"c\":[1,2.5,true,null]}")`**
|
||||
|
||||
**`合法数组 = json.严格解析("[1,2.5,true,null,\"x\",{\"b\":3}]")`**
|
||||
|
||||
**`重复键 = json.严格解析("{\"a\":1,\"a\":2}")`**
|
||||
|
||||
**`转义等价重复 = json.严格解析("{\"a\":1,\"\\u0061\":2}")`**
|
||||
|
||||
**`溢出 = json.严格解析("1e400")`**
|
||||
|
||||
**`负溢出 = json.严格解析("-1e400")`**
|
||||
|
||||
**`最大量级 = json.严格解析("1.79e308")`**
|
||||
|
||||
**`超出最大量级 = json.严格解析("1.8e308")`**
|
||||
|
||||
**`普通入口 = json.解析("{\"a\":1,\"a\":2}")`**
|
||||
|
||||
`return [合法对象.ok, 合法数组.ok, 重复键.ok, 重复键.code, 转义等价重复.code, 溢出.code, 负溢出.code, 最大量级.ok, 超出最大量级.ok, 普通入口.ok, 普通入口.value]`
|
||||
Reference in new issue
Block a user