package bjc.pratt.commands.impls; import bjc.pratt.ParserContext; import bjc.pratt.blocks.ParseBlock; import bjc.pratt.commands.BinaryPostCommand; import bjc.pratt.tokens.Token; import bjc.utils.data.ITree; import bjc.utils.data.Tree; import bjc.utils.parserutils.ParserException; /** * A post-circumfix operator, like array indexing. * * @author bjculkin * * @param * The key type of the tokens. * * @param * The value type of the tokens. * * @param * The state type of the parser. */ public class PostCircumfixCommand extends BinaryPostCommand { private final ParseBlock innerBlock; private final Token mark; /** * Create a new post-circumfix operator. * * @param precedence * The precedence of the operator. * * @param inner * The block inside the expression. * * @param marker * The token to use as the node for the AST. */ public PostCircumfixCommand(final int precedence, final ParseBlock inner, final Token marker) { super(precedence); if (inner == null) throw new NullPointerException("Inner block must not be null"); innerBlock = inner; mark = marker; } @Override public ITree> denote(final ITree> operand, final Token operator, final ParserContext ctx) throws ParserException { final ITree> inside = innerBlock.parse(ctx); return new Tree<>(mark, operand, inside); } }