// Evaluate will evaluate this AST graph for when scope evaluation
Evaluate will evaluate this AST graph for when scope evaluation
// Evaluate will evaluate this AST graph for when scope evaluation
func (e *Variable) Evaluate(dataContext IDataContext, memory *WorkingMemory) (reflect.Value, error) {
	if len(e.Name) > 0 && e.Variable == nil {
		valueNode := dataContext.Get(e.Name)
		if valueNode == nil {
			return reflect.ValueOf(nil), fmt.Errorf("non existent key %s", e.Name)
		}
		e.ValueNode = valueNode
		e.Value = valueNode.Value()
		return e.Value, nil
	}
	if e.Variable != nil && len(e.Name) > 0 {
		_, err := e.Variable.Evaluate(dataContext, memory)
		if err != nil {
			return reflect.Value{}, err
		}
		valueNode, err := e.Variable.ValueNode.GetChildNodeByField(e.Name)
		if err != nil {
			return reflect.Value{}, err
		}
		e.ValueNode = valueNode
		e.Value = valueNode.Value()
		return e.Value, nil
	}
	if e.Variable != nil && e.ArrayMapSelector != nil {
		_, err := e.Variable.Evaluate(dataContext, memory)
		if err != nil {
			return reflect.Value{}, err
		}
		selValue, err := e.ArrayMapSelector.Evaluate(dataContext, memory)
		if err != nil {
			return reflect.Value{}, err
		}
		var valueNode model.ValueNode
		if e.Variable.ValueNode.IsArray() {
			valueNode, err = e.Variable.ValueNode.GetChildNodeByIndex(int(selValue.Int()))
			if err != nil {
				return reflect.Value{}, err
			}
		} else if e.Variable.ValueNode.IsMap() {
			valueNode, err = e.Variable.ValueNode.GetChildNodeBySelector(selValue)
			if err != nil {
				return reflect.Value{}, err
			}
		} else {
			return reflect.Value{}, fmt.Errorf("%s is not an array nor map", e.Variable.ValueNode.IdentifiedAs())
		}
		e.ValueNode = valueNode
		e.Value = valueNode.Value()
		return e.Value, nil
	}
	return reflect.ValueOf(nil), fmt.Errorf("this code part should not be reached")
}
func ( e * Variable ) Evaluate ( dataContext IDataContext , memory * WorkingMemory ) ( reflect . Value , error ) { if len ( e . Name ) > 0 && e . Variable == nil { valueNode := dataContext . Get ( e . Name ) if valueNode == nil { return reflect . ValueOf ( nil ) , fmt . Errorf ( " " , e . Name ) } e . ValueNode = valueNode e . Value = valueNode . Value ( ) return e . Value , nil } if e . Variable != nil && len ( e . Name ) > 0 { _ , err := e . Variable . Evaluate ( dataContext , memory ) if err != nil { return reflect . Value { } , err } valueNode , err := e . Variable . ValueNode . GetChildNodeByField ( e . Name ) if err != nil { return reflect . Value { } , err } e . ValueNode = valueNode e . Value = valueNode . Value ( ) return e . Value , nil } if e . Variable != nil && e . ArrayMapSelector != nil { _ , err := e . Variable . Evaluate ( dataContext , memory ) if err != nil { return reflect . Value { } , err } selValue , err := e . ArrayMapSelector . Evaluate ( dataContext , memory ) if err != nil { return reflect . Value { } , err } var valueNode model . ValueNode if e . Variable . ValueNode . IsArray ( ) { valueNode , err = e . Variable . ValueNode . GetChildNodeByIndex ( int ( selValue . Int ( ) ) ) if err != nil { return reflect . Value { } , err } } else if e . Variable . ValueNode . IsMap ( ) { valueNode , err = e . Variable . ValueNode . GetChildNodeBySelector ( selValue ) if err != nil { return reflect . Value { } , err } } else { return reflect . Value { } , fmt . Errorf ( " " , e . Variable . ValueNode . IdentifiedAs ( ) ) } e . ValueNode = valueNode e . Value = valueNode . Value ( ) return e . Value , nil } return reflect . ValueOf ( nil ) , fmt . Errorf ( " " ) }
Evaluate will evaluate this AST graph for when scope evaluation
Evaluate will evaluate this AST graph for when scope evaluation