Skip to content

docs(spec): add expression specification aligned with dev @ 3b84ef2 - #54

Draft
hydroroll-bot wants to merge 2 commits into
devfrom
krypton/docs-spec-add-expression-specification-a-jccc59f
Draft

hydroroll-bot wants to merge 2 commits into
devfrom
krypton/docs-spec-add-expression-specification-a-jccc59f

Conversation

@hydroroll-bot

@hydroroll-bot hydroroll-bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

内容

新增 docs/source/expression-spec.rst(1042 行),挂进 docs/source/index.rst 的 toctree。一套语法:1.x 现行语法为正文正式定义,2.0 新特性并入同一套词法/产生式/语义章节,每项标「已实现」或「未实现(issue #N)」。体例:词法表、优先级表、pest PEG 产生式、错误码表、示例带期望结果。

对上一轮审查意见的回应

  1. docs/rfcs/0001-v2-target.pest 是否存在:存在,且是 0001 号提案的附件(git cat-file -e 3b84ef2:docs/rfcs/0001-v2-target.pest 通过;git ls-files docs/rfcs 可见 0001–0006 各提案及其附件 .pest/.json/.pyi)。docs/rfcs 下确实只有 0001–0006 六份提案。已在「写法约定」里写明这是 0001 的附件、不是另一份 RFC,避免误读。
  2. 1 d 6:已从 3.3 与第 7 节示例表删除,不再给「等价 1d6」的推导结论;3.3 只陈述词法规则(silent WHITESPACE、number/dice_sides 为 atomic),并把「空白宽容度需补 conformance 用例」列入第 9 节 TODO 与本文末尾遗留项。
  3. PR 回执:见文末「交付回执」,含 commit 与遗留未核实项;PR 号在开成草稿后回读 API 补报。

核对来源(dev @ 3b84ef2)

src/oneroll/grammar.pest、docs/rfcs/0001-v2-target.pest、src/calculator.rs、src/errors.rs、tests/conformance/v1.json(46 条单表达式 + 5 条 program 用例)、issue tracker。引用的 #3/#7/#15/#16/#24/#26/#29/#37–#43/#51 均为真实 issue,标题已比对。

关键修正

已实现 / 未实现对 issue

范围 状态 issue
1.x 词法、文法、算术、15 个修饰符、错误码、预算 已实现 —
v2 Program / 分号指令 未实现 #38
typed values、闭区间、不可变变量 未实现 #39
数字范围骰、加权列表骰 未实现 #40
keep / filter / sort / count / unique 未实现 #15
bounded explode / reroll / keep-and-explode 未实现 #24
Pratt 分层与 canonical 表达式 未实现 #16
validator 与 filter 作用域 未实现 #41
merge / bind / occurrences / paint / split / group 未实现 #42
repeat / conditional 未实现 #43
typed Python 异常层级 未实现 #26
v1→v2 诊断与迁移 未实现 #29
v2.0 RC→GA 清单 未开始 #37
精确概率分析边界 未定 #3
v2 表面语法是否重议 未定 #51

K 的已知偏差已记录:calculator.rs 里 K 只取高 n、不 explode,语料 keep_and_explode_incomplete 以 known_defect 固定(#24)。

待拍板

  1. 精确概率分析边界([RFC-0006] Program Sampling and Exact Analysis Scope #3):!/R 无次数上限,只能靠预算终止;可精确分析的范围需先定。
  2. v2 表面语法是否按 Reconsider v2 surface syntax for non-code hosts and LLM tool-call recall #51 重议:本文 v2 部分暂以 RFC-0001 的 0001-v2-target.pest 为准,若 Reconsider v2 surface syntax for non-code hosts and LLM tool-call recall #51 改动则 3.5/4.5/5.2 同步。
  3. values_list([1,2])无独立 issue 归属,标 TODO。

后续细节讨论会开 tracking issue,PR 随讨论同步更新;草稿状态,不合并。

验证

  • 已做:逐条对照源码与语料;脚本比对 3.4/4.4 两表、示例 total 与 v1.json、错误码集合与 errors.rs、引用语料 id 是否存在;git diff --check、UTF-8、无 tab。
  • 未做:cargo test(无 crates 缓存/网络)、sphinx-build -W(无 sphinx/docutils)、python -m unittest(缺 oneroll 扩展与 jsonschema)。CI docs workflow 若报 RST 告警会跟进修。

交付回执

  • 分支:dev(基于 3b84ef2)
  • commit:9ea2adb93b539b84f80ef00c8b80a1fea93f74d8
  • PR:本 PR(草稿);号码在开成后回读 API 补记于对话
  • 遗留未核实项:① 空白宽容度无 conformance 用例(不写等价结论);② values_list 的 issue 归属 TODO;③ 1d1! 期望依赖默认 generated_values = 10000 的预算实现,未实跑;④ 文档未经 sphinx-build -W 构建。

由 Krypton(hydroroll-bot)应群里可信成员的请求自动生成,是草稿,需要人审查后再合并。

Summary by Sourcery

Document the expression language and its planned evolution with an implementation-aligned specification.

Enhancements:

  • Add a comprehensive expression specification covering the implemented 1.x language and planned 2.0 syntax, semantics, modifiers, errors, budgets, examples, and implementation status.
  • Record known discrepancies, unresolved design questions, and issue references to clarify current behavior and guide future v2 work.

Documentation:

  • Include the new expression specification in the documentation site's table of contents.

Add docs/source/expression-spec.rst and hook it into the documentation
toctree. The spec is written against the files at 3b84ef2 (grammar.pest,
calculator.rs, errors.rs, tests/conformance/v1.json) rather than from
memory, and marks every rule as implemented or 未实现(issue #N).

Corrections made during review of the first draft:
- 3.4 and 4.4 share one 15-row modifier set and order
- 1d1! follows the explode loop -> limit.generated_values, not total = 1
- no unverified spaced-dice example; the whitespace rule is stated only at
  the lexical level and flagged for a conformance case
- section 3.2 defines factor for both 1.x (dice_term) and v2 (primary)
- 4.2 maps every DiceError to Python ValueError via From<DiceError> for PyErr
- only real files referenced; 0001-v2-target.pest is documented as an
  attachment of RFC-0001, not a separate proposal
- issue numbers checked against the tracker
- no scrape date in the header, only dev @ 3b84ef2
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This documentation-only PR adds a source-aligned, 1041-line expression specification covering current 1.x behavior and proposed v2 syntax/semantics, with implementation status, issue links, examples, edge cases, and review provenance, then links it from the main documentation index.

File-Level Changes

Change Details Files
Adds a comprehensive expression specification and exposes it through the documentation table of contents.
  • Defines 1.x lexical, grammar, precedence, modifier, semantic, error, budget, and example behavior based on the dev sources and conformance corpus.
  • Documents v2 target syntax and semantics alongside 1.x, explicitly marking implemented, unimplemented, undecided, and known-defect areas with issue references.
  • Records important compatibility and edge-case behavior, including precedence differences, modifier consistency, infinite explode/reroll budget handling, Python error conversion, and the incomplete K behavior.
  • Adds review provenance, validation results, unresolved questions, and limitations of the unexecuted test/build checks.
  • Adds the specification page to the documentation toctree.
docs/source/expression-spec.rst
docs/source/index.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@hydroroll-bot
hydroroll-bot force-pushed the krypton/docs-spec-add-expression-specification-a-jccc59f branch from f776394 to 34d3a06 Compare October 22, 2026 02:20
@HsiangNianian

Copy link
Copy Markdown
Member

中文正文里的行内标记(``代码``、**粗体**、:doc:`...`)紧贴汉字或全角标点时
docutils 不认边界,``sphinx-build -W`` 因此报 31 条 warning,CI 的 Quality
job 直接失败。逐处补 ``\ `` 转义空格,并顺带处理三类别的问题:

- 行内标记不能嵌套(reST 的限制),把 ``**``1.x``:…**`` 这类改成两个标记
  相邻但不嵌套的写法;
- 行内字面量不能跨行,把跨行的 ``schema_version = "2.0"`` 收进同一行;
- 以空白开头/结尾的字面量(``  1d1  ``)无法用 `` `` `` 表示,改成
  ``1d1``(首尾带空格)并在期望列写明首尾空白忽略。

标题下划线按 docutils 的 column_width 补齐。本地 ``sphinx-build -W`` 现在
零 docutils 警告,只剩 intersphinx 拉不到 objects.inv 的网络警告(沙箱无外网)。
@hydroroll-bot

Copy link
Copy Markdown
Member Author

@HsiangNianian 看了一下你贴的 job(Quality / sphinx-build -W --keep-going),失败原因是文档警告,不是代码问题。已在分支上改好并重跑。

失败原因

docs/source/expression-spec.rst 是中文正文,行内标记紧贴汉字或全角标点时 docutils 不认边界:

expression-spec.rst:30: WARNING: Inline strong start-string without end-string.
expression-spec.rst:174: WARNING: Inline literal start-string without end-string.
... 共 31 条 docutils 警告 + 1 条 Title underline too short

-W 把它们当错误,job 就红了。另外还有一批「没报 warning 但实际渲染坏了」的地方:-W 只在部分情况下报警,另一批行内字面量直接被当成普通文本,页面上会露出原始的 `` 反引号(本地对比旧构建和新构建,旧版正文里有 71 处这样的裸反引号)。

这次改了什么(只动这一个文件,198 行)

  1. 逐处补 \ 转义空格,让标记边界成立:**已实现**\ :、语料 ``id``\ 。、(\ ``x``\ )。
  2. 行内标记不能嵌套(reST 本身的限制,**``1.x``:…** 这类会退化成纯文本),改成两个标记相邻、不嵌套的写法,例如
    • 3. **issue 归属**(``values_list``)\ :…
    • 1. **逐骰、按源码顺序处理全部修饰符**(``!`` / ``e``)\ :…
    • **``1.x``**:单层… → 1.x\ :**单层、左结合,已实现**\ 。
      只调整了强调的范围,句子意思和术语没变。
  3. 行内字面量不能跨行:把跨行的 schema_version = "2.0" 收进同一行(顺便重排了那一段的折行)。
  4. * - `` 1d1 `` 这种以空白开头/结尾的字面量没法用 表示,改成 `1d1``\ (首尾带空格)`,期望列本来就写着「首尾空白忽略」。
  5. 三处标题下划线按 docutils 的 column_width 补长(含全角字符时一个汉字算两格)。

验证

uv sync --all-groups --frozen
uv run --frozen sphinx-build -W --keep-going -b html docs/source docs/_build/html
  • docutils 警告:0(改之前 32 条)。
  • 只剩一条 failed to reach any of the inventories … docs.python.org/objects.inv——我这个环境没有外网,requests.exceptions.ProxyError;CI 有网,这条不会出现。
  • 渲染结果对照旧构建:裸反引号和裸 ** 已经没有了(剩下的 ** 都是 2 ** 3、** 这类字面量内容,正常)。
  • uv run --frozen ruff check .:All checks passed。

说明

  • 转义空格在页面上会占一个空格(( 3b84ef25610a ) 这种),这是 reST + 中文的固有毛病,不是排版失误;如果不想看到这些空格,只能给 docutils 开 character_level_inline_markup 或改文案语序,那属于另一件事,这次没动。
  • 没有为了凑 80 列重新折行,避免在 \ 边界处断行产生新问题;改动行长略增(最多 82 列,原文件本来就有 109 列的行)。
  • 如果 CI 还红,麻烦再贴一下 job 链接,我按日志继续。

按审查意见追加了 1 个提交(docs(spec): fix reST inline markup so the docs build passes -W)。

@HsiangNianian

HsiangNianian commented Oct 22, 2026 via email

Copy link
Copy Markdown
Member

@hydroroll-bot

Copy link
Copy Markdown
Member Author

PDF 版本已经出好了,交付说明同步在这里。

成品

压缩包在群里发了:OneRoll-docs-pdf-1.3.5.zip,解压后两本:

  • OneRoll-docs-v1.3.5.pdf —— 整本 156 页
  • OneRoll-expression-spec-v1.3.5.pdf —— 表达式规范单篇 16 页,就是本 PR 改动的那篇

封面、带页码的目录、每章另起一页都有;目录和交叉引用可点击跳转,书签按「章 / 节」两层生成。

生成方式

不是 LaTeX 排版,是 HTML 转打印:

uv run sphinx-build -b html -D html_theme=basic docs/source docs/_build/html

把各页正文按 toctree 顺序拼成一个文档,再交给无头 Chrome 按 A4 打印成 PDF。-W 构建这条路径本身也是 0 warning,除了沙箱无网连不上 docs.python.org 的 intersphinx 提示(不影响产出)。

已知限制

  • 页脚只能用英文:往 PDF 里嵌中文页脚字体太麻烦,正文中文显示正常。
  • 文档源码这次没有需要改的地方,所以本分支没有追加新提交,成品直接以文件形式交付。

要是希望把这条 PDF 流水线固化进 CI(比如 release 时自动产出一份),可以另开 issue,我再按流程提。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants