Intuitive DSL for Java

Version 2.0.0 · src/main/java/ch/dbalabs/intuitivedsl/grammar/GroupNode.java

Git clone
git clone https://www.dbalabs.ch/git/intuitive-dsl-java.git

GroupNode.java

/*
 * This file is part of the Intuitive DSL project.
 * Copyright (c) 2026 DBA Labs - Switzerland. All rights reserved.
 *
 * This program is dual-licensed under a commercial license and the AGPLv3.
 * For commercial licensing, contact us at [email protected] or visit https://www.dbalabs.ch.
 *
 * AGPLv3 licensing:
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, version 3 (19 November 2007).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
 */

package ch.dbalabs.intuitivedsl.grammar;

import java.util.List;

/**
 * Represents a logical grouping of syntax nodes, which can be either required
 * or optional.
 * <p>
 * A GroupNode always contains a list of {@link AlternativeNode}s. Even if a group
 * has no explicit OR ('|') operators, it is modeled as containing a single alternative branch.
 * </p>
 *
 * @param type         the strictness type of the group (REQUIRED or OPTIONAL)
 * @param children     the list of alternative branches contained within this group
 * @param isRepeatable true if the entire group can be repeated ('...')
 *
 * @author DBA Labs
 */
public record GroupNode(GroupType type, List<SyntaxNode> children, boolean isRepeatable) implements SyntaxNode {

    /**
     * Compact constructor to ensure deep immutability of the node tree.
     */
    public GroupNode {
        children = (children == null) ? List.of() : List.copyOf(children);
    }
}