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


Golang file.Idx函數代碼示例

本文整理匯總了Golang中github.com/robertkrimen/otto/file.Idx函數的典型用法代碼示例。如果您正苦於以下問題:Golang Idx函數的具體用法?Golang Idx怎麽用?Golang Idx使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: TestCommentMap_move

func TestCommentMap_move(t *testing.T) {
	statement1 := &EmptyStatement{file.Idx(1)}
	statement2 := &EmptyStatement{file.Idx(2)}
	comment := &Comment{1, "test", LEADING}

	cm := CommentMap{}
	cm.AddComment(statement1, comment)

	if cm.Size() != 1 {
		t.Errorf("the number of comments is %v, not 1", cm.Size())
	}

	if len(cm[statement1]) != 1 {
		t.Errorf("the number of comments is %v, not 1", cm.Size())
	}

	if len(cm[statement2]) != 0 {
		t.Errorf("the number of comments is %v, not 0", cm.Size())
	}

	cm.MoveComments(statement1, statement2, LEADING)

	if cm.Size() != 1 {
		t.Errorf("the number of comments is %v, not 1", cm.Size())
	}

	if len(cm[statement2]) != 1 {
		t.Errorf("the number of comments is %v, not 1", cm.Size())
	}

	if len(cm[statement1]) != 0 {
		t.Errorf("the number of comments is %v, not 0", cm.Size())
	}
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:34,代碼來源:comments_test.go

示例2: location

func (fr _frame) location() string {
	str := "<unknown>"

	switch {
	case fr.native:
		str = "<native code>"
		if fr.nativeFile != "" && fr.nativeLine != 0 {
			str = fmt.Sprintf("%s:%d", fr.nativeFile, fr.nativeLine)
		}
	case fr.file != nil:
		if p := fr.file.Position(file.Idx(fr.offset)); p != nil {
			path, line, column := p.Filename, p.Line, p.Column

			if path == "" {
				path = "<anonymous>"
			}

			str = fmt.Sprintf("%s:%d:%d", path, line, column)
		}
	}

	if fr.callee != "" {
		str = fmt.Sprintf("%s (%s)", fr.callee, str)
	}

	return str
}
開發者ID:NetSys,項目名稱:quilt,代碼行數:27,代碼來源:error.go

示例3: TestCommentMap

func TestCommentMap(t *testing.T) {
	statement := &EmptyStatement{file.Idx(1)}
	comment := &Comment{1, "test", LEADING}

	cm := CommentMap{}
	cm.AddComment(statement, comment)

	if cm.Size() != 1 {
		t.Errorf("the number of comments is %v, not 1", cm.Size())
	}

	if len(cm[statement]) != 1 {
		t.Errorf("the number of comments is %v, not 1", cm.Size())
	}

	if cm[statement][0].Text != "test" {
		t.Errorf("the text is %v, not \"test\"", cm[statement][0].Text)
	}
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:19,代碼來源:comments_test.go

示例4: error

func (self *_parser) error(place interface{}, msg string, msgValues ...interface{}) *Error {
	idx := file.Idx(0)
	switch place := place.(type) {
	case int:
		idx = self.idxOf(place)
	case file.Idx:
		if place == 0 {
			idx = self.idxOf(self.chrOffset)
		} else {
			idx = place
		}
	default:
		panic(fmt.Errorf("error(%T, ...)", place))
	}

	position := self.position(idx)
	msg = fmt.Sprintf(msg, msgValues...)
	self.errors.Add(position, msg)
	return self.errors[len(self.errors)-1]
}
開發者ID:BiggerNoise,項目名稱:otto,代碼行數:20,代碼來源:error.go

示例5: parseNewExpression

func (self *_parser) parseNewExpression() ast.Expression {
	idx := self.expect(token.NEW)
	callee := self.parseLeftHandSideExpression()
	node := &ast.NewExpression{
		New:              idx,
		Callee:           callee,
		RightParenthesis: idx + file.Idx(3),
	}
	if self.token == token.LEFT_PARENTHESIS {
		argumentList, idx0, idx1 := self.parseArgumentList()
		node.ArgumentList = argumentList
		node.LeftParenthesis = idx0
		node.RightParenthesis = idx1
	}

	if self.mode&StoreComments != 0 {
		self.comments.SetExpression(node)
	}

	return node
}
開發者ID:wolfgarnet,項目名稱:otto,代碼行數:21,代碼來源:expression.go

示例6: errorUnexpectedToken

func (self *_parser) errorUnexpectedToken(tkn token.Token) error {
	switch tkn {
	case token.EOF:
		return self.error(file.Idx(0), err_UnexpectedEndOfInput)
	}
	value := tkn.String()
	switch tkn {
	case token.BOOLEAN, token.NULL:
		value = self.literal
	case token.IDENTIFIER:
		return self.error(self.idx, "Unexpected identifier")
	case token.KEYWORD:
		// TODO Might be a future reserved word
		return self.error(self.idx, "Unexpected reserved word")
	case token.NUMBER:
		return self.error(self.idx, "Unexpected number")
	case token.STRING:
		return self.error(self.idx, "Unexpected string")
	}
	return self.error(self.idx, err_UnexpectedToken, value)
}
開發者ID:BiggerNoise,項目名稱:otto,代碼行數:21,代碼來源:error.go

示例7: location

func (fr _frame) location() string {
	if fr.file == nil {
		return "<unknown>"
	}

	p := fr.file.Position(file.Idx(fr.offset))

	path, line, column := p.Filename, p.Line, p.Column

	if path == "" {
		path = "<anonymous>"
	}

	str := fmt.Sprintf("%s:%d:%d", path, line, column)

	if fr.callee != "" {
		str = fmt.Sprintf("%s (%s)", fr.callee, str)
	}

	return str
}
開發者ID:porty,項目名稱:react-in-go,代碼行數:21,代碼來源:error.go

示例8: Idx1

func (self *RegExpLiteral) Idx1() file.Idx         { return file.Idx(int(self.Idx) + len(self.Literal)) }
開發者ID:BiggerNoise,項目名稱:otto,代碼行數:1,代碼來源:node.go

示例9: idxOf

func (self *_parser) idxOf(offset int) file.Idx {
	return file.Idx(self.base + offset)
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:3,代碼來源:parser.go

示例10: TestLexer

func TestLexer(t *testing.T) {
	tt(t, func() {
		setup := func(src string) *_parser {
			parser := newParser("", src)
			return parser
		}

		test := func(src string, test ...interface{}) {
			parser := setup(src)
			for len(test) > 0 {
				tkn, literal, idx := parser.scan()
				if len(test) > 0 {
					is(tkn, test[0].(token.Token))
					test = test[1:]
				}
				if len(test) > 0 {
					is(literal, test[0].(string))
					test = test[1:]
				}
				if len(test) > 0 {
					// FIXME terst, Fix this so that cast to file.Idx is not necessary?
					is(idx, file.Idx(test[0].(int)))
					test = test[1:]
				}
			}
		}

		test("",
			token.EOF, "", 1,
		)

		test("1",
			token.NUMBER, "1", 1,
			token.EOF, "", 2,
		)

		test(".0",
			token.NUMBER, ".0", 1,
			token.EOF, "", 3,
		)

		test("abc",
			token.IDENTIFIER, "abc", 1,
			token.EOF, "", 4,
		)

		test("abc(1)",
			token.IDENTIFIER, "abc", 1,
			token.LEFT_PARENTHESIS, "", 4,
			token.NUMBER, "1", 5,
			token.RIGHT_PARENTHESIS, "", 6,
			token.EOF, "", 7,
		)

		test(".",
			token.PERIOD, "", 1,
			token.EOF, "", 2,
		)

		test("===.",
			token.STRICT_EQUAL, "", 1,
			token.PERIOD, "", 4,
			token.EOF, "", 5,
		)

		test(">>>=.0",
			token.UNSIGNED_SHIFT_RIGHT_ASSIGN, "", 1,
			token.NUMBER, ".0", 5,
			token.EOF, "", 7,
		)

		test(">>>=0.0.",
			token.UNSIGNED_SHIFT_RIGHT_ASSIGN, "", 1,
			token.NUMBER, "0.0", 5,
			token.PERIOD, "", 8,
			token.EOF, "", 9,
		)

		test("\"abc\"",
			token.STRING, "\"abc\"", 1,
			token.EOF, "", 6,
		)

		test("abc = //",
			token.IDENTIFIER, "abc", 1,
			token.ASSIGN, "", 5,
			token.EOF, "", 9,
		)

		test("abc = /*test*/",
			token.IDENTIFIER, "abc", 1,
			token.ASSIGN, "", 5,
			token.EOF, "", 15,
		)

		test("abc = 1 / 2",
			token.IDENTIFIER, "abc", 1,
			token.ASSIGN, "", 5,
			token.NUMBER, "1", 7,
			token.SLASH, "", 9,
//.........這裏部分代碼省略.........
開發者ID:wolfgarnet,項目名稱:otto,代碼行數:101,代碼來源:lexer_test.go

示例11: ContextSkip

// ContextSkip returns the current execution context of the vm, with a
// specific limit on the number of stack frames to traverse, optionally
// skipping any innermost native function stack frames.
func (self Otto) ContextSkip(limit int, skipNative bool) (ctx Context) {
	// Ensure we are operating in a scope
	if self.runtime.scope == nil {
		self.runtime.enterGlobalScope()
		defer self.runtime.leaveScope()
	}

	scope := self.runtime.scope
	frame := scope.frame

	for skipNative && frame.native && scope.outer != nil {
		scope = scope.outer
		frame = scope.frame
	}

	// Get location information
	ctx.Filename = "<unknown>"
	ctx.Callee = frame.callee

	switch {
	case frame.native:
		ctx.Filename = frame.nativeFile
		ctx.Line = frame.nativeLine
		ctx.Column = 0
	case frame.file != nil:
		ctx.Filename = "<anonymous>"

		if p := frame.file.Position(file.Idx(frame.offset)); p != nil {
			ctx.Line = p.Line
			ctx.Column = p.Column

			if p.Filename != "" {
				ctx.Filename = p.Filename
			}
		}
	}

	// Get the current scope this Value
	ctx.This = toValue_object(scope.this)

	// Build stacktrace (up to 10 levels deep)
	ctx.Symbols = make(map[string]Value)
	ctx.Stacktrace = append(ctx.Stacktrace, frame.location())
	for limit != 0 {
		// Get variables
		stash := scope.lexical
		for {
			for _, name := range getStashProperties(stash) {
				if _, ok := ctx.Symbols[name]; !ok {
					ctx.Symbols[name] = stash.getBinding(name, true)
				}
			}
			stash = stash.outer()
			if stash == nil || stash.outer() == nil {
				break
			}
		}

		scope = scope.outer
		if scope == nil {
			break
		}
		if scope.frame.offset >= 0 {
			ctx.Stacktrace = append(ctx.Stacktrace, scope.frame.location())
		}
		limit--
	}

	return
}
開發者ID:vozhyk-,項目名稱:gohan,代碼行數:73,代碼來源:otto.go


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