XSD 1.0 datatype validation for MoonBit: lexical-space parsing and facet checking for the built-in simple types.
状态:v0.1.2。 44 个内置类型、12 个 facet、三种 variety、XSD 正则方言、 文档解析都已落地;W3C 套件 974 个用例全部一致。不做内容模型,边界写在「已知限制」里。
moon add ouoankang/moonbit-xsd-datatypesxs:dateTime 2026-02-30T00:00:00 -> 非法(2 月没有 30 日)
xs:decimal 1.230 -> 合法,规范化为 1.23
xs:integer 1.0 -> 非法(integer 的词法空间不含小数点)
xs:double INF -> 合法
xs:hexBinary 0F3 -> 非法(长度必须是偶数)moon check --deny-warn # 零警告
moon test # 68 个测试(67 单测 + 1 个 W3C 一致性)
# 直接验证内置类型
moon run --target js cmd/main -- dateTime 2026-02-30T00:00:00
# 读真实 XSD 文件,按其中声明的类型验证
moon run --target js cmd/main -- --schema examples/invoice.xsd amount 100.50 100000000$ moon run --target js cmd/main -- --schema examples/invoice.xsd amount 100.50 99999999.99 100000000 1.234
valid amount 100.50 => 100.5
valid amount 99999999.99 => 99999999.99
INVALID amount 100000000 => facet violation: value is above maxInclusive
INVALID amount 1.234 => facet violation: fractionDigits 3 exceeds 2
2 value(s) invalidTotal tests: 68, passed: 68, failed: 0.
w3c cases: 974/974 agreed, 0 schema errorsw3c cases: 974/974 agreed, 0 schema errorsThe use of length, minLength and maxLength on QName, NOTATION, and datatypes derived from them is deprecated.
python scripts/gen_w3c.py # 需要 GH_TOKEN 或已登录的 gh
moon test| 模块 | 状态 |
|---|---|
| Namespace-aware XML 读取 | 完成,17 测试 |
| 44 个内置类型 | 完成 |
| 12 个 facet | 完成 |
| 类型派生 restriction / list / union | 完成 |
| XML Schema 正则方言 | 完成(Unicode 类别为近似) |
| XSD 文档解析(simpleType / element,含匿名类型) | 完成 |
| CLI(内置类型 / 读 XSD 文件) | 完成 |
| W3C 测试套件 driver | 完成,974/974 一致 |
Install
Download zipXSD 1.0 datatype validation for MoonBit: lexical-space parsing and facet checking for the built-in simple types.