示例#1
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()
		}
	}
}
示例#2
0
文件: examine.go 项目: proebsting/re
//  genexamples writes a line of specimen strings matching the expression
func genexamples(w http.ResponseWriter, tree rx.Node, maxrepl int) {
	nprinted := 0
	ncolm := 0
	for {
		s := rx.Specimen(tree, maxrepl)
		t := rx.Protect(s)
		ncolm += 2 + len(t)
		if nprinted > 0 && ncolm > linemax {
			break
		}
		fmt.Fprintf(w, " %s   ", hx(t))
		nprinted++
	}
	fmt.Fprint(w, "<BR>\n")
}
示例#3
0
文件: rxplor.go 项目: proebsting/re
//   examples generates a line's worth of examples with max replication n.
//   Each example is also tested against the DFA.
func examples(dfa *rx.DFA, tree rx.Node, n int) {
	s := fmt.Sprintf("ex(%d):", n)
	nprinted := 0
	fmt.Print(s)
	ncolm := utf8.RuneCountInString(s)
	for {
		s := rx.Specimen(tree, n)
		t := rx.Protect(s)
		ncolm += 2 + utf8.RuneCountInString(t)
		if nprinted > 0 && ncolm > linemax {
			break
		}
		fmt.Printf("  %s", t)
		if dfa.Accepts(s) == nil {
			fmt.Print(" [FAIL]")
			ncolm += 7
		}
		nprinted++
	}
	fmt.Println()
}