Esempio n. 1
0
func TestKeyLeaf(t *testing.T) {
	p := ast.NewLeafNode(ast.NewStringVar())
	g := p.Grammar()
	gkey, err := FieldNamesToNumbers("debug", "Debug", debug.DebugDescription(), g)
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("%v", gkey)
	check(t, gkey)
}
Esempio n. 2
0
func simplifyAnd(refs ast.RefLookup, p1, p2 *ast.Pattern, record bool) *ast.Pattern {
	if isNotZany(p1) || isNotZany(p2) {
		return emptyset
	}
	if isZany(p1) {
		return p2
	}
	if isZany(p2) {
		return p1
	}
	if isEmpty(p1) {
		if Nullable(refs, p2) {
			return ast.NewEmpty()
		} else {
			return emptyset
		}
	}
	if isEmpty(p2) {
		if Nullable(refs, p1) {
			return ast.NewEmpty()
		} else {
			return emptyset
		}
	}
	if p1.GetLeafNode() != nil && p2.GetLeafNode() != nil {
		expr1, err1 := compose.ConvertBuiltInIntoFunction(p1.GetLeafNode().GetExpr())
		expr2, err2 := compose.ConvertBuiltInIntoFunction(p2.GetLeafNode().GetExpr())
		if err1 == nil && err2 == nil {
			return ast.NewLeafNode(ast.NewFunction("and", expr1, expr2))
		}
	}
	left := getAnds(p1)
	right := getAnds(p2)
	list := append(left, right...)
	list = ast.Set(list)
	list = simplifyChildren(list, func(left, right *ast.Pattern) *ast.Pattern {
		return simplifyAnd(refs, left, right, record)
	}, record)
	ast.Sort(list)
	var p *ast.Pattern = list[0]
	for i := range list {
		if i == 0 {
			continue
		}
		p = ast.NewAnd(p, list[i])
	}
	return p
}