Esempio n. 1
0
func (this *JSConverter) Visit(expr expression.Expression) string {
	var buf bytes.Buffer
	s, err := expr.Accept(this)
	if err != nil {
		panic(fmt.Sprintf("Unexpected error in JSConverter: %v", err))
	}

	switch s := s.(type) {
	case []byte:
		buf.WriteString(string(s))
		for this.stack.Size() != 0 {
			funcExpr := this.stack.Pop().(*funcExpr)
			buf.WriteString(funcExpr.name)
			if funcExpr.operands.Front() != nil {
				buf.WriteString(writeOperands(funcExpr.operands))
			}
		}

	default:
		buf.WriteString(s.(string))
	}

	// if the stack is not empty, pop the function
	/*
		for this.stack.Size() != 0 {
			funcExpr := this.stack.Pop().(*funcExpr)
			buf.WriteString(funcExpr.name)
			if funcExpr.operands.Front() != nil {
				buf.WriteString(writeOperands(funcExpr.operands))
			}
		}
	*/

	return buf.String()
}
Esempio n. 2
0
func SargableFor(expr1, expr2 expression.Expression) bool {
	if expr2.Value() != nil {
		return false
	}

	s := newSargable(expr1)
	result, _ := expr2.Accept(s)
	return result.(bool)
}
Esempio n. 3
0
func SubsetOf(expr1, expr2 expression.Expression) bool {
	v2 := expr2.Value()
	if v2 != nil {
		return v2.Truth()
	}

	s := newSubset(expr1)
	result, _ := expr2.Accept(s)
	return result.(bool)
}
Esempio n. 4
0
func SargFor(expr1, expr2 expression.Expression) Spans {
	if expr2.Value() != nil {
		return nil
	}

	s := newSarg(expr1)
	result, _ := expr2.Accept(s)
	if result != nil {
		return result.(Spans)
	}

	return nil
}
Esempio n. 5
0
func newSarg(expr expression.Expression) expression.Visitor {
	s, _ := expr.Accept(_SARG_FACTORY)
	return s.(expression.Visitor)
}
Esempio n. 6
0
func newSubset(expr expression.Expression) expression.Visitor {
	s, _ := expr.Accept(_SUBSET_FACTORY)
	return s.(expression.Visitor)
}