001package gudusoft.gsqlparser.pp2.layout;
002
003/**
004 * A single layout rule. Rules read the {@link LayoutContext} (token stream +
005 * upstream analyses + decisions so far) and request layout decisions
006 * ({@code requestLinebreaksBefore}/{@code requestBlanksBefore}/{@code requestIndent}).
007 *
008 * <p>Rules are registered with a {@link LayoutRulePipeline} and applied in
009 * registration order. Competing writes to the same token-gap property are
010 * resolved by {@link #priority()} (higher wins; later-applied wins on a tie) via
011 * the {@link LayoutConflictResolver}.
012 *
013 * <p>Implementations must be iterative (no recursion over deep trees) and must
014 * not mutate {@link gudusoft.gsqlparser.pp2.token.Pp2Token} or the wrapped
015 * {@code TSourceToken}; all output goes through the context's request methods.
016 *
017 * <p>Plan reference: §7.3/S23, §7.4/S23.
018 */
019public interface LayoutRule {
020
021    /**
022     * The rule's precedence. Higher-priority rules win conflicts over
023     * lower-priority ones regardless of registration order.
024     */
025    int priority();
026
027    /** Short, stable identifier for logging/diagnostics. */
028    String name();
029
030    /** Apply the rule, requesting layout decisions on the context. */
031    void apply(LayoutContext context);
032}