package bjc.pratt.commands; import bjc.pratt.NonInitialCommand; import bjc.pratt.ParseBlock; import bjc.pratt.ParserContext; import bjc.pratt.Token; import bjc.utils.data.ITree; import bjc.utils.data.Tree; import bjc.utils.parserutils.ParserException; /** * A non-initial command that delegates all of the work to a {@link ParseBlock} * * @author bjculkin * * @param * The token key type. * * @param * The token value type. * * @param * The parser state type. */ public class BlockNonInitialCommand extends NonInitialCommand { private ParseBlock innr; private int lftBind; private int nxtBind; private Token trm; /** * Create a new non-initial command that delegates to a parse block. * * @param inner * The parse block to delegate to. * * @param leftBind * The left binding power (precedence). * * @param rightBind * The right binding power (associativity control). * * @param term * The token to use as the node in the AST. */ public BlockNonInitialCommand(ParseBlock inner, int leftBind, int rightBind, Token term) { innr = inner; lftBind = leftBind; nxtBind = rightBind; trm = term; } @Override public ITree> denote(ITree> operand, Token operator, ParserContext ctx) throws ParserException { ITree> expression = innr.parse(ctx); return new Tree<>(trm, expression); } @Override public int leftBinding() { return lftBind; } @Override public int nextBinding() { return nxtBind; } }