當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Indexing.End方法代碼示例

本文整理匯總了Golang中github.com/elves/elvish/parse.Indexing.End方法的典型用法代碼示例。如果您正苦於以下問題:Golang Indexing.End方法的具體用法?Golang Indexing.End怎麽用?Golang Indexing.End使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/elves/elvish/parse.Indexing的用法示例。


在下文中一共展示了Indexing.End方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: lvaluesOp

// lvaluesOp compiles lvalues, returning the fixed part and, optionally a rest
// part.
//
// In the AST an lvalue is either an Indexing node where the head is a string
// literal, or a braced list of such Indexing nodes. The last Indexing node may
// be prefixed by @, in which case they become the rest part. For instance, in
// {a[x],b,@c[z]}, "a[x],b" is the fixed part and "c[z]" is the rest part.
func (cp *compiler) lvaluesOp(n *parse.Indexing) (LValuesOp, LValuesOp) {
	if n.Head.Type == parse.Braced {
		// Braced list of variable specs, possibly with indicies. The braced list
		if len(n.Indicies) > 0 {
			cp.errorf("may not have indicies")
		}

		opFuncs := make([]LValuesOpFunc, len(n.Head.Braced))
		var restNode *parse.Indexing
		var restOpFunc LValuesOpFunc

		// Compile each spec inside the brace.
		lvalueNodes := n.Head.Braced
		fixedEnd := 0
		for i, cn := range lvalueNodes {
			if len(cn.Indexings) != 1 {
				cp.errorpf(cn.Begin(), cn.End(), "must be an lvalue")
			}
			var rest bool
			rest, opFuncs[i] = cp.lvaluesOne(cn.Indexings[0], "must be an lvalue ")
			// Only the last one may a rest part.
			if rest {
				if i == len(n.Head.Braced)-1 {
					restNode = cn.Indexings[0]
					restOpFunc = opFuncs[i]
				} else {
					cp.errorpf(cn.Begin(), cn.End(), "only the last lvalue may have @")
				}
			} else {
				fixedEnd = cn.End()
			}
		}

		var restOp LValuesOp
		// If there is a rest part, make LValuesOp for it and remove it from opFuncs.
		if restOpFunc != nil {
			restOp = LValuesOp{restOpFunc, restNode.Begin(), restNode.End()}
			opFuncs = opFuncs[:len(opFuncs)-1]
		}

		var op LValuesOp
		// If there is still anything left in opFuncs, make LValuesOp for the fixed part.
		if len(opFuncs) > 0 {
			op = LValuesOp{func(ec *EvalCtx) []Variable {
				var variables []Variable
				for _, opFunc := range opFuncs {
					variables = append(variables, opFunc(ec)...)
				}
				return variables
			}, lvalueNodes[0].Begin(), fixedEnd}
		}

		return op, restOp
	}
	rest, opFunc := cp.lvaluesOne(n, "must be an lvalue or a braced list of those")
	op := LValuesOp{opFunc, n.Begin(), n.End()}
	if rest {
		return LValuesOp{}, op
	} else {
		return op, LValuesOp{}
	}
}
開發者ID:zhsj,項目名稱:elvish,代碼行數:69,代碼來源:compile_lvalue_op.go

示例2: indexingOp

func (cp *compiler) indexingOp(n *parse.Indexing) ValuesOp {
	return ValuesOp{cp.indexing(n), n.Begin(), n.End()}
}
開發者ID:zhsj,項目名稱:elvish,代碼行數:3,代碼來源:boilerplate.go


注:本文中的github.com/elves/elvish/parse.Indexing.End方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。