<commit_before>/*
 * Copyright 2015 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Package driver contains a Driver implementation that sends analyses to a
// CompilationAnalyzer based on a Queue of compilations.
package driver

import (
	"errors"
	"fmt"
	"io"
	"log"

	"kythe.io/kythe/go/platform/analysis"

	"golang.org/x/net/context"

	apb "kythe.io/kythe/proto/analysis_proto"
)

// CompilationFunc handles a single CompilationUnit.
type CompilationFunc func(context.Context, *apb.CompilationUnit) error

// Queue is a generic interface to a sequence of CompilationUnits.
type Queue interface {
	Next(context.Context, CompilationFunc) error
}

// Driver sends compilations sequentially from a queue to an analyzer.
type Driver struct {
	Analyzer        analysis.CompilationAnalyzer
	FileDataService string

	// AnalysisError is called for each non-nil err returned from the Analyzer
	// (before Teardown is called).  The error returned from AnalysisError
	// replaces the analysis error that would normally be returned from Run.
	AnalysisError func(context.Context, *apb.CompilationUnit, error) error

	// Compilations is a queue of compilations to be sent for analysis.<commit_msg>Clarify the docs on the driver.Queue interface.<commit_after>/*
 * Copyright 2015 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Package driver contains a Driver implementation that sends analyses to a
// CompilationAnalyzer based on a Queue of compilations.
package driver

import (
	"errors"
	"fmt"
	"io"
	"log"

	"kythe.io/kythe/go/platform/analysis"

	"golang.org/x/net/context"

	apb "kythe.io/kythe/proto/analysis_proto"
)

// CompilationFunc handles a single CompilationUnit.
type CompilationFunc func(context.Context, *apb.CompilationUnit) error

// A Queue represents an ordered sequence of compilation units.
type Queue interface {
	// Next invokes f with the next available compilation in the queue.  If no
	// further values are available, Next must return io.EOF; otherwise, the
	// return value from f is propagated to the caller of Next.
	Next(_ context.Context, f CompilationFunc) error
}

// Driver sends compilations sequentially from a queue to an analyzer.
type Driver struct {
	Analyzer        analysis.CompilationAnalyzer
	FileDataService string

	// AnalysisError is called for each non-nil err returned from the Analyzer
	// (before Teardown is called).  The error returned from AnalysisError
	// replaces the analysis error that would normally be returned from Run.
	AnalysisError func(context.Context, *apb.CompilationUnit, error) error

	// Compilations is a queue of compilations to be sent for analysis.
{'fraction_non_alphanumeric': 0.07046799354491662, 'fraction_numerical': 0.004303388918773534, 'mean_word_length': 3.9986559139784945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5385087', 'n_tokens_mistral': 1018, 'n_tokens_neox': 982, 'n_words': 450}