Ejemplo n.º 1
0
//  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()
		}
	}
}
Ejemplo n.º 2
0
//  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")
}
Ejemplo n.º 3
0
//   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()
}