/**
* Returns a new command containing the contents of the given multiple command but with with
* multiple successive (matching) escape commands folded into one.
*/
private static PCommand optimizeEscapeSequences(AMultipleCommand multiCommand) {
AEscapeCommand lastEscapeCommand = null;
LinkedList<PCommand> commands = new LinkedList<PCommand>();
for (PCommand command : multiCommand.getCommand()) {
AEscapeCommand escapeCommand = asSimpleEscapeCommand(command);
if (isSameEscaper(escapeCommand, lastEscapeCommand)) {
addToContents(contentsOf(lastEscapeCommand), escapeCommand.getCommand());
} else {
// Add the original command and set the escaper (possibly null)
commands.add(command);
lastEscapeCommand = escapeCommand;
}