feat(parser): [[iftags]]のtext-level preprocess pass追加#44
Merged
Conversation
include展開後・parse前に [[iftags ...]]X[[/iftags]] を pageTags 評価で text-levelに expand する pass を追加。AST levelの resolveIfTags では到達 できない、ブロックopener属性内の iftags (例: [[div_ class="x" [[iftags +foo]]style="display:none;"[[/iftags]]]]) を 扱えるようにする。 新規: - preprocessIftags(source, pageTags): pageTags=null → no-op、それ以外は innermost-firstに [[iftags]] を expand - raw region保護: [[code]] (unclosed時 EOFまで), [[html]] (closingあり時のみ), @<...>@ (同一行), @@..@@ (同一行) - placeholder sentinelは Private Use Area chars。source内に既出する場合は makeUniqueSentinels で衝突回避 Wikidot rule order との整合: - Wikidot (lib/Text_Wiki/Text/Wiki.php line 52-133) では Iftags (index 11) が Comment (index 12) より先に走る。すなわち comment 内の iftags も 通常通り展開され、その後 Comment rule が non-greedy 正規表現 ([!--(.*?)--]、Comment.php line 44) で剥がす。本 pass は comment を マスクせず、この順序を保つ。 - Code / Raw (@@/@<) は Wikidot 順序で Iftags より前にあるので、これらは 本 pass で mask (= 内部の [[iftags]] を保護)。 性能: - INNERMOST_IFTAGS_PATTERN に g flag を付け、1 passで全 innermost を まとめて置換 (兄弟 iftags が多い場合の O(n^2) 再走査を解消)。 - raw region mask の opener / closer を sticky (y) + lastIndex 探索に 変更し、per-`[[` の source.slice(i) (O(n) 確保) を排除。 公開 API: - @wdprlib/parser の preprocessIftags をexport パイプライン更新: - examples/wdmock-cf: resolveIncludes → getPageTags → preprocessIftags → parse → resolveModules の順序に変更 test: unit + integration、すべて通過。
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wdpr-demo-v1 | 9e4963e | Commit Preview URL Branch Preview URL |
Jun 03 2026, 03:47 AM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
decompiler-preview | 9e4963e | Commit Preview URL Branch Preview URL |
Jun 03 2026, 03:46 AM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wdpr-demo-v1-files | 9e4963e | Commit Preview URL Branch Preview URL |
Jun 03 2026, 03:46 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[[iftags ...]]X[[/iftags]]を pageTags 評価で text-level に展開する pass を追加。resolveIfTagsでは到達できないブロック opener 属性内の iftags (例[[div_ class="x" [[iftags +foo]]style="display:none;"[[/iftags]]]]) を扱えるようにする。lib/Text_Wiki/Text/Wiki.php) の rule 適用順 (Iftags は index 11、Comment は index 12) に整合: comment 内の iftags も普通に展開され、その後 comment rule が剥がす流れを保つ。Changes
新規
packages/parser/src/parser/rules/block/module/iftags/preprocess.ts:preprocessIftags(source, pageTags):pageTags === nullで no-op、それ以外は innermost-first に[[iftags]]を展開。INNERMOST_IFTAGS_PATTERNにgflag を付与し、1 pass で全 innermost block を置換 (兄弟 iftags のO(n^2)再走査を解消、反復回数は入れ子深さに比例)。[[code]](未閉じ時は EOF まで吸収)[[html]](close ある時のみ)@<...>@(同一行)@@...@@(同一行)RAW_BLOCK_OPEN_PATTERNを sticky (y) +lastIndex探索に変更し、per-[[のsource.slice(i)確保 (O(n^2)) を排除。close 探索もg+lastIndexで同様に slice 排除。makeUniqueSentinelsで衝突回避。packages/parser/src/index.tsにpreprocessIftagsを export。パイプライン更新
examples/wdmock-cf/apps/main/src/services/pipeline.ts:resolveIncludes → getPageTags → preprocessIftags → parse → resolveModulesの順序に変更。Test plan
[[iftags +tag]]で tag を持つページは body を保持、持たないページは空に置換。[[iftags -tag]]で逆方向の条件評価。[[code]]/[[html]]/@@..@@/@<..>@内の[[iftags]]は展開されない。[[div_ class="x" [[iftags +foo]]style="..."[[/iftags]]]]) で展開される。O(n^2)にならない。