From 15a2b29e48f134bc93cfd0a3d8512001e9242f3d Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Mon, 3 Jun 2024 17:33:53 -0400 Subject: Rename package to new domain Rename the package to the new domain --- .../bjc/pratt/commands/impls/InitialCommands.java | 241 --------------------- 1 file changed, 241 deletions(-) delete mode 100644 JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java (limited to 'JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java') diff --git a/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java b/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java deleted file mode 100644 index 6af6954..0000000 --- a/JPratt/src/main/java/bjc/pratt/commands/impls/InitialCommands.java +++ /dev/null @@ -1,241 +0,0 @@ -package bjc.pratt.commands.impls; - -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.blocks.ParseBlock; -import bjc.pratt.commands.*; -import bjc.pratt.tokens.Token; -import bjc.data.Tree; -import bjc.functypes.MapBuilder; - -/** - * * Contains factory methods for producing common implementations of - * {@link InitialCommand} - * - * @author EVE - * - */ -public class InitialCommands { - /** - * Create a new unary operator. - * - * @param The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @param precedence - * The precedence of the operator. - * - * @return A command implementing that operator. - */ - public static InitialCommand unary(final int precedence) { - return new UnaryCommand<>(precedence); - } - - /** - * Create a new grouping operator. - * - * @param The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @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(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. - * - * @param The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @return A command implementing the operator. - */ - public static InitialCommand leaf() { - return new LeafCommand<>(); - } - - /** - * Create a new pre-ternary operator, like an if-then-else statement. - * - * @param The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @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(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 The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @param val - * The value of the constant. - * - * @return A command implementing the constant. - */ - public static InitialCommand constant(final Tree> val) { - return new ConstantCommand<>(val); - } - - /** - * Create a new delimited command. This is for block-like constructs. - * - * @param The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @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(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); - - final GroupingCommand command = new GroupingCommand<>(scopedBlock, term); - - /* - * Remove the wrapper layer from grouping-command on top of - * RepeatingParseBlock. - */ - return denest(command); - } - - /** - * Create a new denesting command. - * - * This removes one tree-level, and is useful when combining complex - * parse blocks with commands. - * - * @param The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @param comm - * The command to denest. - * - * @return A command that denests the result of the provided command. - */ - public static InitialCommand denest(final InitialCommand comm) { - return new DenestingCommand<>(comm); - } - - /** - * Create a new 'panfix' command. - * - * Form is - * - * @param The key type for the tokens. - * @param The value type for the tokens. - * @param The context type for the tokens. - * - * @param precedence The precedence for this operator - * @param term The indicator for the operator - * @param marker The token to mark this tree - * - * @return A command that implements a panfix operator - */ - public static InitialCommand panfix(final int precedence, final K term, final Token marker) { - return new PanfixCommand<>(marker, term, precedence); - } - - /** - * Create a command that unconditionally returns a failure result. - * - * @param Token key type - * @param Token value type - * @param Context type - * - * @return A command that unconditionally fails - */ - public static InitialCommand fail() { - return (operator, ctx) -> CommandResult.fail(); - } - - /** - * Create a new builder for branching/sub-command style commands. - * - * @param Token key type - * @param Value key type - * @param Context type - * - * @return A builder for branching/sub-command style commands - */ - public static MapBuilder, InitialCommand> branch() { - return MapBuilder.from(BranchInitialCommand::new); - } -} \ No newline at end of file -- cgit v1.2.3