docs: function parse(contents, options) {
      var commands = [];
      var i;
      var line;
      var lineno;
      var lines = contents.split(/[\r?\n]/);
      var lookingForDirectives = true;
      var parseOptions = {};
      var parseResult;
      var regexMatch;
      var remainder = '';
      var includeComments = options && options['includeComments'];
  
      for (i = 0; i < lines.length; i++) {
          lineno = i + 1;
          if (remainder) {
              line = remainder + lines[i];
          } else {
              line = lines[i];
          }
  
          if (lookingForDirectives) {
              // Handle the parser directive '# escape=<char>. Parser directives
              // must precede any builder instruction or other comments, and
              // cannot be repeated.
              regexMatch = line.match(TOKEN_ESCAPE_DIRECTIVE);
              if (regexMatch) {
                  if (regexMatch[1] != '`' && regexMatch[1] != '\\') {
                      throw new Error('invalid ESCAPE "' + regexMatch[1]
                          + '". Must be ` or \\');
                  }
                  if (parseOptions.lineContinuationRegex) {
                      throw new Error(
                          'only one escape parser directive can be used');
                  }
                  parseOptions.lineContinuationRegex = RegExp(
                      regexEscape(regexMatch[1]) + '[ \t]*$');
                  continue;
              }
          }
          // Once a comment, empty line or builder instruction has been processed,
          // Docker no longer looks for parser directives.
          lookingForDirectives = false;
  
          parseResult = parseLine(line, lineno, parseOptions);
          if (parseResult.command) {
              if (parseResult.command.name !== 'COMMENT' || includeComments) {
                  commands.push(parseResult.command);
              }
          }
          remainder = parseResult.remainder;
      }
  
      return commands;
  }