Exemplo n.º 1
0
func UnmarshalBindings(body []byte) (expression.Bindings, error) {
	var _unmarshalled []struct {
		Var  string `json:"variable"`
		Expr string `json:"expr"`
		Desc bool   `json:"descend"`
	}

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return nil, err
	}

	bindings := make(expression.Bindings, len(_unmarshalled))
	for i, binding := range _unmarshalled {
		expr, err := parser.Parse(binding.Expr)
		if err != nil {
			return nil, err
		}

		if binding.Desc {
			bindings[i] = expression.NewDescendantBinding(binding.Var, expr)
		} else {
			bindings[i] = expression.NewBinding(binding.Var, expr)
		}
	}

	return bindings, nil
}
Exemplo n.º 2
0
func (this *Let) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_        string `json:"#operator"`
		Bindings []struct {
			_    string `json:"type"`
			Var  string `json:"variable"`
			Expr string `json:"variable"`
			Desc bool   `json:"descend"`
		} `json:"bindings"`
	}

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return err
	}

	this.bindings = make(expression.Bindings, len(_unmarshalled.Bindings))
	for i, binding := range _unmarshalled.Bindings {
		expr, err := parser.Parse(binding.Expr)
		if err != nil {
			return err
		}
		if binding.Desc {
			this.bindings[i] = expression.NewDescendantBinding(binding.Var, expr)
		} else {
			this.bindings[i] = expression.NewBinding(binding.Var, expr)
		}
	}

	return nil
}
Exemplo n.º 3
0
func UnmarshalBinding(body []byte) (*expression.Binding, error) {
	var _unmarshalled struct {
		Var  string `json:"variable"`
		Expr string `json:"expr"`
		Desc bool   `json:"descend"`
	}

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return nil, err
	}

	expr, err := parser.Parse(_unmarshalled.Expr)
	if err != nil {
		return nil, err
	}

	if _unmarshalled.Desc {
		return expression.NewDescendantBinding(_unmarshalled.Var, expr), nil
	} else {
		return expression.NewBinding(_unmarshalled.Var, expr), nil
	}
}