Beispiel #1
0
// setup performs global initialization actions
func setup() {
	rxsys.Interval() // initialize timestamps
	options()        // process command-line options
	if verbose {
		showopts() // show command options
	}

	// handle -P (profiling) option
	pfname := *val['P'] // profiling filename
	if pfname != "" {   // if set
		pfile, err := os.Create(pfname)
		rx.CkErr(err)
		pprof.StartCPUProfile(pfile)
	}

	// set up input scanning
	if *val['e'] != "" { // if -e specified
		if len(flag.Args()) > 0 {
			log.Fatal("-e option precludes reading " + flag.Arg(0))
		}
		input = bufio.NewScanner(bytes.NewReader([]byte(*val['e'])))
	} else {
		input = rx.MkScanner(rx.OneInputFile())
	}

	timestamp("init")
}
Beispiel #2
0
func main() {

	rflag := flag.Bool("R", false, "reproducible output")
	flag.Parse()
	if *rflag {
		rand.Seed(0)
	} else {
		rand.Seed(int64(time.Now().Nanosecond()))
	}

	// load and process regexps
	exprs := make([]*RegEx, 0)
	tlist := make([]rx.Node, 0)
	rx.LoadExpressions(rx.OneInputFile(), func(l *rx.RegExParsed) {
		if l.Err != nil {
			fmt.Fprintln(os.Stderr, l.Err)
		}
		if l.Tree != nil {
			atree := rx.Augment(l.Tree, len(tlist))
			tlist = append(tlist, atree)
			exprs = append(exprs, &RegEx{len(exprs), l.Expr})
		}
	})

	// echo the input with index numbers
	fmt.Print(`{"Expressions":`)
	rx.Jlist(os.Stdout, exprs)
	fmt.Println(",")

	// build the DFA and produce examples
	synthx := rx.MultiDFA(tlist).Synthesize()

	// convert into expected form with int array replacing BitSet
	results := make([]*Example, 0, len(synthx))
	for _, x := range synthx {
		results = append(results,
			&Example{x.State, x.RXset.Members(), x.Example})
	}

	// output the array of synthesized examples
	fmt.Print(`"Examples":`)
	rx.Jlist(os.Stdout, results)
	fmt.Println("}")
}