当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.Data方法代码示例

本文整理汇总了Golang中github.com/quarnster/parser.Node.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Data方法的具体用法?Golang Node.Data怎么用?Golang Node.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/quarnster/parser.Node的用法示例。


在下文中一共展示了Node.Data方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: eval

func eval(node *parser.Node) string {
	switch node.Name {
	case "Env":
		name := eval(node.Children[0])
		if ret := os.Getenv(name); ret == "" {
			return name + "_NOT_SET"
		} else {
			return ret
		}
	case "Folder":
		return filepath.Dir(eval(node.Children[0]))
	case "String", "NonOperation", "RecNonOp":
		return node.Data()
	case "Home":
		if u, err := user.Current(); err != nil {
			log4go.Warn("Couldn't lookup current user: %s", err)
		} else {
			return u.HomeDir
		}
	case "EXPAND_PATH", "RecOp":
		buf := bytes.NewBuffer(nil)
		for _, c := range node.Children {
			buf.WriteString(eval(c))
		}
		return buf.String()
	}
	return ""
}
开发者ID:NeoTse,项目名称:completion,代码行数:28,代码来源:manual.go

示例2: convert

func convert(node *parser.Node) string {
	ret := ""
	switch node.Name {
	case "MethodDescriptor":
		ri := len(node.Children) - 1
		ret += convert(node.Children[ri]) + " ("
		for i := range node.Children[:ri] {
			if i > 0 {
				ret += ", "
			}
			ret += convert(node.Children[i])
		}
		ret += ")"
		return ret
	case "BaseType":
		fallthrough
	case "VoidDescriptor":
		return lut[node.Data()]
	case "Classname":
		return strings.Replace(node.Data(), "/", ".", -1)
	}
	for i := range node.Children {
		if ret != "" {
			ret += " "
		}
		ret += convert(node.Children[i])
	}
	if node.Name == "ArrayType" {
		ret += "[]"
	}
	return ret
}
开发者ID:NeoTse,项目名称:completion,代码行数:32,代码来源:descriptors_conv.go

示例3: data

func data(n *parser.Node) string {
	switch n.Name {
	default:
		return n.Data()
	case "InheritedName":
		return data(n.Children[1])
	case "OptionalArgument":
		return data(n.Children[0])
	}
}
开发者ID:noname007,项目名称:completion,代码行数:10,代码来源:clang.go

示例4: variable

func (c *Net) variable(n *parser.Node) string {
	switch n.Name {
	case "Access":
	default:
		if len(n.Children) == 0 {
			return n.Data()
		}
		for _, child := range n.Children {
			if v := c.variable(child); v != "" {
				return v
			}
		}
	}
	return ""
}
开发者ID:noname007,项目名称:completion,代码行数:15,代码来源:net.go

示例5: ToContentType

func ToContentType(node *parser.Node) (ret content.Type) {
	if node.Name == "ArrayType" {
		ret.Flags |= content.FLAG_TYPE_ARRAY
		ret.Specialization = append(ret.Specialization, ToContentType(node.Children[0]))
		return
	}
	switch node.Name {
	case "BaseType":
		fallthrough
	case "VoidDescriptor":
		ret.Name.Relative = lut[node.Data()]
		ret.Name.Absolute = ret.Name.Relative
	case "Classname":
		ret.Name = ToContentFQN(node.Data())
	default:
		return ToContentType(node.Children[0])
	}

	return
}
开发者ID:NeoTse,项目名称:completion,代码行数:20,代码来源:descriptors_conv.go

示例6: typeresolve

func typeresolve(td *TypeDef, node *parser.Node) (*content.Type, error) {
	switch n := node.Name; n {
	case "MethodCall":
		if methods, err := td.Methods(); err != nil {
			return nil, err
		} else {
			for _, method := range methods {
				if method.Name.Relative == node.Children[0].Data() {
					return &method.Returns[0].Type, nil
				}
			}
		}
	case "Identifier":
		if fields, err := td.Fields(); err != nil {
			return nil, err
		} else {
			for _, field := range fields {
				if field.Name.Relative == node.Data() {
					return &field.Type, nil
				}
			}
		}

		// Is it a Property then perhaps?
		name := "get_" + node.Data()
		if methods, err := td.Methods(); err != nil {
			return nil, err
		} else {
			for _, method := range methods {
				if method.Name.Relative == name {
					return &method.Returns[0].Type, nil
				}
			}
		}
		// TODO: could also be an inner class
	}

	// Found nothing.
	// TODO: Try parents
	return nil, fmt.Errorf("No such type found: %s, %s", td.Name(), node)
}
开发者ID:jerchung,项目名称:completion,代码行数:41,代码来源:net.go

