示例#1
0
文件: rxplor.go 项目: proebsting/re
// individual handles separate processing of each input regex
func individual(l *rx.RegExParsed, cx int, i int, image string, augt rx.Node) {
	babble("tree:   %s\n", image)
	babble("augmnt: %v\n", augt)
	x := augt.MaxLen()
	if x >= 0 {
		babble("length: %d to %d\n", augt.MinLen(), x)
	} else {
		babble("length: %d to *\n", augt.MinLen())
	}
	babble("cplxty: %d\n", cx)

	dfa := rx.BuildDFA(augt)

	if *opt['R'] {
		rand.Seed(int64(seedvalue))
	}
	if *opt['g'] {
		rx.ShowLabel(os.Stdout, "Examples")
		examples(dfa, l.Tree, 0) // gen and test w/ max repl of 0
		examples(dfa, l.Tree, 1) // ... and 1
		examples(dfa, l.Tree, 2) // ... and 2
		examples(dfa, l.Tree, 3) // ... and 3
		examples(dfa, l.Tree, 5) // ... and 5
		examples(dfa, l.Tree, 8) // ... and 8
	}
	showDFA(dfa, "Annotated Tree", false)
}
示例#2
0
文件: rxplor.go 项目: proebsting/re
//  synthx generates and prints synthetic examples from a DFA.
func synthx(dfa *rx.DFA) {
	_, isMulti := dfa.Tree.(*rx.AltNode) // true if MultiDFA
	synthx := dfa.Synthesize()           // synthesize examples
	rx.ShowLabel(os.Stdout, "Examples from DFA")
	for _, x := range synthx {
		fmt.Printf("s%d:  %s", x.State, rx.Protect(x.Example))
		if isMulti {
			fmt.Printf("  %s\n", x.RXset)
		} else {
			fmt.Println()
		}
	}
}
示例#3
0
文件: rxplor.go 项目: proebsting/re
// main is the overall controller
func main() {
	setup()                      // initialize
	defer pprof.StopCPUProfile() // may have started profiling

	exprs, trees := load() // load input
	timestamp(fmt.Sprintf(
		"load %d expressions", len(exprs)))

	if !*opt['m'] { // if nothing uses a combined DFA
		return
	}
	if *opt['i'] { // if preceded by individual processing
		fmt.Println()
		rx.ShowLabel(os.Stdout, "MERGING EXPRESSIONS")
		fmt.Println()
		if *opt['R'] {
			rand.Seed(int64(seedvalue))
		}
	}

	dfa := rx.MultiDFA(trees)
	timestamp(fmt.Sprintf(
		"make merged DFA of %d states", len(dfa.Dstates)))
	dfa = showDFA(dfa, "Combined Tree", *opt['t'])

	// generate graphs if requested
	label := exprs[0].Expr
	if len(exprs) > 1 {
		label = fmt.Sprintf("%d expressions", len(exprs))
	}
	if *val['N'] != "" {
		rx.WriteGraph(*val['N'], func(w io.Writer) {
			dfa.GraphNFA(w, "NFA: "+label)
		})
	}
	if *val['D'] != "" {
		labels := ""
		if len(exprs) > 1 && len(exprs) <= len(rx.AcceptLabels) {
			labels = rx.AcceptLabels
		}
		rx.WriteGraph(*val['D'], func(w io.Writer) {
			dfa.ToDot(w, "DFA: "+label, labels)
		})
	}
}