diff options
Diffstat (limited to 'JPratt/src/main/java/bjc')
9 files changed, 68 insertions, 51 deletions
diff --git a/JPratt/src/main/java/bjc/pratt/ParserContext.java b/JPratt/src/main/java/bjc/pratt/ParserContext.java index f5e22ba..1697a12 100644 --- a/JPratt/src/main/java/bjc/pratt/ParserContext.java +++ b/JPratt/src/main/java/bjc/pratt/ParserContext.java @@ -30,18 +30,18 @@ public class ParserContext<K, V, C> { /** * Create a new parser context. * - * @param tokens + * @param tokns * The source of tokens. * - * @param parse + * @param prse * The parser to call for sub expressions. * - * @param state + * @param stte * Any state needing to be kept during parsing. */ - public ParserContext(TokenStream<K, V> tokens, PrattParser<K, V, C> parse, C state) { - this.tokens = tokens; - this.parse = parse; - this.state = state; + public ParserContext(TokenStream<K, V> tokns, PrattParser<K, V, C> prse, C stte) { + this.tokens = tokns; + this.parse = prse; + this.state = stte; } }
\ No newline at end of file diff --git a/JPratt/src/main/java/bjc/pratt/PrattParser.java b/JPratt/src/main/java/bjc/pratt/PrattParser.java index e08a67c..c36cabc 100644 --- a/JPratt/src/main/java/bjc/pratt/PrattParser.java +++ b/JPratt/src/main/java/bjc/pratt/PrattParser.java @@ -174,7 +174,16 @@ public class PrattParser<K, V, C> { } /** - * Add a dependant non-initial command to this parser. + * Add a dependent non-initial command to this parser. + * + * @param dependant + * The dependent that precedes the command. + * + * @param marker + * The token key that marks the command. + * + * @param comm + * The command. */ public void addDependantCommand(K dependant, K marker, NonInitialCommand<K, V, C> comm) { if (dependantLeftCommands.containsKey(dependant)) { diff --git a/JPratt/src/main/java/bjc/pratt/TokenStream.java b/JPratt/src/main/java/bjc/pratt/TokenStream.java index d3472a0..e377352 100644 --- a/JPratt/src/main/java/bjc/pratt/TokenStream.java +++ b/JPratt/src/main/java/bjc/pratt/TokenStream.java @@ -69,9 +69,9 @@ public abstract class TokenStream<K, V> implements Iterator<Token<K, V>> { String expectedList = StringUtils.toEnglishList(expectedKeys.toArray(), false); throw new ExpectationException("One of '" + expectedList + "' was expected, not " + curKey); - } else { - next(); } + + next(); } /** @@ -88,7 +88,15 @@ public abstract class TokenStream<K, V> implements Iterator<Token<K, V>> { public final void expect(K... expectedKeys) throws ExpectationException { expect(new HashSet<>(Arrays.asList(expectedKeys))); } - + + /** + * Check whether the head token is a certain type. + * + * @param val + * The type to check for. + * + * @return Whether or not the head token is of that type. + */ public boolean headIs(K val) { return current().getKey().equals(val); } diff --git a/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java b/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java index 5e561fc..76d99de 100644 --- a/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java +++ b/JPratt/src/main/java/bjc/pratt/blocks/TriggeredParseBlock.java @@ -21,10 +21,10 @@ import bjc.utils.parserutils.ParserException; * The state type of the parser. */ public class TriggeredParseBlock<K, V, C> implements ParseBlock<K, V, C> { - private UnaryOperator<C> onEnter; - private UnaryOperator<C> onExit; + private UnaryOperator<C> onEntr; + private UnaryOperator<C> onExt; - private ParseBlock<K, V, C> source; + private ParseBlock<K, V, C> sourc; /** * Create a new triggered parse block. @@ -39,21 +39,20 @@ public class TriggeredParseBlock<K, V, C> implements ParseBlock<K, V, C> { * The block to use for parsing. */ public TriggeredParseBlock(UnaryOperator<C> onEnter, UnaryOperator<C> onExit, ParseBlock<K, V, C> source) { - super(); - this.onEnter = onEnter; - this.onExit = onExit; - this.source = source; + onEntr = onEnter; + onExt = onExit; + sourc = source; } @Override public ITree<Token<K, V>> parse(ParserContext<K, V, C> ctx) throws ParserException { - C newState = onEnter.apply(ctx.state); + C newState = onEntr.apply(ctx.state); ParserContext<K, V, C> newCtx = new ParserContext<>(ctx.tokens, ctx.parse, newState); - ITree<Token<K, V>> res = source.parse(newCtx); + ITree<Token<K, V>> res = sourc.parse(newCtx); - ctx.state = onExit.apply(newState); + ctx.state = onExt.apply(newState); return res; } diff --git a/JPratt/src/main/java/bjc/pratt/commands/ChainCommand.java b/JPratt/src/main/java/bjc/pratt/commands/ChainCommand.java index c7a10b1..6ab126a 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/ChainCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/ChainCommand.java @@ -61,9 +61,9 @@ public class ChainCommand<K, V, C> extends BinaryPostCommand<K, V, C> { new ParserContext<>(ctx.tokens, ctx.parse, ctx.state)); return new Tree<>(chain, res, other); - } else { - return res; } + + return res; } @Override diff --git a/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java index efa7872..072c58c 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java @@ -22,7 +22,7 @@ import bjc.utils.parserutils.ParserException; * The state type of the parser. */ public class PreTernaryCommand<K, V, C> extends AbstractInitialCommand<K, V, C> { - private Token<K, V> term; + private Token<K, V> trm; private ParseBlock<K, V, C> condBlock; @@ -54,11 +54,11 @@ public class PreTernaryCommand<K, V, C> extends AbstractInitialCommand<K, V, C> throw new NullPointerException("Op block #1 must not be null"); else if (op2 == null) throw new NullPointerException("Op block #2 must not be null"); - this.condBlock = cond; - this.opblock1 = op1; - this.opblock2 = op2; + condBlock = cond; + opblock1 = op1; + opblock2 = op2; - this.term = term; + trm = term; } @Override @@ -70,6 +70,6 @@ public class PreTernaryCommand<K, V, C> extends AbstractInitialCommand<K, V, C> ITree<Token<K, V>> op2 = opblock2.parse(ctx); - return new Tree<>(term, cond, op1, op2); + return new Tree<>(trm, cond, op1, op2); } }
\ No newline at end of file diff --git a/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java index bac12cd..0152471 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java @@ -70,8 +70,8 @@ public class TernaryCommand<K, V, C> extends BinaryPostCommand<K, V, C> { public int nextBinding() { if (nonassoc) { return leftBinding() - 1; - } else { - return leftBinding(); } + + return leftBinding(); } }
\ No newline at end of file diff --git a/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java index 9ec3631..d75c8ce 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java @@ -23,9 +23,9 @@ import bjc.utils.parserutils.ParserException; * The state type of the parser. */ public class TransformingInitialCommand<K, V, C> extends AbstractInitialCommand<K, V, C> { - private InitialCommand<K, V, C> internal; + private InitialCommand<K, V, C> internl; - private UnaryOperator<ITree<Token<K, V>>> transform; + private UnaryOperator<ITree<Token<K, V>>> transfrm; /** * Create a new transforming initial command. @@ -39,14 +39,14 @@ public class TransformingInitialCommand<K, V, C> extends AbstractInitialCommand< public TransformingInitialCommand(InitialCommand<K, V, C> internal, UnaryOperator<ITree<Token<K, V>>> transform) { super(); - this.internal = internal; - this.transform = transform; + internl = internal; + transfrm = transform; } @Override protected ITree<Token<K, V>> intNullDenotation(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException { - return transform.apply(internal.denote(operator, ctx)); + return transfrm.apply(internl.denote(operator, ctx)); } } diff --git a/JPratt/src/main/java/bjc/pratt/tokens/StringToken.java b/JPratt/src/main/java/bjc/pratt/tokens/StringToken.java index 2e75702..9f97e33 100644 --- a/JPratt/src/main/java/bjc/pratt/tokens/StringToken.java +++ b/JPratt/src/main/java/bjc/pratt/tokens/StringToken.java @@ -49,26 +49,19 @@ public class StringToken implements Token<String, String> { @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof StringToken)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof StringToken)) return false; StringToken other = (StringToken) obj; if (key == null) { - if (other.key != null) - return false; - } else if (!key.equals(other.key)) - return false; + if (other.key != null) return false; + } else if (!key.equals(other.key)) return false; if (val == null) { - if (other.val != null) - return false; - } else if (!val.equals(other.val)) - return false; + if (other.val != null) return false; + } else if (!val.equals(other.val)) return false; return true; } @@ -77,7 +70,15 @@ public class StringToken implements Token<String, String> { public String toString() { return String.format("StringToken [key='%s', val='%s']", key, val); } - + + /** + * Create a new literal token (has same key/value). + * + * @param val + * The value for the literal token. + * + * @return A literal token with that key. + */ public static StringToken litToken(String val) { return new StringToken(val, val); } |
