From b4e4e7f1d6749de92b0f2c5ca09eb4170704100f Mon Sep 17 00:00:00 2001 From: bjculkin Date: Fri, 31 Mar 2017 08:53:33 -0400 Subject: Move Pratt Parser to new project --- .../pratt/blocks/TriggeredParseBlock.java | 61 ---------------------- 1 file changed, 61 deletions(-) delete mode 100644 BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/blocks/TriggeredParseBlock.java (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/blocks/TriggeredParseBlock.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/blocks/TriggeredParseBlock.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/blocks/TriggeredParseBlock.java deleted file mode 100644 index fbfc61b..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/blocks/TriggeredParseBlock.java +++ /dev/null @@ -1,61 +0,0 @@ -package bjc.utils.parserutils.pratt.blocks; - -import java.util.function.UnaryOperator; - -import bjc.utils.data.ITree; -import bjc.utils.parserutils.ParserException; -import bjc.utils.parserutils.pratt.ParseBlock; -import bjc.utils.parserutils.pratt.ParserContext; -import bjc.utils.parserutils.pratt.Token; - -/** - * A parse block that can adjust the state before handling its context. - * - * @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 TriggeredParseBlock implements ParseBlock { - private UnaryOperator onEnter; - private UnaryOperator onExit; - - private ParseBlock source; - - /** - * Create a new triggered parse block. - * - * @param onEnter - * The action to fire before parsing the block. - * - * @param onExit - * The action to fire after parsing the block. - * - * @param source - * The block to use for parsing. - */ - public TriggeredParseBlock(UnaryOperator onEnter, UnaryOperator onExit, ParseBlock source) { - super(); - this.onEnter = onEnter; - this.onExit = onExit; - this.source = source; - } - - @Override - public ITree> parse(ParserContext ctx) throws ParserException { - C newState = onEnter.apply(ctx.state); - - ParserContext newCtx = new ParserContext<>(ctx.tokens, ctx.parse, newState); - - ITree> res = source.parse(newCtx); - - ctx.state = onExit.apply(newState); - - return res; - } - -} -- cgit v1.2.3