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


Golang Reader.Pos方法代码示例

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


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

示例1: readStruct

func (gofile *File) readStruct(r *kmgGoReader.Reader) StructType {
	// 仅跳过
	r.ReadAllSpace()
	b := r.ReadByte()
	if b != '{' {
		panic(fmt.Errorf("%s unexcept %s", r.GetFileLineInfo(), string(rune(b))))
	}
	lastReadBuf := []bytesAndType{}
	var lastTag []byte
	out := StructType{}
	for {
		r.ReadAllSpaceWithoutLineBreak()
		b := r.ReadByte()
		if b == '}' {
			return out
		} else if b == '"' || b == '\'' || b == '`' {
			r.UnreadByte()
			lastTag = MustReadGoString(r)
		} else if b == ',' {
			continue
		} else if b == '\n' {
			if len(lastReadBuf) == 0 {
				continue
			} else if len(lastReadBuf) == 1 {
				typ := lastReadBuf[0].typ
				name := getTypeStructAnonymousName(typ)
				out.Field = append(out.Field, StructField{
					Name:             name,
					Elem:             typ,
					IsAnonymousField: true,
					Tag:              string(lastTag),
				})
				lastReadBuf = []bytesAndType{}
			} else if len(lastReadBuf) >= 2 {
				typ := lastReadBuf[len(lastReadBuf)-1].typ
				for i := range lastReadBuf[:len(lastReadBuf)-1] {
					out.Field = append(out.Field, StructField{
						Name:             string(lastReadBuf[i].originByte),
						Elem:             typ,
						IsAnonymousField: false,
						Tag:              string(lastTag),
					})
				}
				lastReadBuf = []bytesAndType{}
			}
		} else {
			r.UnreadByte()
			startPos := r.Pos()
			typ := gofile.readType(r)
			lastReadBuf = append(lastReadBuf, bytesAndType{
				originByte: r.BufToCurrent(startPos),
				typ:        typ,
			})
		}
	}
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:56,代码来源:type.go

示例2: readMatchChar

func readMatchChar(r *kmgGoReader.Reader, starter byte, ender byte) []byte {
	startPos := r.Pos()
	level := 1
	for {
		if r.IsEof() {
			panic(r.GetFileLineInfo() + " unexcept EOF")
		}
		b := r.ReadByte()
		if b == '"' || b == '`' {
			r.UnreadByte()
			MustReadGoString(r)
		} else if b == '\'' {
			r.UnreadByte()
			mustReadGoChar(r)
		} else if b == starter {
			level++
		} else if b == ender {
			level--
			if level == 0 {
				return r.BufToCurrent(startPos)
			}
		}
	}
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:24,代码来源:kmgGoParser.go

示例3: readParameters

func (gofile *File) readParameters(r *kmgGoReader.Reader) (output []FuncParameter) {

	b := r.ReadByte()
	if b != '(' {
		// 处理 int 这种类型
		r.UnreadByte()
		return []FuncParameter{
			{
				Type: gofile.readType(r),
			},
		}
	}
	parameterPartList := []*astParameterPart{}
	lastPart := &astParameterPart{}
	for {
		r.ReadAllSpace()
		b := r.ReadByte()
		if b == ')' || b == ',' {
			if lastPart.partList[0].originByte != nil {
				parameterPartList = append(parameterPartList, lastPart)
				lastPart = &astParameterPart{}
			}
			if b == ')' {
				break
			}
			if b == ',' {
				continue
			}
		}

		r.UnreadByte()
		if r.IsMatchAfter([]byte("...")) {
			r.MustReadMatch([]byte("..."))
			lastPart.isVariadic = true
		}
		startPos := r.Pos()
		typ := gofile.readType(r)
		buf := r.BufToCurrent(startPos)
		//fmt.Println(string(buf))
		hasSet := false
		for i := range lastPart.partList {
			if lastPart.partList[i].originByte == nil {
				lastPart.partList[i].originByte = buf
				lastPart.partList[i].typ = typ
				hasSet = true
				break
			}
		}
		if !hasSet {
			panic(r.GetFileLineInfo() + " unexcept func parameterList.")
		}
	}

	output = make([]FuncParameter, len(parameterPartList))
	onlyHavePart1Num := 0
	for i := range parameterPartList {
		if parameterPartList[i].partList[1].originByte == nil {
			onlyHavePart1Num++
		}
	}
	//重新分析出函数参数来. 处理(int,int) 这种类型.
	if onlyHavePart1Num == len(parameterPartList) {
		for i := range parameterPartList {
			output[i].Type = parameterPartList[i].partList[0].typ
			output[i].IsVariadic = parameterPartList[i].isVariadic
		}
		return output
	}
	// 处理 (x,y int) (x int,y int) 这种类型.
	for i, parameterPart := range parameterPartList {
		output[i].Name = string(parameterPart.partList[0].originByte)
		if parameterPart.partList[1].typ != nil {
			output[i].Type = parameterPart.partList[1].typ
		}
		output[i].IsVariadic = parameterPart.isVariadic
	}
	// 补全 (x,y int) 里面 x的类型.
	for i := range parameterPartList {
		if output[i].Type == nil {
			for j := i + 1; j < len(parameterPartList); j++ {
				if output[j].Type != nil {
					output[i].Type = output[j].Type
				}
			}
		}
	}
	return output
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:88,代码来源:func.go


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