@Override
public PlainBlockCommandState parse(MatchTemplateImpl template, String parameters) {
Label startLabel = new Label(), endLabel = new Label(), forkLabel = new Label();
startLabel.setDestinationToNextCommand(template);
template.appendOperation(new ForkOperation(template.getCurrentTemplatePosition(), forkLabel, false));
template.appendOperation(new JumpOperation(template.getCurrentTemplatePosition(), endLabel));
forkLabel.setDestinationToNextCommand(template);
int pos = parameters.indexOf(" ");
int pos2 = parameters.indexOf("\t");
if (pos2 != -1 && (pos == -1 || pos > pos2))
pos = pos2;
String commandName, commandParameters;
if (pos == -1) {
commandName = parameters.toLowerCase();
commandParameters = "";
} else {
commandName = parameters.substring(0, pos).toLowerCase();
commandParameters = parameters.substring(pos + 1);
}
Command cmd = Command.getCommand(commandName);
if (cmd != null) {
PlainBlockCommandState bcs = cmd.parse(template, commandParameters);
if (bcs != null)
throw new RuntimeException("Optional/Repeated command cannot be used for block commands!");
} else {
throw new RuntimeException("Unsupported command: " + commandName);
}
if (repeated) {
template.appendOperation(new JumpOperation(template.getCurrentTemplatePosition(), startLabel));
}
endLabel.setDestinationToNextCommand(template);
return null;
}