本文整理汇总了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;未经允许,请勿转载。 |
请发表评论