<commit_before>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"flag";
	"fmt";
	"go/ast";
	"go/parser";
	"go/printer";
	"io";
	"os";
	"sort";
	"tabwriter";
)


var (
	// operation modes
	silent = flag.Bool("s", false, "silent mode: parsing only");
	verbose = flag.Bool("v", false, "verbose mode: trace parsing");
	exports = flag.Bool("x", false, "show exports only");

	// layout control
	tabwidth = flag.Int("tabwidth", 4, "tab width");
	usetabs = flag.Bool("tabs", false, "align with tabs instead of blanks");
	optcommas = flag.Bool("optcommas", false, "print optional commas");
	optsemis = flag.Bool("optsemis", false, "print optional semicolons");
)


func usage() {
	fmt.Fprintf(os.Stderr, "usage: gofmt [flags] [file.go]\n");
	flag.PrintDefaults();
	os.Exit(1);
}


func parserMode() uint {
	mode := parser.ParseComments;
	if *verbose {
		mode |= parser.Trace;
	}
	return mode;
}


func printerMode() uint {
	mode := printer.DocComments;
	if *optcommas {
		mode |= printer.OptCommas;
	}
	if *optsemis {
		mode |= printer.OptSemis;
	}
	return mode;
}


func makeTabwriter(writer io.Writer) *tabwriter.Writer {
	padchar := byte(' ');
	if *usetabs {
		padchar = '\t';
	}
	return tabwriter.NewWriter(writer, *tabwidth, 1, padchar, 0);
}


func main() {
	flag.Parse();

	var filename string;
	switch flag.NArg() {
	case 0: filename = "/dev/stdin";
	case 1: filename = flag.Arg(0);
	default: usage();
	}

	src, err := io.ReadFile(filename);
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: %v\n", filename, err);
		os.Exit(1);
	}

	prog, err := parser.Parse(src, parserMode());
	if err != nil {
		if errors, ok := err.(parser.ErrorList); ok {
			sort.Sort(errors);
			for _, e := range errors {
				fmt.Fprintf(os.Stderr, "%s:%v\n", filename, e);
			}<commit_msg>mention file name only once in error message<commit_after>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"flag";
	"fmt";
	"go/ast";
	"go/parser";
	"go/printer";
	"io";
	"os";
	"sort";
	"tabwriter";
)


var (
	// operation modes
	silent = flag.Bool("s", false, "silent mode: parsing only");
	verbose = flag.Bool("v", false, "verbose mode: trace parsing");
	exports = flag.Bool("x", false, "show exports only");

	// layout control
	tabwidth = flag.Int("tabwidth", 4, "tab width");
	usetabs = flag.Bool("tabs", false, "align with tabs instead of blanks");
	optcommas = flag.Bool("optcommas", false, "print optional commas");
	optsemis = flag.Bool("optsemis", false, "print optional semicolons");
)


func usage() {
	fmt.Fprintf(os.Stderr, "usage: gofmt [flags] [file.go]\n");
	flag.PrintDefaults();
	os.Exit(1);
}


func parserMode() uint {
	mode := parser.ParseComments;
	if *verbose {
		mode |= parser.Trace;
	}
	return mode;
}


func printerMode() uint {
	mode := printer.DocComments;
	if *optcommas {
		mode |= printer.OptCommas;
	}
	if *optsemis {
		mode |= printer.OptSemis;
	}
	return mode;
}


func makeTabwriter(writer io.Writer) *tabwriter.Writer {
	padchar := byte(' ');
	if *usetabs {
		padchar = '\t';
	}
	return tabwriter.NewWriter(writer, *tabwidth, 1, padchar, 0);
}


func main() {
	flag.Parse();

	var filename string;
	switch flag.NArg() {
	case 0: filename = "/dev/stdin";
	case 1: filename = flag.Arg(0);
	default: usage();
	}

	src, err := io.ReadFile(filename);
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err);
		os.Exit(1);
	}

	prog, err := parser.Parse(src, parserMode());
	if err != nil {
		if errors, ok := err.(parser.ErrorList); ok {
			sort.Sort(errors);
			for _, e := range errors {
				fmt.Fprintf(os.Stderr, "%s:%v\n", filename, e);
			}
{'fraction_non_alphanumeric': 0.17292049330884282, 'fraction_numerical': 0.006297559695617948, 'mean_word_length': 3.765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1643695', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1386, 'n_words': 391}