From 56f07e9a3aaa873fe385d224f088f048dbafa8f7 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 10 Apr 2017 16:49:54 -0400 Subject: Cleanup --- .../bjc/pratt/commands/AbstractInitialCommand.java | 9 +- .../java/bjc/pratt/commands/BinaryCommand.java | 16 ++-- .../java/bjc/pratt/commands/BinaryPostCommand.java | 16 ++-- .../main/java/bjc/pratt/commands/ChainCommand.java | 35 +++---- .../java/bjc/pratt/commands/ConstantCommand.java | 15 +-- .../bjc/pratt/commands/DefaultInitialCommand.java | 9 +- .../pratt/commands/DefaultNonInitialCommand.java | 9 +- .../java/bjc/pratt/commands/DenestingCommand.java | 18 ++-- .../java/bjc/pratt/commands/GroupingCommand.java | 20 ++-- .../java/bjc/pratt/commands/InitialCommands.java | 103 +++++++++++---------- .../main/java/bjc/pratt/commands/LeafCommand.java | 9 +- .../java/bjc/pratt/commands/LeftBinaryCommand.java | 10 +- .../java/bjc/pratt/commands/NonBinaryCommand.java | 10 +- .../bjc/pratt/commands/NonInitialCommands.java | 79 ++++++++-------- .../bjc/pratt/commands/PostCircumfixCommand.java | 28 +++--- .../java/bjc/pratt/commands/PostfixCommand.java | 14 +-- .../java/bjc/pratt/commands/PreTernaryCommand.java | 34 +++---- .../bjc/pratt/commands/RightBinaryCommand.java | 6 +- .../java/bjc/pratt/commands/TernaryCommand.java | 36 +++---- .../pratt/commands/TransformingInitialCommand.java | 20 ++-- .../main/java/bjc/pratt/commands/UnaryCommand.java | 20 ++-- 21 files changed, 260 insertions(+), 256 deletions(-) (limited to 'JPratt/src/main/java/bjc/pratt/commands') diff --git a/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java index b5a789c..9fc4fbc 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java @@ -8,21 +8,22 @@ import bjc.utils.parserutils.ParserException; /** * Abstract base for initial commands. - * + * * @author bjculkin * * @param * The key type of the tokens. - * + * * @param * The value type of the tokens. - * + * * @param * The state type of the parser. */ public abstract class AbstractInitialCommand implements InitialCommand { @Override - public ITree> denote(Token operator, ParserContext ctx) throws ParserException { + public ITree> denote(final Token operator, final ParserContext ctx) + throws ParserException { return intNullDenotation(operator, ctx); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/BinaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/BinaryCommand.java index 44cb5f8..ef81d3f 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/BinaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/BinaryCommand.java @@ -8,35 +8,35 @@ import bjc.utils.parserutils.ParserException; /** * A binary 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 abstract class BinaryCommand extends BinaryPostCommand { /** * Create a new binary operator with the specified precedence. - * + * * @param precedence * The precedence of the operator. */ - public BinaryCommand(int precedence) { + public BinaryCommand(final int precedence) { super(precedence); } protected abstract int rightBinding(); @Override - public ITree> denote(ITree> operand, Token operator, ParserContext ctx) - throws ParserException { - ITree> opr = ctx.parse.parseExpression(rightBinding(), ctx.tokens, ctx.state, false); + public ITree> denote(final ITree> operand, final Token operator, + final ParserContext ctx) throws ParserException { + final ITree> opr = ctx.parse.parseExpression(rightBinding(), ctx.tokens, ctx.state, false); return new Tree<>(operator, operand, opr); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java b/JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java index 18a5584..316f0fe 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java @@ -4,15 +4,15 @@ import bjc.pratt.NonInitialCommand; /** * A operator with fixed precedence. - * + * * @author bjculkin - * + * * @param * The key type of the tokens. - * + * * @param * The value type of the tokens. - * + * * @param * The state type of the parser. */ @@ -21,14 +21,12 @@ public abstract class BinaryPostCommand extends NonInitialCommand * The key type of the tokens. - * + * * @param * The value type of the tokens. - * + * * @param * The state type of the parser. */ public class ChainCommand extends BinaryPostCommand { - private Set chainWith; + private final Set chainWith; - private Token chain; + private final Token chain; /** * Create a new chained operator. - * + * * @param precedence * The precedence of this operator. - * + * * @param chainSet * The operators to chain with. - * + * * @param chainMarker * The token to use as the node in the AST. */ - public ChainCommand(int precedence, Set chainSet, Token chainMarker) { + public ChainCommand(final int precedence, final Set chainSet, final Token chainMarker) { super(precedence); chainWith = chainSet; @@ -47,17 +47,18 @@ public class ChainCommand extends BinaryPostCommand { } @Override - public ITree> denote(ITree> operand, Token operator, ParserContext ctx) - throws ParserException { - ITree> tree = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, false); + public ITree> denote(final ITree> operand, final Token operator, + final ParserContext ctx) throws ParserException { + final ITree> tree = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, + false); - ITree> res = new Tree<>(operator, operand, tree); + final ITree> res = new Tree<>(operator, operand, tree); if (chainWith.contains(ctx.tokens.current().getKey())) { - Token tok = ctx.tokens.current(); + final Token tok = ctx.tokens.current(); ctx.tokens.next(); - ITree> other = denote(tree, tok, + final ITree> other = denote(tree, tok, new ParserContext<>(ctx.tokens, ctx.parse, ctx.state)); return new Tree<>(chain, res, other); diff --git a/JPratt/src/main/java/bjc/pratt/commands/ConstantCommand.java b/JPratt/src/main/java/bjc/pratt/commands/ConstantCommand.java index 86a172f..9b12cda 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/ConstantCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/ConstantCommand.java @@ -8,33 +8,34 @@ import bjc.utils.parserutils.ParserException; /** * A command that represents a specific tree. - * + * * @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 ConstantCommand implements InitialCommand { - private ITree> val; + private final ITree> val; /** * Create a new constant. - * + * * @param con * The tree this constant represents. */ - public ConstantCommand(ITree> con) { + public ConstantCommand(final ITree> con) { val = con; } @Override - public ITree> denote(Token operator, ParserContext ctx) throws ParserException { + public ITree> denote(final Token operator, final ParserContext ctx) + throws ParserException { return val; } } \ No newline at end of file diff --git a/JPratt/src/main/java/bjc/pratt/commands/DefaultInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/DefaultInitialCommand.java index 717444a..ff40ef2 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/DefaultInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/DefaultInitialCommand.java @@ -8,21 +8,22 @@ import bjc.utils.parserutils.ParserException; /** * Default implementation of an initial command. - * + * * @author EVE * * @param * The key type of the token. - * + * * @param * The value type of the token. - * + * * @param * The state type of the parser. */ public class DefaultInitialCommand implements InitialCommand { @Override - public ITree> denote(Token operator, ParserContext ctx) throws ParserException { + public ITree> denote(final Token operator, final ParserContext ctx) + throws ParserException { throw new ParserException("Unexpected token " + operator); } } diff --git a/JPratt/src/main/java/bjc/pratt/commands/DefaultNonInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/DefaultNonInitialCommand.java index aeb337d..6f590c9 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/DefaultNonInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/DefaultNonInitialCommand.java @@ -7,21 +7,22 @@ import bjc.utils.data.ITree; /** * Default implementation of a non-initial command. - * + * * @author EVE * * @param * The key type of the tokens. - * + * * @param * The value type of the tokens. - * + * * @param * The state type of the parser. */ public class DefaultNonInitialCommand extends NonInitialCommand { @Override - public ITree> denote(ITree> operand, Token operator, ParserContext ctx) { + public ITree> denote(final ITree> operand, final Token operator, + final ParserContext ctx) { throw new UnsupportedOperationException("Default command has no left denotation"); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/DenestingCommand.java b/JPratt/src/main/java/bjc/pratt/commands/DenestingCommand.java index 9b4518f..e3b1d3c 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/DenestingCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/DenestingCommand.java @@ -8,37 +8,37 @@ import bjc.utils.parserutils.ParserException; /** * A command that denests a input tree. - * + * * Useful for processing the result of passing a complex parse group to a * command. - * + * * @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 DenestingCommand extends AbstractInitialCommand { - private InitialCommand wrapped; + private final InitialCommand wrapped; /** * Create a new transforming initial command. - * + * * @param internal * The initial command to delegate to. */ - public DenestingCommand(InitialCommand internal) { + public DenestingCommand(final InitialCommand internal) { wrapped = internal; } @Override - protected ITree> intNullDenotation(Token operator, ParserContext ctx) + protected ITree> intNullDenotation(final Token operator, final ParserContext ctx) throws ParserException { return wrapped.denote(operator, ctx).getChild(0); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/GroupingCommand.java b/JPratt/src/main/java/bjc/pratt/commands/GroupingCommand.java index 1a8d3c8..f4288d0 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/GroupingCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/GroupingCommand.java @@ -9,42 +9,42 @@ 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 ParseBlock innerBlock; + private final ParseBlock innerBlock; - private Token mark; + 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(ParseBlock inner, Token marker) { + public GroupingCommand(final ParseBlock inner, final Token marker) { innerBlock = inner; mark = marker; } @Override - protected ITree> intNullDenotation(Token operator, ParserContext ctx) + protected ITree> intNullDenotation(final Token operator, final ParserContext ctx) throws ParserException { - ITree> opr = innerBlock.parse(ctx); + final ITree> opr = innerBlock.parse(ctx); return new Tree<>(mark, opr); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java b/JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java index 3ece14c..5710277 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java +++ b/JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java @@ -1,57 +1,60 @@ package bjc.pratt.commands; +import static bjc.pratt.blocks.ParseBlocks.repeating; +import static bjc.pratt.blocks.ParseBlocks.simple; +import static bjc.pratt.blocks.ParseBlocks.trigger; + +import java.util.function.UnaryOperator; + import bjc.pratt.InitialCommand; import bjc.pratt.ParseBlock; import bjc.pratt.Token; import bjc.utils.data.ITree; -import java.util.function.UnaryOperator; - -import static bjc.pratt.blocks.ParseBlocks.*; - /** * * Contains factory methods for producing common implementations of * {@link InitialCommand} - * + * * @author EVE * */ public class InitialCommands { /** * Create a new unary operator. - * + * * @param precedence * The precedence of the operator. - * + * * @return A command implementing that operator. */ - public static InitialCommand unary(int precedence) { + public static InitialCommand unary(final int precedence) { return new UnaryCommand<>(precedence); } /** * Create a new grouping operator. - * + * * @param precedence * The precedence of the expression in the operator. - * + * * @param term * The type that closes the group. - * + * * @param mark * The token for the AST node of the group. - * + * * @return A command implementing the operator. */ - public static InitialCommand grouping(int precedence, K term, Token mark) { - ParseBlock innerBlock = simple(precedence, term, null); + public static InitialCommand grouping(final int precedence, final K term, + final Token mark) { + final ParseBlock innerBlock = simple(precedence, term, null); return new GroupingCommand<>(innerBlock, mark); } /** * Create a new leaf operator. - * + * * @return A command implementing the operator. */ public static InitialCommand leaf() { @@ -60,89 +63,89 @@ public class InitialCommands { /** * Create a new pre-ternary operator, like an if-then-else statement. - * + * * @param cond1 * The priority of the first block. - * + * * @param block1 * The priority of the second block. - * + * * @param block2 * The priority of the third block. - * + * * @param mark1 * The marker that ends the first block. - * + * * @param mark2 * The marker that ends the second block. - * + * * @param term * The token for the AST node of the group. - * + * * @return A command implementing the operator. */ - public static InitialCommand preTernary(int cond1, int block1, int block2, K mark1, K mark2, - Token term) { - ParseBlock condBlock = simple(cond1, mark1, null); - ParseBlock opblock1 = simple(block1, mark2, null); - ParseBlock opblock2 = simple(block2, null, null); + public static InitialCommand preTernary(final int cond1, final int block1, final int block2, + final K mark1, final K mark2, final Token term) { + final ParseBlock condBlock = simple(cond1, mark1, null); + final ParseBlock opblock1 = simple(block1, mark2, null); + final ParseBlock opblock2 = simple(block2, null, null); return new PreTernaryCommand<>(condBlock, opblock1, opblock2, term); } /** * Create a new named constant. - * + * * @param val * The value of the constant. - * + * * @return A command implementing the constant. */ - public static InitialCommand constant(ITree> val) { + public static InitialCommand constant(final ITree> val) { return new ConstantCommand<>(val); } /** * Create a new delimited command. This is for block-like constructs. - * + * * @param inner * The precedence of the inner blocks. - * + * * @param delim * The marker between sub-blocks. - * + * * @param mark * The block terminator. - * + * * @param term * The token for the AST node of the group. - * + * * @param onEnter * The function to apply to the state on entering the * block. - * + * * @param onDelim * The function to apply to the state on finishing a * sub-block. - * + * * @param onExit * The function to apply to the state on exiting the * block. - * + * * @param statement * Whether or not the sub-blocks are statements or * expressions. - * + * * @return A command implementing the operator. */ - public static InitialCommand delimited(int inner, K delim, K mark, Token term, - UnaryOperator onEnter, UnaryOperator onDelim, UnaryOperator onExit, - boolean statement) { - ParseBlock innerBlock = simple(inner, null, null); - ParseBlock delimsBlock = repeating(innerBlock, delim, mark, term, onDelim); - ParseBlock scopedBlock = trigger(delimsBlock, onEnter, onExit); + public static InitialCommand delimited(final int inner, final K delim, final K mark, + final Token term, final UnaryOperator onEnter, final UnaryOperator onDelim, + final UnaryOperator onExit, final boolean statement) { + final ParseBlock innerBlock = simple(inner, null, null); + final ParseBlock delimsBlock = repeating(innerBlock, delim, mark, term, onDelim); + final ParseBlock scopedBlock = trigger(delimsBlock, onEnter, onExit); - GroupingCommand command = new GroupingCommand<>(scopedBlock, term); + final GroupingCommand command = new GroupingCommand<>(scopedBlock, term); /* * Remove the wrapper layer from grouping-command on top of @@ -153,16 +156,16 @@ public class InitialCommands { /** * Create a new denesting command. - * + * * This removes one tree-level, and is useful when combining complex * parse blocks with commands. - * + * * @param comm * The command to denest. - * + * * @return A command that denests the result of the provided command. */ - public static InitialCommand denest(InitialCommand comm) { + public static InitialCommand denest(final InitialCommand comm) { return new DenestingCommand<>(comm); } } diff --git a/JPratt/src/main/java/bjc/pratt/commands/LeafCommand.java b/JPratt/src/main/java/bjc/pratt/commands/LeafCommand.java index 798b9ce..9b4480d 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/LeafCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/LeafCommand.java @@ -9,21 +9,22 @@ import bjc.utils.parserutils.ParserException; /** * A operator that stands for itself. - * + * * @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 LeafCommand implements InitialCommand { @Override - public ITree> denote(Token operator, ParserContext ctx) throws ParserException { + public ITree> denote(final Token operator, final ParserContext ctx) + throws ParserException { return new Tree<>(operator); } } \ No newline at end of file diff --git a/JPratt/src/main/java/bjc/pratt/commands/LeftBinaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/LeftBinaryCommand.java index 4a481d7..adf98a1 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/LeftBinaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/LeftBinaryCommand.java @@ -2,26 +2,26 @@ package bjc.pratt.commands; /** * A left-associative 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 LeftBinaryCommand extends BinaryCommand { /** * Create a new left-associative operator. - * + * * @param precedence * The precedence of the operator. */ - public LeftBinaryCommand(int precedence) { + public LeftBinaryCommand(final int precedence) { super(precedence); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/NonBinaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/NonBinaryCommand.java index d1208bd..54ab98b 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/NonBinaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/NonBinaryCommand.java @@ -2,26 +2,26 @@ package bjc.pratt.commands; /** * A non-associative 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 NonBinaryCommand extends BinaryCommand { /** * Create a new non-associative operator. - * + * * @param precedence * The precedence of the operator. */ - public NonBinaryCommand(int precedence) { + public NonBinaryCommand(final int precedence) { super(precedence); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommands.java b/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommands.java index b7eda95..48922b7 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommands.java +++ b/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommands.java @@ -1,139 +1,140 @@ package bjc.pratt.commands; +import java.util.Set; + import bjc.pratt.NonInitialCommand; import bjc.pratt.ParseBlock; import bjc.pratt.Token; import bjc.pratt.blocks.SimpleParseBlock; -import java.util.Set; - /** * Contains factory methods for producing common implementations of * {@link NonInitialCommand} - * + * * @author EVE * */ public class NonInitialCommands { /** * Create a left-associative infix operator. - * + * * @param precedence * The precedence of the operator. - * + * * @return A command implementing that operator. */ - public static NonInitialCommand infixLeft(int precedence) { + public static NonInitialCommand infixLeft(final int precedence) { return new LeftBinaryCommand<>(precedence); } /** * Create a right-associative infix operator. - * + * * @param precedence * The precedence of the operator. - * + * * @return A command implementing that operator. */ - public static NonInitialCommand infixRight(int precedence) { + public static NonInitialCommand infixRight(final int precedence) { return new RightBinaryCommand<>(precedence); } /** * Create a non-associative infix operator. - * + * * @param precedence * The precedence of the operator. - * + * * @return A command implementing that operator. */ - public static NonInitialCommand infixNon(int precedence) { + public static NonInitialCommand infixNon(final int precedence) { return new NonBinaryCommand<>(precedence); } /** * Create a chained operator. - * + * * @param precedence * The precedence of the operator. - * + * * @param chainSet * The operators it forms a chain with. - * + * * @param marker * The token to use as the AST node for the chained * operators. - * + * * @return A command implementing that operator. */ - public static NonInitialCommand chain(int precedence, Set chainSet, Token marker) { + public static NonInitialCommand chain(final int precedence, final Set chainSet, + final Token marker) { return new ChainCommand<>(precedence, chainSet, marker); } /** * Create a postfix operator. - * + * * @param precedence * The precedence of the operator. - * + * * @return A command implementing that operator. */ - public static NonInitialCommand postfix(int precedence) { + public static NonInitialCommand postfix(final int precedence) { return new PostfixCommand<>(precedence); } /** * Create a post-circumfix operator. - * + * * This is an operator in form similar to array indexing. - * + * * @param precedence * The precedence of this operator - * + * * @param insidePrecedence * The precedence of the expression inside the operator - * + * * @param closer * The token that closes the circumfix. - * + * * @param marker * The token to use as the AST node for the operator. - * + * * @return A command implementing that operator. */ - public static NonInitialCommand postCircumfix(int precedence, int insidePrecedence, K closer, - Token marker) { - ParseBlock innerBlock = new SimpleParseBlock<>(insidePrecedence, closer, null); + public static NonInitialCommand postCircumfix(final int precedence, + final int insidePrecedence, final K closer, final Token marker) { + final ParseBlock innerBlock = new SimpleParseBlock<>(insidePrecedence, closer, null); return new PostCircumfixCommand<>(precedence, innerBlock, marker); } /** * Create a ternary operator. - * + * * This is like C's ?: operator. - * + * * @param precedence * The precedence of the operator. - * + * * @param insidePrecedence * The precedence of the inner section of the operator. - * + * * @param closer * The token that marks the end of the inner section. - * + * * @param marker * The token to use as the AST node for the operator. - * + * * @param nonassoc * True if the command is non-associative, false * otherwise. - * + * * @return A command implementing this operator. */ - public static NonInitialCommand ternary(int precedence, int insidePrecedence, K closer, - Token marker, boolean nonassoc) { - ParseBlock innerBlock = new SimpleParseBlock<>(insidePrecedence, closer, null); + public static NonInitialCommand ternary(final int precedence, final int insidePrecedence, + final K closer, final Token marker, final boolean nonassoc) { + final ParseBlock innerBlock = new SimpleParseBlock<>(insidePrecedence, closer, null); return new TernaryCommand<>(precedence, innerBlock, marker, nonassoc); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/PostCircumfixCommand.java b/JPratt/src/main/java/bjc/pratt/commands/PostCircumfixCommand.java index 6bed0ff..e7d2eea 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/PostCircumfixCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/PostCircumfixCommand.java @@ -9,41 +9,39 @@ 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 ParseBlock innerBlock; + private final ParseBlock innerBlock; - private Token mark; + 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(int precedence, ParseBlock inner, Token marker) { + 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"); - } + if (inner == null) throw new NullPointerException("Inner block must not be null"); innerBlock = inner; @@ -51,9 +49,9 @@ public class PostCircumfixCommand extends BinaryPostCommand { } @Override - public ITree> denote(ITree> operand, Token operator, ParserContext ctx) - throws ParserException { - ITree> inside = innerBlock.parse(ctx); + 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); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/PostfixCommand.java b/JPratt/src/main/java/bjc/pratt/commands/PostfixCommand.java index 5e2ce28..3276d09 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/PostfixCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/PostfixCommand.java @@ -8,32 +8,32 @@ import bjc.utils.parserutils.ParserException; /** * A postfix 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 PostfixCommand extends BinaryPostCommand { /** * Create a new postfix operator. - * + * * @param precedence * The precedence of the operator. */ - public PostfixCommand(int precedence) { + public PostfixCommand(final int precedence) { super(precedence); } @Override - public ITree> denote(ITree> operand, Token operator, ParserContext ctx) - throws ParserException { + public ITree> denote(final ITree> operand, final Token operator, + final ParserContext ctx) throws ParserException { return new Tree<>(operator, operand); } } \ No newline at end of file diff --git a/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java index 072c58c..d8304e2 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java @@ -9,43 +9,43 @@ import bjc.utils.parserutils.ParserException; /** * A prefix ternary operator, like an if/then/else group. - * + * * @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 PreTernaryCommand extends AbstractInitialCommand { - private Token trm; + private final Token trm; - private ParseBlock condBlock; + private final ParseBlock condBlock; - private ParseBlock opblock1; - private ParseBlock opblock2; + private final ParseBlock opblock1; + private final ParseBlock opblock2; /** * Create a new ternary statement. - * + * * @param cond * The block for handling the condition. - * + * * @param op1 * The block for handling the first operator. - * + * * @param op2 * The block for handling the second operator. - * + * * @param term * The token to use as the node for the AST. */ - public PreTernaryCommand(ParseBlock cond, ParseBlock op1, ParseBlock op2, - Token term) { + public PreTernaryCommand(final ParseBlock cond, final ParseBlock op1, + final ParseBlock op2, final Token term) { super(); if (cond == null) @@ -62,13 +62,13 @@ public class PreTernaryCommand extends AbstractInitialCommand } @Override - protected ITree> intNullDenotation(Token operator, ParserContext ctx) + protected ITree> intNullDenotation(final Token operator, final ParserContext ctx) throws ParserException { - ITree> cond = condBlock.parse(ctx); + final ITree> cond = condBlock.parse(ctx); - ITree> op1 = opblock1.parse(ctx); + final ITree> op1 = opblock1.parse(ctx); - ITree> op2 = opblock2.parse(ctx); + final ITree> op2 = opblock2.parse(ctx); return new Tree<>(trm, cond, op1, op2); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/RightBinaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/RightBinaryCommand.java index 8ddab06..35c828f 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/RightBinaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/RightBinaryCommand.java @@ -2,7 +2,7 @@ package bjc.pratt.commands; /** * A right-associative binary operator. - * + * * @author bjculkin * * @param @@ -15,11 +15,11 @@ package bjc.pratt.commands; public class RightBinaryCommand extends BinaryCommand { /** * Create a new right-associative operator. - * + * * @param precedence * The precedence of the operator. */ - public RightBinaryCommand(int precedence) { + public RightBinaryCommand(final int precedence) { super(precedence); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java index 0152471..2e12050 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java @@ -9,42 +9,43 @@ import bjc.utils.parserutils.ParserException; /** * A ternary command, like C's ?: - * + * * @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 TernaryCommand extends BinaryPostCommand { - private ParseBlock innerBlck; + private final ParseBlock innerBlck; - private Token mark; + private final Token mark; - private boolean nonassoc; + private final boolean nonassoc; /** * Create a new ternary command. - * + * * @param precedence * The precedence of this operator. - * + * * @param innerBlock * The representation of the inner block of the * expression. - * + * * @param marker * The token to use as the root of the AST node. - * + * * @param isNonassoc * Whether or not the conditional is associative. */ - public TernaryCommand(int precedence, ParseBlock innerBlock, Token marker, boolean isNonassoc) { + public TernaryCommand(final int precedence, final ParseBlock innerBlock, final Token marker, + final boolean isNonassoc) { super(precedence); if (innerBlock == null) @@ -57,20 +58,19 @@ public class TernaryCommand extends BinaryPostCommand { } @Override - public ITree> denote(ITree> operand, Token operator, ParserContext ctx) - throws ParserException { - ITree> inner = innerBlck.parse(ctx); + public ITree> denote(final ITree> operand, final Token operator, + final ParserContext ctx) throws ParserException { + final ITree> inner = innerBlck.parse(ctx); - ITree> outer = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, false); + final ITree> outer = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, + false); return new Tree<>(mark, inner, operand, outer); } @Override public int nextBinding() { - if (nonassoc) { - return leftBinding() - 1; - } + if (nonassoc) return leftBinding() - 1; return leftBinding(); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java index d75c8ce..a706ea8 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java @@ -10,41 +10,41 @@ import bjc.utils.parserutils.ParserException; /** * An initial command that transforms the result of another command. - * + * * @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 TransformingInitialCommand extends AbstractInitialCommand { - private InitialCommand internl; + private final InitialCommand internl; - private UnaryOperator>> transfrm; + private final UnaryOperator>> transfrm; /** * Create a new transforming initial command. - * + * * @param internal * The initial command to delegate to. - * + * * @param transform * The transform to apply to the returned tree. */ - public TransformingInitialCommand(InitialCommand internal, - UnaryOperator>> transform) { + public TransformingInitialCommand(final InitialCommand internal, + final UnaryOperator>> transform) { super(); internl = internal; transfrm = transform; } @Override - protected ITree> intNullDenotation(Token operator, ParserContext ctx) + protected ITree> intNullDenotation(final Token operator, final ParserContext ctx) throws ParserException { return transfrm.apply(internl.denote(operator, ctx)); } diff --git a/JPratt/src/main/java/bjc/pratt/commands/UnaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/UnaryCommand.java index 0689210..d36dc24 100644 --- a/JPratt/src/main/java/bjc/pratt/commands/UnaryCommand.java +++ b/JPratt/src/main/java/bjc/pratt/commands/UnaryCommand.java @@ -8,15 +8,15 @@ import bjc.utils.parserutils.ParserException; /** * A unary operator. - * + * * @author bjculkin * * @param * The key type of the tokens. - * + * * @param * The value type of the tokens. - * + * * @param * The state type of the parser. */ @@ -25,22 +25,20 @@ public class UnaryCommand extends AbstractInitialCommand { /** * Create a new unary command. - * + * * @param precedence * The precedence of this operator. */ - public UnaryCommand(int precedence) { - if(precedence < 0) { - throw new IllegalArgumentException("Precedence must be non-negative"); - } - + public UnaryCommand(final int precedence) { + if (precedence < 0) throw new IllegalArgumentException("Precedence must be non-negative"); + nullPwer = precedence; } @Override - protected ITree> intNullDenotation(Token operator, ParserContext ctx) + protected ITree> intNullDenotation(final Token operator, final ParserContext ctx) throws ParserException { - ITree> opr = ctx.parse.parseExpression(nullPwer, ctx.tokens, ctx.state, false); + final ITree> opr = ctx.parse.parseExpression(nullPwer, ctx.tokens, ctx.state, false); return new Tree<>(operator, opr); } -- cgit v1.2.3