private TemplateEntry parseExpression(Collection<TokenType> endTokens) throws ParseError {
List<TemplateEntry> entries = new ArrayList<>();
while (true) {
TemplateEntry templateEntry;
Token token = tokenizer.lookAhead();
if (token.getType() == TokenType.CONDITION_START) {
templateEntry = parseCondition();
} else if (token.getType() == TokenType.CONTEXT_SWITCH_START) {
templateEntry = parseContextSwitch();
} else if (token.getType() == TokenType.VARIABLE_START) {
templateEntry = parseVariable();
} else if (endTokens.contains(token.getType()))
return CompoundTemplateEntry.fromArray(entries.toArray(new TemplateEntry[entries.size()]));
else if (token.getType() == TokenType.TEXT) {
tokenizer.nextToken();
templateEntry = new StaticText(token.getText());
} else
throw new ParseError(token);
entries.add(templateEntry);
}
}