private List<Token> nestedToken(List<Token> input) throws ParserException {
        List<Token> output = new ArrayList<Token>();
        Deque<Token> sections = new LinkedList<Token>(); // stack
        Token section;
        List<Token> collector = output;

        for (Token token : input) {
            switch (token.type) {
            case Token.INVERTED:
            case Token.TRUE:
            case Token.SECTION:
                token.tokens = new ArrayList<Token>();
                sections.add(token);
                collector.add(token);
                collector = token.tokens;
                break;
            case '/':
                if (sections.isEmpty()) {
                    throw new ParserException("Unopened section: " + token.value);
                }
                section = sections.removeLast();
                if (!section.value.equals(token.value)) {
                    throw new ParserException("Unclosed " + token.value + "; in section"
                            + section.value);
                }

                if (sections.size() > 0) {
                    collector = sections.peekLast().tokens;
                } else {
                    collector = output;
                }
                break;
            default:
                collector.add(token);
                break;
            }
        }
        if (sections.size() > 0) {
            throw new ParserException("Unclosed section: " + sections.peek().value);
        }
        return output;
    }