summaryrefslogtreecommitdiff
path: root/JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:49:54 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:49:54 -0400
commit56f07e9a3aaa873fe385d224f088f048dbafa8f7 (patch)
tree64fae78f95fd1c233689ecf3dda2e2b645bb8d33 /JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java
parent251419e1f0ab8eb04d21287b708b06a552f4c58a (diff)
Cleanup
Diffstat (limited to 'JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java')
-rw-r--r--JPratt/src/main/java/bjc/pratt/commands/InitialCommands.java103
1 files changed, 53 insertions, 50 deletions
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 <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);
}
}