code: protected String parse(Reader reader) throws IOException {
          if (!reader.markSupported()) {
              reader = new BufferedReader(reader);
          }
          StringWriter sw = new StringWriter();
          startScript(sw);
          int c;
          while ((c = reader.read()) != -1) {
              if (c == '<') {
                  reader.mark(1);
                  c = reader.read();
                  if (c != '%') {
                      sw.write('<');
                      reader.reset();
                  } else {
                      reader.mark(1);
                      c = reader.read();
                      if (c == '=') {
                          groovyExpression(reader, sw);
                      } else {
                          reader.reset();
                          groovySection(reader, sw);
                      }
                  }
                  continue; // at least '<' is consumed ... read next chars.
              }
              if (c == '$') {
                  reader.mark(1);
                  c = reader.read();
                  if (c != '{') {
                      sw.write('$');
                      reader.reset();
                  } else {
                      reader.mark(1);
                      sw.write("${");
                      processGSstring(reader, sw);
                  }
                  continue; // at least '$' is consumed ... read next chars.
              }
              if (c == '\"') {
                  sw.write('\\');
              }
              /*
               * Handle raw new line characters.
               */
              if (c == '\n' || c == '\r') {
                  if (c == '\r') { // on Windows, "\r\n" is a new line.
                      reader.mark(1);
                      c = reader.read();
                      if (c != '\n') {
                          reader.reset();
                      }
                  }
                  sw.write("\n");
                  continue;
              }
              sw.write(c);
          }
          endScript(sw);
          return sw.toString();
      }
docs: Parse the text document looking for <% or <%= and then call out to the appropriate handler, otherwise copy the text directly
  into the script while escaping quotes.
  
  @param reader a reader for the template text
  @return the parsed text
  @throws IOException if something goes wrong