示例7: Eval

func Eval(v *reflect.Value, node *parser.Node) (int, error) {
	switch node.Name {
	case "EXPRESSION":
		if l := len(node.Children); l != 2 {
			return 0, fmt.Errorf("Unexpected child length: %d, %s", l, node)
		}
		return Eval(v, node.Children[0])
	case "DotIdentifier":
		curr := v.Type().Name()
		children := node.Children
		if len(children) > 0 {
			// The last one will be handled by the fallthrough instead
			children = node.Children[:len(node.Children)-1]
		}
		for _, child := range children {
			f := v.FieldByName(child.Data())
			if !f.IsValid() {
				return 0, fmt.Errorf("No field by name %s in struct %s", node.Data(), curr)
			}
			v = &f
		}
		node = node.Children[len(node.Children)-1]
		fallthrough
	case "Identifier":
		if f := v.FieldByName(node.Data()); !f.IsValid() {
			return 0, fmt.Errorf("No field by name %s in struct %s", node.Data(), v)
		} else {
			switch f.Kind() {
			case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				return int(f.Uint()), nil
			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
				return int(f.Int()), nil
			case reflect.Bool:
				if f.Bool() {
					return 1, nil
				} else {
					return 0, nil
				}
			default:
				return 0, fmt.Errorf("Unexpected identifier kind: %v %v", f, f.Kind())
			}
		}
	case "Constant":
		i, err := strconv.ParseInt(node.Data(), 0, 32)
		return int(i), err
	case "EndOfFile":
		return 0, nil
	default:
		if l := len(node.Children); l != 2 {
			return 0, fmt.Errorf("Unexpected child length: %d, %s", l, node)
		}
		if a, err := Eval(v, node.Children[0]); err != nil {
			return 0, err
		} else if b, err := Eval(v, node.Children[1]); err != nil {
			return 0, err
		} else {
			switch node.Name {
			case "Ne":
				if a != b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Eq":
				if a == b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Lt":
				if a < b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Gt":
				if a > b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Le":
				if a <= b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Ge":
				if a >= b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Add":
				return a + b, nil
			case "Sub":
				return a - b, nil
			case "Mul":
				return a * b, nil
			case "ShiftLeft":
//.........这里部分代码省略.........
开发者ID:quarnster,项目名称:util,代码行数:101,代码来源:eval.go

示例8: Eval

func Eval(v *reflect.Value, node *parser.Node) (int, error) {
	switch node.Name {
	case "EXPRESSION":
		if l := len(node.Children); l != 2 {
			return 0, fmt.Errorf("Unexpected child length: %d, %s", l, node)
		}
		return Eval(v, node.Children[0])
	case "Identifier":
		if f := v.FieldByName(node.Data()); !f.IsValid() {
			return 0, fmt.Errorf("No field by name %s in struct %s", node.Data(), v)
		} else {
			switch f.Kind() {
			case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				return int(f.Uint()), nil
			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
				return int(f.Int()), nil
			default:
				return 0, fmt.Errorf("Unexpected identifier kind: %v %v", f, f.Kind())
			}
		}
	case "Constant":
		i, err := strconv.ParseInt(node.Data(), 0, 32)
		return int(i), err
	case "EndOfFile":
		return 0, nil
	default:
		if l := len(node.Children); l != 2 {
			return 0, fmt.Errorf("Unexpected child length: %d, %s", l, node)
		}
		if a, err := Eval(v, node.Children[0]); err != nil {
			return 0, err
		} else if b, err := Eval(v, node.Children[1]); err != nil {
			return 0, err
		} else {
			switch node.Name {
			case "Eq":
				if a == b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Lt":
				if a < b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Gt":
				if a > b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Le":
				if a <= b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Ge":
				if a >= b {
					return 1, nil
				} else {
					return 0, nil
				}
			case "Add":
				return a + b, nil
			case "Sub":
				return a - b, nil
			case "Mul":
				return a * b, nil
			case "ShiftLeft":
				return int(uint(a) << uint(b)), nil
			case "ShiftRight":
				return int(uint(a) >> uint(b)), nil
			case "Mask":
				return a & b, nil
			case "AndNot":
				return a &^ b, nil
			default:
				return 0, fmt.Errorf("Unimplemented operation: %s", node.Name)
			}
		}
	}
}
开发者ID:jiyeyuran,项目名称:util,代码行数:85,代码来源:eval.go


注:本文中的github.com/quarnster/parser.Node.Data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。