anchor.diff:     * @throws Exception if the source could not be parsed, if the compilation errors in the source do
      *           not match those that are expected, or if the result would have been `null`
      */
  -  CompilationUnit parseCompilationUnit(String source,
  +  CompilationUnit parseCompilationUnit(String content,
         {List<ErrorCode> codes, List<ExpectedError> errors}) {
  +    Source source = new TestSource();
       GatheringErrorListener listener = new GatheringErrorListener();
  -    Scanner scanner =
  -        new Scanner(null, new CharSequenceReader(source), listener);
  -    TestSource testSource = new TestSource();
  -    listener.setLineInfo(testSource, scanner.lineStarts);
  -    Token token = scanner.tokenize();
  -    Parser parser = new Parser(testSource, listener);
  +
  +    void reportError(
  +        ScannerErrorCode errorCode, int offset, List<Object> arguments) {
  +      listener
  +          .onError(new AnalysisError(source, offset, 1, errorCode, arguments));
  +    }
  +
  +    //
  +    // Scan the source.
  +    //
  +    ScannerResult result = scanString(content,
  +        includeComments: true,
  +        scanGenericMethodComments: enableGenericMethodComments,
  +        scanLazyAssignmentOperators: enableLazyAssignmentOperators);
  +    Token token = result.tokens;
  +    if (result.hasErrors) {
  +      // The default recovery strategy used by scanString
  +      // places all error tokens at the head of the stream.
  +      while (token.type == TokenType.BAD_INPUT) {
  +        translateErrorToken(token, reportError);
  +        token = token.next;
  +      }
  +    }
  +    listener.setLineInfo(source, result.lineStarts);
  +
  +    Parser parser = new Parser(source, listener);
       parser.enableOptionalNewAndConst = enableOptionalNewAndConst;
       CompilationUnit unit = parser.parseCompilationUnit(token);
       expect(unit, isNotNull);
  
positive.code:    *           the expected count, if the compilation errors in the source do not match those that
     *           are expected, or if the result would have been `null`
     */
    List<Statement> parseStatements(String source, int expectedCount,
        [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
      GatheringErrorListener listener = new GatheringErrorListener();
      Scanner scanner =
          new Scanner(null, new CharSequenceReader(source), listener);
      var testSource = new TestSource();
      listener.setLineInfo(testSource, scanner.lineStarts);
      Token token = scanner.tokenize();
      Parser parser = new Parser(testSource, listener);
      parser.enableOptionalNewAndConst = enableOptionalNewAndConst;
      List<Statement> statements = parser.parseStatements(token);
      expect(statements, hasLength(expectedCount));
  
negative.code:   }
  
    /**
     * Parse the given [content] as a compilation unit.
     */
    CompilationUnit parseCompilationUnit2(String content,
        {AnalysisErrorListener listener}) {
      Source source = NonExistingSource.unknown;
      listener ??= AnalysisErrorListener.NULL_LISTENER;
  
      void reportError(
          ScannerErrorCode errorCode, int offset, List<Object> arguments) {
        listener
            .onError(new AnalysisError(source, offset, 1, errorCode, arguments));
      }
  
      //
      // Scan the source.
      //
      ScannerResult result = scanString(content,
          includeComments: true,
          scanGenericMethodComments: enableGenericMethodComments,
          scanLazyAssignmentOperators: enableLazyAssignmentOperators);
      Token token = result.tokens;
      if (result.hasErrors) {
        // The default recovery strategy used by scanString
        // places all error tokens at the head of the stream.
        while (token.type == TokenType.BAD_INPUT) {
          translateErrorToken(token, reportError);
          token = token.next;
        }
      }
  
      Parser parser = new Parser(source, listener);
      parser.enableOptionalNewAndConst = enableOptionalNewAndConst;
      CompilationUnit unit = parser.parseCompilationUnit(token);
      unit.lineInfo = new LineInfo(result.lineStarts);
      return unit;
    }
  
  