コード例 #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, "")
}