Skip to content

feat(parser)!: パーサーに診断(diagnostics)機能を追加#23

Merged
r74tech merged 15 commits intodevelopfrom
feature/parse-diagnostics
Feb 12, 2026
Merged

feat(parser)!: パーサーに診断(diagnostics)機能を追加#23
r74tech merged 15 commits intodevelopfrom
feature/parse-diagnostics

Conversation

@r74tech
Copy link
Owner

@r74tech r74tech commented Feb 12, 2026

Summary

parse() の戻り値を SyntaxTree から ParseResult { ast, diagnostics } に変更し、構文エラーを検出・報告する診断基盤を導入。

  • Diagnostic 型と ParseResult 型を @wdprlib/ast に追加
  • 閉じタグ不足(unclosed-block)、インラインブロック要素(inline-block-element)、閉じ忘れコメント(unclosed-comment)の3種の診断コードを実装
  • ブロック要素(div, collapsible, tabview, tab, align, iftags, code, math, html, embed, module, table, list, bibliography)とインライン要素(span, size, anchor, footnote, comment)を網羅
  • div の outside-in マッチングを budget システムで実装(Wikidot の挙動を再現)
  • div 隣接 paragraph の <p> 抑制を post-processing で実装

Breaking Changes

  • parse() の戻り値が SyntaxTreeParseResult に変更
  • 移行: parse(input)parse(input).ast で従来の SyntaxTree を取得可能
  • parse(input).diagnostics で診断情報の配列を取得

parse()の診断基盤となる型定義を@wdprlib/astに追加。
Diagnostic(severity/code/message/position)とParseResult(ast + diagnostics)を定義。
BREAKING CHANGE: parse()がSyntaxTreeではなくParseResult { ast, diagnostics }を返すように変更。
ParseContextにdiagnostics配列を追加。
テストファイルにparseAst()ヘルパーを追加し、parse().astでSyntaxTreeを取得するように変更。
wdmock-cfのpipeline.tsでもparse().astを使用し、resolveModulesのコールバックをラップ。
div, collapsible, tabview/tab, align, iftagsの各ブロックルールに
閉じタグ不足のwarning診断を追加。
consumeFailedDivにインラインブロック要素のerror診断を追加。
メッセージは英語で統一し、codeフィールドでi18n対応可能。
tabviewルールのEOFハンドリングバグも修正
orphan-li、リスト内li閉じ忘れ、左寄せalignのunclosedテストを追加
expected-diagnostics.jsonがあるfail fixtureのdiagnosticsを検証する仕組みを追加
Wikidotのdivブロックは外側から内側へペアリングされる。
opens > closesの場合、最も内側の余剰openはテキスト化される。

- ParseContextにdivClosesBudgetフィールドを追加
- budget=0でdivルールがfail→テキストにフォールバック
- countDivCloses()で残りclose数を計算
- consumeFailedDivのスキャンを改善: valid divブロック開始時に停止
- 吸収範囲内の追加[[div]]パターンにinline-block-element diagnostic発行
Wikidotではdivブロックに直接隣接するparagraphの<p>ラッピングが
抑制される。間に他のブロック要素がある場合は<p>を維持する。

- suppressDivAdjacentParagraphs()をpostprocessモジュールに追加
- トップレベルでのみ適用(div内部のparagraphは維持)
- div後に続くunwrapped contentにはline-breakを先頭に付与
- expected.json: budget systemと<p>抑制を反映したAST
- expected-diagnostics.json: case 1/2両方のinline-block-element
- diagnostics.test.ts: budget systemの動作に合わせてテストを修正
  - 余剰openはunclosed-blockではなくテキスト化される
blockCommentがsuccess:falseを返すとparagraph fallback経由で
inlineCommentが同じdiagnosticを発行していた。
block側のdiagnostic pushを除去し、inline側に一元化。
@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wdpr-demo-v1-files e5f0dcd Commit Preview URL

Branch Preview URL
Feb 12 2026, 01:59 PM

@r74tech r74tech merged commit a5dc954 into develop Feb 12, 2026
8 checks passed
@r74tech r74tech deleted the feature/parse-diagnostics branch February 12, 2026 14:05
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.

1 participant