From c82452e59b1547392c3e89d08d9173cc6dc79e23 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Wed, 5 Apr 2017 15:35:13 -0400 Subject: Reorganize --- .../parserutils/pratt/blocks/SimpleParseBlock.java | 101 --------------------- 1 file changed, 101 deletions(-) delete mode 100644 JPratt/src/main/java/bjc/utils/parserutils/pratt/blocks/SimpleParseBlock.java (limited to 'JPratt/src/main/java/bjc/utils/parserutils/pratt/blocks/SimpleParseBlock.java') diff --git a/JPratt/src/main/java/bjc/utils/parserutils/pratt/blocks/SimpleParseBlock.java b/JPratt/src/main/java/bjc/utils/parserutils/pratt/blocks/SimpleParseBlock.java deleted file mode 100644 index c2e9e54..0000000 --- a/JPratt/src/main/java/bjc/utils/parserutils/pratt/blocks/SimpleParseBlock.java +++ /dev/null @@ -1,101 +0,0 @@ -package bjc.utils.parserutils.pratt.blocks; - -import java.util.function.Predicate; - -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; - -/** - * Simple implementation of {@link ParseBlock} - * - * @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 SimpleParseBlock implements ParseBlock { - private int pow; - - private K term; - - private Predicate>> validatr; - - /** - * Create a new block. - * - * @param precedence - * The precedence of this block. - * - * @param terminator - * The token type that terminates the block. If this is - * null, don't check for a terminator. - * - * @param validator - * The predicate to apply to blocks. - */ - public SimpleParseBlock(int precedence, K terminator, Predicate>> validator) { - if (precedence < 0) throw new IllegalArgumentException("Precedence must be non-negative"); - - pow = precedence; - term = terminator; - validatr = validator; - } - - @Override - public ITree> parse(ParserContext ctx) throws ParserException { - ITree> res = ctx.parse.parseExpression(pow, ctx.tokens, ctx.state, false); - - if (term != null) { - ctx.tokens.expect(term); - } - - if (validatr == null || validatr.test(res)) { - return res; - } - - throw new ParserException("Block failed validation"); - } - - @Override - public int hashCode() { - final int prime = 31; - - int result = 1; - - result = prime * result + pow; - result = prime * result + ((term == null) ? 0 : term.hashCode()); - - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof SimpleParseBlock)) return false; - - SimpleParseBlock other = (SimpleParseBlock) obj; - - if (pow != other.pow) return false; - - if (term == null) { - if (other.term != null) return false; - } else if (!term.equals(other.term)) return false; - - return true; - } - - @Override - public String toString() { - return String.format("ParseBlock [pow=%s, term='%s']", pow, term); - } -} \ No newline at end of file -- cgit v1.2.3