package com.ashardalon.pratt.commands.impls; import bjc.data.Tree; import com.ashardalon.pratt.ParserContext; import com.ashardalon.pratt.blocks.ParseBlock; import com.ashardalon.pratt.commands.AbstractInitialCommand; import com.ashardalon.pratt.commands.CommandResult; import com.ashardalon.pratt.tokens.Token; import bjc.data.SimpleTree; import bjc.utils.parserutils.ParserException; /** * A grouping operator. * * @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 GroupingCommand extends AbstractInitialCommand { private final ParseBlock innerBlock; private final Token mark; /** * Create a new grouping command. * * @param inner * The inner block. * * @param marker * The token to use as the node in the AST. */ public GroupingCommand(final ParseBlock inner, final Token marker) { innerBlock = inner; mark = marker; } @Override protected CommandResult intNullDenotation(final Token operator, final ParserContext ctx) throws ParserException { final CommandResult resOpr = innerBlock.parse(ctx); Tree> opr = resOpr.success(); return CommandResult.success(new SimpleTree<>(mark, opr)); } }