package parser;

/**
 * Factory for F grammar non-terminal objects.
 */
public class FFact extends ATVFactory {
    /**
     * Factory for F1 grammar non-terminals.
     */
    private F1Fact _f1Fact;

    /**
     * Factory for F2 grammar non-terminals.
     */
    private F2Fact _f2Fact;

    /**
     * Constructor for the F factory,
     *
     * @param tkz    tokenizer to use
     * @param f1Fact factory for F1 grammar non-terminals
     * @param f2Fact factory for F2 grammar non-terminals
     */
    public FFact(ITokenizer tkz, F1Fact f1Fact, F2Fact f2Fact) {
        super(tkz);
        _f1Fact = f1Fact;
        _f2Fact = f2Fact;
    }

    /**
     * Make a token visitor to parse an F non-terminal.
     *
     * @return token visitor
     */
    public ITokVisitor makeVisitor() {
        return _f1Fact.makeChainedVisitor(_f2Fact.makeVisitor());
    }

    /**
     * Make a token visitor that delegates to the given visitor in a chain of responsibility
     *
     * @param successor visitor to serve as successor in the chain
     */
    public ITokVisitor makeChainedVisitor(ITokVisitor successor) {
        return _f1Fact.makeChainedVisitor(_f2Fact.makeChainedVisitor(successor));
    }
}

