<commit_before>package main

import (
	"log"
	"os"
	"path"

	"go/ast"
	"go/parser"
	"go/token"
)

func validator(name string, s *ast.StructType) {
	log.Print(name)
	for _, fld := range(s.Fields.List) {
		nam := fld.Names[0].Name
		typ := fld.Type.(*ast.Ident)
		log.Printf("%s %s", nam, typ)
	}
}

func main() {
	log.SetFlags(0)

	if len(os.Args) != 2 {
		log.Printf("usage: %s file.v", path.Base(os.Args[0]))
		os.Exit(2)
	}

	path := os.Args[1]
	fs := token.NewFileSet()
	f, err := parser.ParseFile(fs, path, nil, 0)
	if err != nil {
		log.Fatal(err)
	}

	for _, obj := range f.Scope.Objects {
		if obj.Kind != ast.Typ { continue }
		ts, ok := obj.Decl.(*ast.TypeSpec)
		if !ok { continue }
		s, ok := ts.Type.(*ast.StructType)
		if !ok { continue }
		if s.Fields == nil {
			log.Fatalf("type %s struct has empty field list %v", ts.Name, ts)
		}
		validator(ts.Name.Name, s)
	}
}
<commit_msg>Updates to read from standard in.<commit_after>package main

import (
	"log"
	"os"

	"go/ast"
	"go/parser"
	"go/token"
)

func validator(name string, s *ast.StructType) {
	log.Print(name)
	for _, fld := range(s.Fields.List) {
		nam := fld.Names[0].Name
		typ := fld.Type.(*ast.Ident)
		log.Printf("%s %s", nam, typ)
	}
}

func main() {
	log.SetFlags(0)

	fs := token.NewFileSet()
	f, err := parser.ParseFile(fs, "-", os.Stdin, 0)
	if err != nil {
		log.Fatal(err)
	}

	for _, obj := range f.Scope.Objects {
		if obj.Kind != ast.Typ { continue }
		ts, ok := obj.Decl.(*ast.TypeSpec)
		if !ok { continue }
		s, ok := ts.Type.(*ast.StructType)
		if !ok { continue }
		if s.Fields == nil {
			log.Fatalf("type %s struct has empty field list %v", ts.Name, ts)
		}
		validator(ts.Name.Name, s)
	}
}

{'fraction_non_alphanumeric': 0.1938352104327208, 'fraction_numerical': 0.005927682276229994, 'mean_word_length': 3.0576923076923075, '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': '5404113', 'n_tokens_mistral': 758, 'n_tokens_neox': 722, 'n_words': 165}