diff options
Diffstat (limited to 'JPratt/src/main/java/com/ashardalon/pratt/commands/BranchInitialCommand.java')
| -rw-r--r-- | JPratt/src/main/java/com/ashardalon/pratt/commands/BranchInitialCommand.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/JPratt/src/main/java/com/ashardalon/pratt/commands/BranchInitialCommand.java b/JPratt/src/main/java/com/ashardalon/pratt/commands/BranchInitialCommand.java new file mode 100644 index 0000000..0e17287 --- /dev/null +++ b/JPratt/src/main/java/com/ashardalon/pratt/commands/BranchInitialCommand.java @@ -0,0 +1,39 @@ +package com.ashardalon.pratt.commands; + +import java.util.Map; + +import com.ashardalon.pratt.ParserContext; +import com.ashardalon.pratt.tokens.Token; + +import bjc.utils.parserutils.ParserException; + +/** + * Represents a initial command that has a number of 'sub-commands' in the way that Go/Git CLI does. + * + * @author bjcul + * + * @param <K> Token key type + * @param <V> Token value type + * @param <C> Parser context type + */ +public class BranchInitialCommand<K, V, C> implements InitialCommand<K, V, C> { + private Map<K, InitialCommand<K, V, C>> comMap; + + /** + * Create a new branch initial command + * + * @param mep The map containing the commands + */ + public BranchInitialCommand(Map<K, InitialCommand<K, V, C>> mep) { + this.comMap = mep; + } + + @Override + public CommandResult<K, V> denote(Token<K, V> operator, ParserContext<K, V, C> ctx) throws ParserException { + Token<K, V> curToken = ctx.tokens.current(); + ctx.tokens.expect(comMap.keySet()); + + return comMap.get(curToken.getKey()).denote(curToken, ctx); + } + +} |
