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;
    }
    if (c == '$') {
      reader.mark(1);
      c=reader.read();
      if (c != '{') {
        sw.write('$');
        reader.reset();
      }
 else {
        reader.mark(1);
        sw.write("${");
        processGSstring(reader,sw);
      }
      continue;
    }
    if (c == '\"') {
      sw.write('\\');
    }
    if (c == '\n' || c == '\r') {
      if (c == '\r') {
        reader.mark(1);
        c=reader.read();
        if (c != '\n') {
          reader.reset();
        }
      }
      sw.write("\n");
      continue;
    }
    sw.write(c);
  }
  endScript(sw);
  return sw.toString();
}

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 ; } if ( c == '$' ) { reader . mark ( 1 ) ; c = reader . read ( ) ; if ( c != '{' ) { sw . write ( '$' ) ; reader . reset ( ) ; } else { reader . mark ( 1 ) ; sw . write ( "${" ) ; processGSstring ( reader , sw ) ; } continue ; } if ( c == '\"' ) { sw . write ( '\\' ) ; } if ( c == '\n' || c == '\r' ) { if ( c == '\r' ) { reader . mark ( 1 ) ; c = reader . read ( ) ; if ( c != '\n' ) { reader . reset ( ) ; } } sw . write ( "\n" ) ; continue ; } sw . write ( c ) ; } endScript ( sw ) ; return sw . toString ( ) ; }
parse the text document looking for & lt ; % or & lt ; % = and then call out to the appropriate handler , otherwise copy the text directly into the script while escaping quotes .
