func main() { flag.Usage = usage flag.Parse() var errs []string if *inFile == "" { errs = append(errs, "-in is required") } if len(errs) > 0 { fmt.Fprintln(os.Stderr, strings.Join(errs, "\n")) flag.Usage() } temp, err := ioutil.TempFile("", "gsm") if err != nil { fmt.Fprintln(os.Stderr, "could not create temp file: ", err) os.Exit(1) } l := lex.New(os.Stdin) tagHarvester := &TagHarvester{TagToMark: make(map[string]int)} filter(l, temp, tagHarvester) _, err = temp.Seek(0, 0) if err != nil { fmt.Fprintln(os.Stderr, "could not seek to beginning of temp file: ", err) os.Exit(1) } parentTags, err := readCSV(*inFile) if err != nil { fmt.Fprintf(os.Stderr, "%s: %v\n", *inFile, err) os.Exit(1) } parentMarks, err := commitParents(parentTags, tagHarvester.TagToMark) if err != nil { fmt.Fprintf(os.Stderr, "%s: %v\n", *inFile, err) os.Exit(1) } //fmt.Fprintf(os.Stderr, "tagToMark: %#v\nparentTags: %#v\nparentMarks: %#v\n", tagHarvester.TagToMark, parentTags, parentMarks) mergeAdder := &MergeAdder{MarkToParentMark: parentMarks} l = lex.New(temp) filter(l, os.Stdout, mergeAdder) }
func NewParser(r io.Reader) *Parser { return &Parser{l: lex.New(r)} }