summaryrefslogtreecommitdiff
path: root/JPratt/src/main/java/bjc/pratt/commands/BranchInitialCommand.java
blob: 3f3093eff6eaf4cda9ad83cc8f6772860bc5c46d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package bjc.pratt.commands;

import java.util.Map;

import bjc.pratt.ParserContext;
import bjc.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);
	}

}