cp-ast-core 0.1.3

Core AST types for competitive programming problem specification DSL
Documentation
use super::types::{ConstraintDef, FillContent, SumBoundDef};
use crate::constraint::ConstraintId;
use crate::structure::{Literal, NodeId};

/// An action that can be applied to the AST.
///
/// Actions are the atomic operations that modify the `StructureAST` and `ConstraintSet`.
#[derive(Debug, Clone, PartialEq)]
pub enum Action {
    /// Fill a hole with concrete content.
    FillHole { target: NodeId, fill: FillContent },
    /// Replace an existing node with new content.
    ReplaceNode {
        target: NodeId,
        replacement: FillContent,
    },
    /// Add a constraint to a node.
    AddConstraint {
        target: NodeId,
        constraint: ConstraintDef,
    },
    /// Remove a constraint by ID.
    RemoveConstraint { constraint_id: ConstraintId },
    /// Introduce multi-test-case wrapper.
    IntroduceMultiTestCase {
        count_var_name: String,
        sum_bound: Option<SumBoundDef>,
    },
    /// Add an element to a parent's slot (e.g., add child to Sequence).
    AddSlotElement {
        parent: NodeId,
        slot_name: String,
        element: FillContent,
    },
    /// Remove an element from a parent's slot.
    RemoveSlotElement {
        parent: NodeId,
        slot_name: String,
        child: NodeId,
    },
    /// Add a sibling element next to a target node.
    /// If target is a direct child of Sequence/Section/Repeat body,
    /// wraps target + new element in a Tuple.
    /// If target is already inside a Tuple, appends to that Tuple.
    AddSibling {
        target: NodeId,
        element: FillContent,
    },
    /// Add a variant to a Choice node.
    AddChoiceVariant {
        choice: NodeId,
        tag_value: Literal,
        first_element: FillContent,
    },
}