예제 #1
0
파일: findernode.go 프로젝트: sbinet/fubsy
func (self *FinderNode) Add(other_ types.FuObject) (types.FuObject, error) {
	var result types.FuObject
	switch other := other_.(type) {
	case types.FuList:
		// <pat> + [a, b, c] = [<pat>, a, b, c]
		// (a, b, c must all be Nodes)
		members := make([]types.FuObject, 1+len(other.List()))
		members[0] = self

		for i, obj := range other.List() {
			switch obj := obj.(type) {
			case types.FuString:
				// <*.c> + ["extra/stuff.c"] should just work
				members[i+1] = NewFileNode(obj.ValueString())
			case Node:
				members[i+1] = obj
			default:
				return types.UnsupportedAdd(
					self, other, "second operand contains "+obj.Typename())
			}
		}
		result = newListNode(members...)
	case types.FuString:
		// <pat> + "foo" = [<pat>, FileNode("foo")]
		result = newListNode(self, NewFileNode(other.ValueString()))
	case Node:
		result = newListNode(self, other)
	default:
		return types.UnsupportedAdd(self, other, "")
	}
	return result, nil
}
예제 #2
0
파일: listnode.go 프로젝트: sbinet/fubsy
func (self *ListNode) Add(other types.FuObject) (types.FuObject, error) {
	values := self.List()
	otherlist := other.List()
	result := make([]types.FuObject, len(values)+len(otherlist))
	for i, obj := range values {
		result[i] = obj
	}
	j := len(values)
	for i, obj := range otherlist {
		if _, ok := obj.(Node); !ok {
			return types.UnsupportedAdd(
				self, other, "second operand contains "+obj.Typename())
		}
		result[j+i] = obj
	}
	return newListNode(result...), nil
}
예제 #3
0
파일: python.go 프로젝트: sbinet/fubsy
func (self PythonCallable) Add(other types.FuObject) (types.FuObject, error) {
	return types.UnsupportedAdd(self, other, "")
}