Example #1
0
func translateType(typ SimpleType) (*relapse.Pattern, error) {
	switch typ {
	case TypeArray, TypeObject:
		//This does not distinguish between arrays and objects
		return combinator.Many(combinator.InAny(combinator.Any())), nil
	case TypeBoolean:
		return combinator.Value(funcs.TypeBool(funcs.BoolVar())), nil
	case TypeInteger:
		return combinator.Value(funcs.TypeDouble(Integer())), nil
	case TypeNull:
		//TODO null is not being returned by json parser, but is also not empty
		return combinator.Value(funcs.Not(
			funcs.Or(
				funcs.TypeDouble(Number()),
				funcs.Or(
					funcs.TypeBool(funcs.BoolVar()),
					funcs.TypeString(funcs.StringVar()),
				),
			),
		)), nil
	case TypeNumber:
		return combinator.Value(funcs.TypeDouble(Number())), nil
	case TypeString:
		return combinator.Value(funcs.TypeString(funcs.StringVar())), nil
	}
	panic(fmt.Sprintf("unknown simpletype: %s", typ))
}
Example #2
0
	"testing"
)

func TestSimplify1(t *testing.T) {
	c := ast.NewConcat(ast.NewNot(ast.NewZAny()), ast.NewZAny())
	s := NewSimplifier(c.Grammar()).Simplify(c)
	if !s.Equal(ast.NewNot(ast.NewZAny())) {
		t.Fatalf("Expected EmptySet, but got %s", s)
	}
}

var andNameTelephonePerson = combinator.G{
	"main": combinator.InOrder(
		combinator.AllOf(
			combinator.InOrder(
				combinator.Any(),
				combinator.In("Name", combinator.Value(
					funcs.StringEq(funcs.StringVar(), funcs.StringConst("David"))),
				),
				combinator.Any(),
			),
			combinator.InOrder(
				combinator.Any(),
				combinator.In("Telephone", combinator.Value(
					funcs.StringEq(funcs.StringVar(), funcs.StringConst("0123456789"))),
				),
				combinator.Any(),
			),
		),
	),
}