summaryrefslogtreecommitdiff
path: root/JPratt/src/main/java/bjc/pratt/commands
diff options
context:
space:
mode:
authorStudent <student@Administrators-iMac-2.local>2017-04-12 11:05:57 -0400
committerStudent <student@Administrators-iMac-2.local>2017-04-12 11:05:57 -0400
commit22c356cd411cf0fcc18d548291af26bc7588a3aa (patch)
tree4f24fdda182b358ca96aed2249bb4e8a19994747 /JPratt/src/main/java/bjc/pratt/commands
parent2dc1b5dd145ab0e2b3e3df67f967a9c07ed6d303 (diff)
parentf394306a4b65a3328551f9f6b8d4abff8bfd5b27 (diff)
Merge branch 'master' of https://github.com/bculkin2442/JPratt.git
Diffstat (limited to 'JPratt/src/main/java/bjc/pratt/commands')
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java12
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/BinaryCommand.java18
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java18
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java40
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java13
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java21
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/NonInitialCommand.java65
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java42
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/ChainCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/ChainCommand.java)44
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/ConstantCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/ConstantCommand.java)21
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/DefaultInitialCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/DefaultInitialCommand.java)15
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/DefaultNonInitialCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/DefaultNonInitialCommand.java)15
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/DenestingCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/DenestingCommand.java)25
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/GroupingCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/GroupingCommand.java)27
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java (renamed from JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java)109
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/LeafCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/LeafCommand.java)15
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/LeftBinaryCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/LeftBinaryCommand.java)14
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/NonBinaryCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/NonBinaryCommand.java)14
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/NonInitialCommands.java (renamed from JPratt/src/main/java/bjc/pratt/commands/NonInitialCommands.java)87
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/PostCircumfixCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/PostCircumfixCommand.java)35
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/PostfixCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/PostfixCommand.java)19
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/PreTernaryCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java)51
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/RightBinaryCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/RightBinaryCommand.java)10
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/TernaryCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java)47
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/TransformingInitialCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java)33
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/impls/UnaryCommand.java (renamed from JPratt/src/main/java/bjc/pratt/commands/UnaryCommand.java)25
26 files changed, 516 insertions, 319 deletions
diff --git a/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java
index b5a789c..c1f9f6b 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/AbstractInitialCommand.java
@@ -1,28 +1,28 @@
package bjc.pratt.commands;
-import bjc.pratt.InitialCommand;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.parserutils.ParserException;
/**
* Abstract base for initial commands.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public abstract class AbstractInitialCommand<K, V, C> implements InitialCommand<K, V, C> {
@Override
- public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException {
+ public ITree<Token<K, V>> denote(final Token<K, V> operator, final ParserContext<K, V, C> 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..06b26aa 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/BinaryCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/BinaryCommand.java
@@ -1,42 +1,42 @@
package bjc.pratt.commands;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A binary operator.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public abstract class BinaryCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
/**
* 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<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx)
- throws ParserException {
- ITree<Token<K, V>> opr = ctx.parse.parseExpression(rightBinding(), ctx.tokens, ctx.state, false);
+ public ITree<Token<K, V>> denote(final ITree<Token<K, V>> operand, final Token<K, V> operator,
+ final ParserContext<K, V, C> ctx) throws ParserException {
+ final ITree<Token<K, V>> 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..943554c 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java
@@ -1,18 +1,16 @@
package bjc.pratt.commands;
-import bjc.pratt.NonInitialCommand;
-
/**
* A operator with fixed precedence.
- *
+ *
* @author bjculkin
- *
+ *
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
@@ -21,14 +19,12 @@ public abstract class BinaryPostCommand<K, V, C> extends NonInitialCommand<K, V,
/**
* Create a new operator with fixed precedence.
- *
+ *
* @param precedence
* The precedence of the operator.
*/
- public BinaryPostCommand(int precedence) {
- if (precedence < 0) {
- throw new IllegalArgumentException("Precedence must be non-negative");
- }
+ public BinaryPostCommand(final int precedence) {
+ if (precedence < 0) throw new IllegalArgumentException("Precedence must be non-negative");
leftPower = precedence;
}
diff --git a/JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java
new file mode 100644
index 0000000..57dc2d1
--- /dev/null
+++ b/JPratt/src/main/java/bjc/pratt/commands/InitialCommand.java
@@ -0,0 +1,40 @@
+package bjc.pratt.commands;
+
+import bjc.pratt.ParserContext;
+import bjc.pratt.tokens.Token;
+import bjc.utils.data.ITree;
+import bjc.utils.parserutils.ParserException;
+
+/**
+ * Represents an initial command in parsing.
+ *
+ * @author EVE
+ *
+ * @param <K>
+ * The key type for the tokens.
+ *
+ * @param <V>
+ * The value type for the tokens.
+ *
+ * @param <C>
+ * The state type of the parser.
+ *
+ *
+ */
+@FunctionalInterface
+public interface InitialCommand<K, V, C> {
+ /**
+ * Construct the null denotation of this command.
+ *
+ * @param operator
+ * The operator for this command.
+ * @param ctx
+ * The context for the command.
+ *
+ * @return The tree for this command.
+ *
+ * @throws ParserException
+ * If something goes wrong during parsing.
+ */
+ ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException;
+}
diff --git a/JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java
new file mode 100644
index 0000000..9f14f36
--- /dev/null
+++ b/JPratt/src/main/java/bjc/pratt/commands/MetaInitialCommand.java
@@ -0,0 +1,13 @@
+package bjc.pratt.commands;
+
+import bjc.pratt.ParserContext;
+
+/**
+ * A 'meta-command' that yields the actual command to use.
+ *
+ * @author bjculkin
+ *
+ */
+public interface MetaInitialCommand<K, V, C> {
+ InitialCommand<K, V, C> getCommand(ParserContext<K, V, C> ctx);
+}
diff --git a/JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java
new file mode 100644
index 0000000..3a5cba4
--- /dev/null
+++ b/JPratt/src/main/java/bjc/pratt/commands/MetaNonInitialCommand.java
@@ -0,0 +1,21 @@
+package bjc.pratt.commands;
+
+import bjc.pratt.ParserContext;
+
+/**
+ * A 'meta-command' for non-initial commands.
+ *
+ * @author bjculkin
+ *
+ * @param <K>
+ * The token key type.
+ *
+ * @param <V>
+ * The token value type.
+ *
+ * @param <C>
+ * The parser state type.
+ */
+public interface MetaNonInitialCommand<K, V, C> {
+ NonInitialCommand<K, V, C> getCommand(ParserContext<K, V, C> ctx);
+}
diff --git a/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommand.java
new file mode 100644
index 0000000..d06e336
--- /dev/null
+++ b/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommand.java
@@ -0,0 +1,65 @@
+package bjc.pratt.commands;
+
+import bjc.pratt.ParserContext;
+import bjc.pratt.tokens.Token;
+import bjc.utils.data.ITree;
+import bjc.utils.parserutils.ParserException;
+
+/**
+ * Represents a non-initial command in parsing.
+ *
+ * @author EVE
+ *
+ * @param <K>
+ * The key type for the tokens.
+ *
+ * @param <V>
+ * The value type for the tokens.
+ *
+ * @param <C>
+ * The state type of the parser.
+ *
+ */
+public abstract class NonInitialCommand<K, V, C> {
+ /**
+ * Construct the left denotation of this command.
+ *
+ * @param operand
+ * The left-hand operand of this command.
+ * @param operator
+ * The operator for this command.
+ *
+ * @param ctx
+ * The state needed for commands.
+ *
+ * @return The tree this command forms.
+ *
+ * @throws ParserException
+ * If something went wrong during parsing.
+ */
+ public abstract ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator,
+ ParserContext<K, V, C> ctx) throws ParserException;
+
+ /**
+ * Get the left-binding power of this command.
+ *
+ * This represents the general precedence of this command.
+ *
+ * @return The left-binding power of this command.
+ */
+ public abstract int leftBinding();
+
+ /**
+ * Get the next-binding power of this command.
+ *
+ * This represents the highest precedence of command this command can be
+ * the left operand of.
+ *
+ * This is the same as the left-binding power by default.
+ *
+ * @return The next-binding power of this command.
+ */
+ public int nextBinding() {
+ return leftBinding();
+ }
+}
diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java
new file mode 100644
index 0000000..3e8c8c2
--- /dev/null
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/BlockInitialCommand.java
@@ -0,0 +1,42 @@
+package bjc.pratt.commands.impls;
+
+import bjc.pratt.ParserContext;
+import bjc.pratt.blocks.ParseBlock;
+import bjc.pratt.commands.AbstractInitialCommand;
+import bjc.pratt.tokens.Token;
+import bjc.utils.data.ITree;
+import bjc.utils.parserutils.ParserException;
+
+/**
+ * An initial command that delegates all the work to a {@link ParseBlock}
+ *
+ * @author bjculkin
+ * @param <K>
+ * The token key type.
+ *
+ * @param <V>
+ * The token value type.
+ *
+ * @param <C>
+ * The parser state type.
+ *
+ */
+public class BlockInitialCommand<K, V, C> extends AbstractInitialCommand<K, V, C> {
+ private final ParseBlock<K, V, C> blck;
+
+ /**
+ * Create a new block initial command.
+ *
+ * @param block
+ * The block to delegate to.
+ */
+ public BlockInitialCommand(final ParseBlock<K, V, C> block) {
+ blck = block;
+ }
+
+ @Override
+ protected ITree<Token<K, V>> intNullDenotation(final Token<K, V> operator, final ParserContext<K, V, C> ctx)
+ throws ParserException {
+ return blck.parse(ctx);
+ }
+} \ No newline at end of file
diff --git a/JPratt/src/main/java/bjc/pratt/commands/ChainCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/ChainCommand.java
index c7a10b1..2a9bf35 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/ChainCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/ChainCommand.java
@@ -1,45 +1,46 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
+
+import java.util.Set;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.BinaryPostCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
-import java.util.Set;
-
/**
* Create a new chained operator.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class ChainCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
- private Set<K> chainWith;
+ private final Set<K> chainWith;
- private Token<K, V> chain;
+ private final Token<K, V> 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<K> chainSet, Token<K, V> chainMarker) {
+ public ChainCommand(final int precedence, final Set<K> chainSet, final Token<K, V> chainMarker) {
super(precedence);
chainWith = chainSet;
@@ -47,23 +48,24 @@ public class ChainCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
}
@Override
- public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx)
- throws ParserException {
- ITree<Token<K, V>> tree = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, false);
+ public ITree<Token<K, V>> denote(final ITree<Token<K, V>> operand, final Token<K, V> operator,
+ final ParserContext<K, V, C> ctx) throws ParserException {
+ final ITree<Token<K, V>> tree = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state,
+ false);
- ITree<Token<K, V>> res = new Tree<>(operator, operand, tree);
+ final ITree<Token<K, V>> res = new Tree<>(operator, operand, tree);
if (chainWith.contains(ctx.tokens.current().getKey())) {
- Token<K, V> tok = ctx.tokens.current();
+ final Token<K, V> tok = ctx.tokens.current();
ctx.tokens.next();
- ITree<Token<K, V>> other = denote(tree, tok,
+ final ITree<Token<K, V>> other = denote(tree, tok,
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/ConstantCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/ConstantCommand.java
index 86a172f..16af5aa 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/ConstantCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/ConstantCommand.java
@@ -1,40 +1,41 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.InitialCommand;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.InitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.parserutils.ParserException;
/**
* A command that represents a specific tree.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class ConstantCommand<K, V, C> implements InitialCommand<K, V, C> {
- private ITree<Token<K, V>> val;
+ private final ITree<Token<K, V>> val;
/**
* Create a new constant.
- *
+ *
* @param con
* The tree this constant represents.
*/
- public ConstantCommand(ITree<Token<K, V>> con) {
+ public ConstantCommand(final ITree<Token<K, V>> con) {
val = con;
}
@Override
- public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException {
+ public ITree<Token<K, V>> denote(final Token<K, V> operator, final ParserContext<K, V, C> 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/impls/DefaultInitialCommand.java
index 717444a..16d2e59 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/DefaultInitialCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/DefaultInitialCommand.java
@@ -1,28 +1,29 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.InitialCommand;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.InitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.parserutils.ParserException;
/**
* Default implementation of an initial command.
- *
+ *
* @author EVE
*
* @param <K>
* The key type of the token.
- *
+ *
* @param <V>
* The value type of the token.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class DefaultInitialCommand<K, V, C> implements InitialCommand<K, V, C> {
@Override
- public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException {
+ public ITree<Token<K, V>> denote(final Token<K, V> operator, final ParserContext<K, V, C> 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/impls/DefaultNonInitialCommand.java
index aeb337d..48aab29 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/DefaultNonInitialCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/DefaultNonInitialCommand.java
@@ -1,27 +1,28 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.NonInitialCommand;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.NonInitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
/**
* Default implementation of a non-initial command.
- *
+ *
* @author EVE
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class DefaultNonInitialCommand<K, V, C> extends NonInitialCommand<K, V, C> {
@Override
- public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx) {
+ public ITree<Token<K, V>> denote(final ITree<Token<K, V>> operand, final Token<K, V> operator,
+ final ParserContext<K, V, C> 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/impls/DenestingCommand.java
index 9b4518f..220e4cc 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/DenestingCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/DenestingCommand.java
@@ -1,44 +1,45 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.InitialCommand;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.AbstractInitialCommand;
+import bjc.pratt.commands.InitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
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 <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*
*/
public class DenestingCommand<K, V, C> extends AbstractInitialCommand<K, V, C> {
- private InitialCommand<K, V, C> wrapped;
+ private final InitialCommand<K, V, C> wrapped;
/**
* Create a new transforming initial command.
- *
+ *
* @param internal
* The initial command to delegate to.
*/
- public DenestingCommand(InitialCommand<K, V, C> internal) {
+ public DenestingCommand(final InitialCommand<K, V, C> internal) {
wrapped = internal;
}
@Override
- protected ITree<Token<K, V>> intNullDenotation(Token<K, V> operator, ParserContext<K, V, C> ctx)
+ protected ITree<Token<K, V>> intNullDenotation(final Token<K, V> operator, final ParserContext<K, V, C> 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/impls/GroupingCommand.java
index 1a8d3c8..28f1299 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/GroupingCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/GroupingCommand.java
@@ -1,50 +1,51 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.ParseBlock;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.blocks.ParseBlock;
+import bjc.pratt.commands.AbstractInitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A grouping operator.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class GroupingCommand<K, V, C> extends AbstractInitialCommand<K, V, C> {
- private ParseBlock<K, V, C> innerBlock;
+ private final ParseBlock<K, V, C> innerBlock;
- private Token<K, V> mark;
+ private final Token<K, V> 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<K, V, C> inner, Token<K, V> marker) {
+ public GroupingCommand(final ParseBlock<K, V, C> inner, final Token<K, V> marker) {
innerBlock = inner;
mark = marker;
}
@Override
- protected ITree<Token<K, V>> intNullDenotation(Token<K, V> operator, ParserContext<K, V, C> ctx)
+ protected ITree<Token<K, V>> intNullDenotation(final Token<K, V> operator, final ParserContext<K, V, C> ctx)
throws ParserException {
- ITree<Token<K, V>> opr = innerBlock.parse(ctx);
+ final ITree<Token<K, V>> 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/impls/InitialCommands.java
index 3ece14c..8da758a 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java
@@ -1,57 +1,60 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.InitialCommand;
-import bjc.pratt.ParseBlock;
-import bjc.pratt.Token;
-import bjc.utils.data.ITree;
+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 static bjc.pratt.blocks.ParseBlocks.*;
+import bjc.pratt.blocks.ParseBlock;
+import bjc.pratt.commands.InitialCommand;
+import bjc.pratt.tokens.Token;
+import bjc.utils.data.ITree;
/**
* * 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 <K, V, C> InitialCommand<K, V, C> unary(int precedence) {
+ public static <K, V, C> InitialCommand<K, V, C> 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 <K, V, C> InitialCommand<K, V, C> grouping(int precedence, K term, Token<K, V> mark) {
- ParseBlock<K, V, C> innerBlock = simple(precedence, term, null);
+ public static <K, V, C> InitialCommand<K, V, C> grouping(final int precedence, final K term,
+ final Token<K, V> mark) {
+ final ParseBlock<K, V, C> innerBlock = simple(precedence, term, null);
return new GroupingCommand<>(innerBlock, mark);
}
/**
* Create a new leaf operator.
- *
+ *
* @return A command implementing the operator.
*/
public static <K, V, C> InitialCommand<K, V, C> 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 <K, V, C> InitialCommand<K, V, C> preTernary(int cond1, int block1, int block2, K mark1, K mark2,
- Token<K, V> term) {
- ParseBlock<K, V, C> condBlock = simple(cond1, mark1, null);
- ParseBlock<K, V, C> opblock1 = simple(block1, mark2, null);
- ParseBlock<K, V, C> opblock2 = simple(block2, null, null);
+ public static <K, V, C> InitialCommand<K, V, C> preTernary(final int cond1, final int block1, final int block2,
+ final K mark1, final K mark2, final Token<K, V> term) {
+ final ParseBlock<K, V, C> condBlock = simple(cond1, mark1, null);
+ final ParseBlock<K, V, C> opblock1 = simple(block1, mark2, null);
+ final ParseBlock<K, V, C> 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 <K, V, C> InitialCommand<K, V, C> constant(ITree<Token<K, V>> val) {
+ public static <K, V, C> InitialCommand<K, V, C> constant(final ITree<Token<K, V>> 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 <K, V, C> InitialCommand<K, V, C> delimited(int inner, K delim, K mark, Token<K, V> term,
- UnaryOperator<C> onEnter, UnaryOperator<C> onDelim, UnaryOperator<C> onExit,
- boolean statement) {
- ParseBlock<K, V, C> innerBlock = simple(inner, null, null);
- ParseBlock<K, V, C> delimsBlock = repeating(innerBlock, delim, mark, term, onDelim);
- ParseBlock<K, V, C> scopedBlock = trigger(delimsBlock, onEnter, onExit);
+ public static <K, V, C> InitialCommand<K, V, C> delimited(final int inner, final K delim, final K mark,
+ final Token<K, V> term, final UnaryOperator<C> onEnter, final UnaryOperator<C> onDelim,
+ final UnaryOperator<C> onExit, final boolean statement) {
+ final ParseBlock<K, V, C> innerBlock = simple(inner, null, null);
+ final ParseBlock<K, V, C> delimsBlock = repeating(innerBlock, delim, mark, term, onDelim);
+ final ParseBlock<K, V, C> scopedBlock = trigger(delimsBlock, onEnter, onExit);
- GroupingCommand<K, V, C> command = new GroupingCommand<>(scopedBlock, term);
+ final GroupingCommand<K, V, C> 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 <K, V, C> InitialCommand<K, V, C> denest(InitialCommand<K, V, C> comm) {
+ public static <K, V, C> InitialCommand<K, V, C> denest(final InitialCommand<K, V, C> comm) {
return new DenestingCommand<>(comm);
}
-}
+} \ No newline at end of file
diff --git a/JPratt/src/main/java/bjc/pratt/commands/LeafCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/LeafCommand.java
index 798b9ce..bb999f6 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/LeafCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/LeafCommand.java
@@ -1,29 +1,30 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.InitialCommand;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.InitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A operator that stands for itself.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class LeafCommand<K, V, C> implements InitialCommand<K, V, C> {
@Override
- public ITree<Token<K, V>> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException {
+ public ITree<Token<K, V>> denote(final Token<K, V> operator, final ParserContext<K, V, C> 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/impls/LeftBinaryCommand.java
index 4a481d7..9727dcb 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/LeftBinaryCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/LeftBinaryCommand.java
@@ -1,27 +1,29 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
+
+import bjc.pratt.commands.BinaryCommand;
/**
* A left-associative operator.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class LeftBinaryCommand<K, V, C> extends BinaryCommand<K, V, C> {
/**
* 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/impls/NonBinaryCommand.java
index d1208bd..2d92780 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/NonBinaryCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/NonBinaryCommand.java
@@ -1,27 +1,29 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
+
+import bjc.pratt.commands.BinaryCommand;
/**
* A non-associative operator.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class NonBinaryCommand<K, V, C> extends BinaryCommand<K, V, C> {
/**
* 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/impls/NonInitialCommands.java
index b7eda95..a2c158c 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/NonInitialCommands.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/NonInitialCommands.java
@@ -1,139 +1,140 @@
-package bjc.pratt.commands;
-
-import bjc.pratt.NonInitialCommand;
-import bjc.pratt.ParseBlock;
-import bjc.pratt.Token;
-import bjc.pratt.blocks.SimpleParseBlock;
+package bjc.pratt.commands.impls;
import java.util.Set;
+import bjc.pratt.blocks.ParseBlock;
+import bjc.pratt.blocks.SimpleParseBlock;
+import bjc.pratt.commands.NonInitialCommand;
+import bjc.pratt.tokens.Token;
+
/**
* 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 <K, V, C> NonInitialCommand<K, V, C> infixLeft(int precedence) {
+ public static <K, V, C> NonInitialCommand<K, V, C> 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 <K, V, C> NonInitialCommand<K, V, C> infixRight(int precedence) {
+ public static <K, V, C> NonInitialCommand<K, V, C> 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 <K, V, C> NonInitialCommand<K, V, C> infixNon(int precedence) {
+ public static <K, V, C> NonInitialCommand<K, V, C> 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 <K, V, C> NonInitialCommand<K, V, C> chain(int precedence, Set<K> chainSet, Token<K, V> marker) {
+ public static <K, V, C> NonInitialCommand<K, V, C> chain(final int precedence, final Set<K> chainSet,
+ final Token<K, V> 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 <K, V, C> NonInitialCommand<K, V, C> postfix(int precedence) {
+ public static <K, V, C> NonInitialCommand<K, V, C> 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 <K, V, C> NonInitialCommand<K, V, C> postCircumfix(int precedence, int insidePrecedence, K closer,
- Token<K, V> marker) {
- ParseBlock<K, V, C> innerBlock = new SimpleParseBlock<>(insidePrecedence, closer, null);
+ public static <K, V, C> NonInitialCommand<K, V, C> postCircumfix(final int precedence,
+ final int insidePrecedence, final K closer, final Token<K, V> marker) {
+ final ParseBlock<K, V, C> innerBlock = new SimpleParseBlock<>(insidePrecedence, null, closer);
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 <K, V, C> NonInitialCommand<K, V, C> ternary(int precedence, int insidePrecedence, K closer,
- Token<K, V> marker, boolean nonassoc) {
- ParseBlock<K, V, C> innerBlock = new SimpleParseBlock<>(insidePrecedence, closer, null);
+ public static <K, V, C> NonInitialCommand<K, V, C> ternary(final int precedence, final int insidePrecedence,
+ final K closer, final Token<K, V> marker, final boolean nonassoc) {
+ final ParseBlock<K, V, C> innerBlock = new SimpleParseBlock<>(insidePrecedence, null, closer);
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/impls/PostCircumfixCommand.java
index 6bed0ff..c1d70b8 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/PostCircumfixCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/PostCircumfixCommand.java
@@ -1,49 +1,48 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.ParseBlock;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.blocks.ParseBlock;
+import bjc.pratt.commands.BinaryPostCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A post-circumfix operator, like array indexing.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class PostCircumfixCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
- private ParseBlock<K, V, C> innerBlock;
+ private final ParseBlock<K, V, C> innerBlock;
- private Token<K, V> mark;
+ private final Token<K, V> 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<K, V, C> inner, Token<K, V> marker) {
+ public PostCircumfixCommand(final int precedence, final ParseBlock<K, V, C> inner, final Token<K, V> 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 +50,9 @@ public class PostCircumfixCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
}
@Override
- public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx)
- throws ParserException {
- ITree<Token<K, V>> inside = innerBlock.parse(ctx);
+ public ITree<Token<K, V>> denote(final ITree<Token<K, V>> operand, final Token<K, V> operator,
+ final ParserContext<K, V, C> ctx) throws ParserException {
+ final ITree<Token<K, V>> 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/impls/PostfixCommand.java
index 5e2ce28..00c7ad2 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/PostfixCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/PostfixCommand.java
@@ -1,39 +1,40 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.BinaryPostCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A postfix operator.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class PostfixCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
/**
* 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<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx)
- throws ParserException {
+ public ITree<Token<K, V>> denote(final ITree<Token<K, V>> operand, final Token<K, V> operator,
+ final ParserContext<K, V, C> 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/impls/PreTernaryCommand.java
index efa7872..fa63c9c 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/PreTernaryCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/PreTernaryCommand.java
@@ -1,51 +1,52 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.ParseBlock;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.blocks.ParseBlock;
+import bjc.pratt.commands.AbstractInitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A prefix ternary operator, like an if/then/else group.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class PreTernaryCommand<K, V, C> extends AbstractInitialCommand<K, V, C> {
- private Token<K, V> term;
+ private final Token<K, V> trm;
- private ParseBlock<K, V, C> condBlock;
+ private final ParseBlock<K, V, C> condBlock;
- private ParseBlock<K, V, C> opblock1;
- private ParseBlock<K, V, C> opblock2;
+ private final ParseBlock<K, V, C> opblock1;
+ private final ParseBlock<K, V, C> 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<K, V, C> cond, ParseBlock<K, V, C> op1, ParseBlock<K, V, C> op2,
- Token<K, V> term) {
+ public PreTernaryCommand(final ParseBlock<K, V, C> cond, final ParseBlock<K, V, C> op1,
+ final ParseBlock<K, V, C> op2, final Token<K, V> term) {
super();
if (cond == null)
@@ -54,22 +55,22 @@ 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
- protected ITree<Token<K, V>> intNullDenotation(Token<K, V> operator, ParserContext<K, V, C> ctx)
+ protected ITree<Token<K, V>> intNullDenotation(final Token<K, V> operator, final ParserContext<K, V, C> ctx)
throws ParserException {
- ITree<Token<K, V>> cond = condBlock.parse(ctx);
+ final ITree<Token<K, V>> cond = condBlock.parse(ctx);
- ITree<Token<K, V>> op1 = opblock1.parse(ctx);
+ final ITree<Token<K, V>> op1 = opblock1.parse(ctx);
- ITree<Token<K, V>> op2 = opblock2.parse(ctx);
+ final 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/RightBinaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/RightBinaryCommand.java
index 8ddab06..c3887ee 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/RightBinaryCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/RightBinaryCommand.java
@@ -1,8 +1,10 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
+
+import bjc.pratt.commands.BinaryCommand;
/**
* A right-associative binary operator.
- *
+ *
* @author bjculkin
*
* @param <K>
@@ -15,11 +17,11 @@ package bjc.pratt.commands;
public class RightBinaryCommand<K, V, C> extends BinaryCommand<K, V, C> {
/**
* 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/impls/TernaryCommand.java
index bac12cd..92355c0 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/TernaryCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/TernaryCommand.java
@@ -1,50 +1,52 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
-import bjc.pratt.ParseBlock;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.blocks.ParseBlock;
+import bjc.pratt.commands.BinaryPostCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A ternary command, like C's ?:
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class TernaryCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
- private ParseBlock<K, V, C> innerBlck;
+ private final ParseBlock<K, V, C> innerBlck;
- private Token<K, V> mark;
+ private final Token<K, V> 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<K, V, C> innerBlock, Token<K, V> marker, boolean isNonassoc) {
+ public TernaryCommand(final int precedence, final ParseBlock<K, V, C> innerBlock, final Token<K, V> marker,
+ final boolean isNonassoc) {
super(precedence);
if (innerBlock == null)
@@ -57,21 +59,20 @@ public class TernaryCommand<K, V, C> extends BinaryPostCommand<K, V, C> {
}
@Override
- public ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator, ParserContext<K, V, C> ctx)
- throws ParserException {
- ITree<Token<K, V>> inner = innerBlck.parse(ctx);
+ public ITree<Token<K, V>> denote(final ITree<Token<K, V>> operand, final Token<K, V> operator,
+ final ParserContext<K, V, C> ctx) throws ParserException {
+ final ITree<Token<K, V>> inner = innerBlck.parse(ctx);
- ITree<Token<K, V>> outer = ctx.parse.parseExpression(1 + leftBinding(), ctx.tokens, ctx.state, false);
+ final ITree<Token<K, V>> 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;
- } else {
- return leftBinding();
- }
+ if (nonassoc) return leftBinding() - 1;
+
+ 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/impls/TransformingInitialCommand.java
index 9ec3631..e6c509c 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/TransformingInitialCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/TransformingInitialCommand.java
@@ -1,52 +1,53 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
import java.util.function.UnaryOperator;
-import bjc.pratt.InitialCommand;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.AbstractInitialCommand;
+import bjc.pratt.commands.InitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.parserutils.ParserException;
/**
* An initial command that transforms the result of another command.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
public class TransformingInitialCommand<K, V, C> extends AbstractInitialCommand<K, V, C> {
- private InitialCommand<K, V, C> internal;
+ private final InitialCommand<K, V, C> internl;
- private UnaryOperator<ITree<Token<K, V>>> transform;
+ private final UnaryOperator<ITree<Token<K, V>>> 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<K, V, C> internal,
- UnaryOperator<ITree<Token<K, V>>> transform) {
+ public TransformingInitialCommand(final InitialCommand<K, V, C> internal,
+ final 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)
+ protected ITree<Token<K, V>> intNullDenotation(final Token<K, V> operator, final 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/commands/UnaryCommand.java b/JPratt/src/main/java/bjc/pratt/commands/impls/UnaryCommand.java
index 0689210..156dee0 100644
--- a/JPratt/src/main/java/bjc/pratt/commands/UnaryCommand.java
+++ b/JPratt/src/main/java/bjc/pratt/commands/impls/UnaryCommand.java
@@ -1,22 +1,23 @@
-package bjc.pratt.commands;
+package bjc.pratt.commands.impls;
import bjc.pratt.ParserContext;
-import bjc.pratt.Token;
+import bjc.pratt.commands.AbstractInitialCommand;
+import bjc.pratt.tokens.Token;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;
import bjc.utils.parserutils.ParserException;
/**
* A unary operator.
- *
+ *
* @author bjculkin
*
* @param <K>
* The key type of the tokens.
- *
+ *
* @param <V>
* The value type of the tokens.
- *
+ *
* @param <C>
* The state type of the parser.
*/
@@ -25,22 +26,20 @@ public class UnaryCommand<K, V, C> extends AbstractInitialCommand<K, V, C> {
/**
* 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<Token<K, V>> intNullDenotation(Token<K, V> operator, ParserContext<K, V, C> ctx)
+ protected ITree<Token<K, V>> intNullDenotation(final Token<K, V> operator, final ParserContext<K, V, C> ctx)
throws ParserException {
- ITree<Token<K, V>> opr = ctx.parse.parseExpression(nullPwer, ctx.tokens, ctx.state, false);
+ final ITree<Token<K, V>> opr = ctx.parse.parseExpression(nullPwer, ctx.tokens, ctx.state, false);
return new Tree<>(operator, opr);
}