Example #1
0
func env(context *parser.FunctionCallContext) error {
	envs := parser.NewMapValue()

	for _, item := range os.Environ() {
		data := strings.Split(item, "=")

		envs.M[parser.NewValueFromString(data[0])] = parser.NewValueFromString(data[1])
	}

	context.Block.Stack.Push(envs)

	return nil
}
Example #2
0
func mapRemove(context *parser.FunctionCallContext) error {
	values, err := parser.ValidateArguments(context, "map-remove", parser.VALUE_ANY, parser.VALUE_MAP)

	if err != nil {
		return err
	}

	newMap := parser.NewMapValue()

	for key, value := range values[1].M {
		if !key.Equals(values[0]) {
			newMap.M[key] = value
		}
	}

	context.Block.Stack.Push(newMap)

	return nil
}
Example #3
0
func map_(context *parser.FunctionCallContext) error {
	values, err := parser.ValidateArguments(context, "map", parser.VALUE_LIST)

	if err != nil {
		return err
	}

	list := values[0].L

	if len(list)%2 != 0 {
		return util.NewInvalidArgumentError("map", "cannot create map of given list because the list is unbalanced, missing key or value", context.Token.Line, context.Token.Column, context.Token.File)
	}

	newMap := parser.NewMapValue()

	for i := 0; i < len(list); i += 2 {
		newMap.M[list[i]] = list[i+1]
	}

	context.Block.Stack.Push(newMap)

	return nil
}