public String process() throws IOException {
        StringWriter result = new StringWriter();
        int nesting = 0;

        String line;

        while ((line = StringHelper.readLine(reader)) != null) {
            Matcher m = begin.matcher(line);
            if (m.matches()) {
                nesting++;
            }
            else {
                m = end.matcher(line);
                if (m.matches()) {
                    if (nesting == 0) {
                        throw new IllegalArgumentException("Invalid nesting");
                    }
                    nesting--;
                }
                else if (nesting == 0) {
                    line = processComment(line);
                    if (line != null && line.length() > 0) {
                        line = processPrint(line);
                        if (line != null && line.length() > 0) {
                            result.write(line);
                        }
                    }
                }
            }
        }

        return result.toString();
    }