Skip to content

Replace DocLayout with validated LayoutPlan for total coverage#128

Merged
ryo33 merged 4 commits intomainfrom
claude/review-euresource-design-TIhia
Apr 21, 2026
Merged

Replace DocLayout with validated LayoutPlan for total coverage#128
ryo33 merged 4 commits intomainfrom
claude/review-euresource-design-TIhia

Conversation

@ryo33
Copy link
Copy Markdown
Member

@ryo33 ryo33 commented Apr 18, 2026

Summary

This PR replaces the best-effort DocLayout projection system with a new LayoutPlan that provides total, verified coverage of all reachable document nodes. The new system eliminates silent fallbacks and makes all failure cases explicit through typed PlanError variants.

Key Changes

  • Removed crates/eure-document/src/layout.rs: The old DocLayout, LayoutStyle, and project_with_layout are deleted entirely.

  • Added crates/eure-document/src/plan/ module with three submodules:

    • plan.rs: Core LayoutPlan and PlanBuilder with explicit form assignment and validation
    • plan/emit.rs: Emission logic that converts a validated plan to SourceDocument
    • plan/traverse.rs: Reachable-node traversal helpers
  • New seven-variant form taxonomy (Form enum):

    • Inline: path = value
    • BindingBlock: path { ... }
    • BindingValueBlock: path { = value ... }
    • Section: @ path with items
    • SectionBlock: @ path { ... }
    • SectionValueBlock: @ path { = value ... }
    • Flatten: Hoist children without self-emission
  • Orthogonal array handling (ArrayForm enum):

    • Inline: Single binding path = [...]
    • PerElement(Form): Per-element with [] marker
    • PerElementIndexed(Form): Per-element with explicit [i] indices
  • Explicit validation:

    • check_form_compat() and check_array_form_compat() validate form assignments against node kinds
    • dry_walk_validate() performs structural validation before emission
    • All errors are typed PlanError variants (no silent fallbacks)
  • Updated schema integration (eure-schema):

    • materialize_layout_plan() replaces materialize_doc_layout() with Result<LayoutPlan, PlanError>
    • LayoutStrategy now aliases Form instead of LayoutStyle
    • Schema-derived strategies are applied with full error propagation
  • Updated test suite and CLI:

    • Test cases now use LayoutPlan API
    • Schema files updated to use new form names (section-block instead of nested, etc.)
    • Error handling updated to surface PlanError in scenarios

Notable Implementation Details

  • The PlanBuilder API is fluent: set_form(), set_array_form(), order() all return Result<&mut Self, PlanError> for chaining.
  • Emission is split into validation (dry_walk_validate) and real emission (emit), both using the same control flow to ensure validation mirrors what emission produces.
  • Extensions always precede value children in emission to keep tags like $variant at the top of blocks.
  • The root node's form is implicit (cannot be set); only non-root nodes are assigned forms.

https://claude.ai/code/session_01TP4JqaAMFLYoMD5wzHESAs

claude and others added 4 commits April 17, 2026 09:59
Introduces eure_document::plan with:
- Form enum for the 6 grammar patterns + Flatten
- ArrayForm enum (Inline, PerElement, PerElementIndexed) orthogonal to Form
- LayoutPlan with total forms map over reachable NodeIds
- PlanBuilder that rejects incompatible assignments up-front via typed
  PlanError variants instead of silent fallbacks
- auto/sectioned/flat policy presets
- Coverage and duplicate-emission checks in build()

This coexists with the existing DocLayout for now; callers will migrate
in follow-up commits.

https://claude.ai/code/session_01TP4JqaAMFLYoMD5wzHESAs
…ensions, make check green

- PlanBuilder::build() fill_defaults walk now threads allow_sections
  top-down so Section is never auto-assigned inside build_items bodies
  (fixes debug_assert!(inner.sections.is_empty()) on case_schema tests)
- ArrayForm::Inline emission now calls emit_extensions_only so \$optional/
  \$variant extensions on array nodes are emitted as path-prefixed bindings
  (fixes generated_case_schema_enforces_exclusive_json_fixture_shapes)
- Remove unused _seg parameter from emit_array_child to satisfy clippy
- Regenerate test-suite-case.schema.eure with new Section-based layout
- Makefile eure-check: pass --offline to eure binary and run specific
  targets to avoid unreachable eure.dev network fetch in offline env

https://claude.ai/code/session_01TP4JqaAMFLYoMD5wzHESAs
Merges main (current-index [^], Zed extension, Rust codegen tab) and
replaces the old best-effort DocLayout with a total, validated LayoutPlan
that owns the document and assigns explicit Form/ArrayForm per node.

Key changes:
- LayoutPlan: context-aware auto-form with Section/Binding/Inline/Flatten
- ArrayForm: PerElement/PerElementIndexed orthogonal to Form
- ArrayIndexKind enum: Specific(usize)/Push/Current replaces Option<usize>
- PlanError: typed thiserror enum; ScenarioError::LayoutPlan(PlanError)
- check_form_compat: *ValueBlock excludes Map/PartialMap (primitives only)
- check_array_form_compat: per-element check_form_compat
- OrderExtensionChild: typed error when ordering extension children
- ArrayFormReason::ElementIncompatibleForm { element, kind }
- emit_extensions_only: propagates allow_sections correctly
- build_items: uses allow_sections=false to enforce section context rule
- New tests: 6 additional cases covering the above invariants
- Delete layout.rs (old DocLayout)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ryo33 ryo33 merged commit c3da15f into main Apr 21, 2026
1 check passed
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.

2 participants