本文整理匯總了Golang中github.com/dgraph-io/dgraph/lex.Lexer.Peek方法的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer.Peek方法的具體用法?Golang Lexer.Peek怎麽用?Golang Lexer.Peek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dgraph-io/dgraph/lex.Lexer
的用法示例。
在下文中一共展示了Lexer.Peek方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: lexLiteral
// Assumes '"' has already been encountered.
func lexLiteral(l *lex.Lexer) lex.StateFn {
for {
r := l.Next()
if r == '\u005c' { // backslash
r = l.Next()
continue // This would skip over the escaped rune.
}
if r == lex.EOF || isEndLiteral(r) {
break
}
}
l.Backup()
l.Emit(itemLiteral)
l.Next() // Move to end literal.
l.Ignore() // Ignore end literal.
l.Depth++
r := l.Peek()
if r == '@' {
return lexLanguage(l)
}
if r == '^' {
return lexObjectType(l)
}
return lexText
}
示例2: lexBlankNode
// Assumes that the current rune is '_'.
func lexBlankNode(l *lex.Lexer, styp lex.ItemType,
sfn lex.StateFn) lex.StateFn {
// RDF Blank Node.
// TODO: At some point do checkings based on the guidelines. For now,
// just accept everything until space.
l.AcceptUntil(isSpace)
r := l.Peek()
if r == lex.EOF {
return l.Errorf("Unexpected end of subject")
}
if isSpace(r) {
l.Emit(styp)
return sfn
}
return l.Errorf("Invalid character %v found for itemType: %v", r, styp)
}
示例3: lexUidNode
func lexUidNode(l *lex.Lexer, styp lex.ItemType, sfn lex.StateFn) lex.StateFn {
l.AcceptUntil(isSpace)
r := l.Peek()
if r == lex.EOF {
return l.Errorf("Unexpected end of uid subject")
}
in := l.Input[l.Start:l.Pos]
if !strings.HasPrefix(in, "_uid_:") {
return l.Errorf("Expected _uid_: Found: %v", l.Input[l.Start:l.Pos])
}
if _, err := strconv.ParseUint(in[6:], 0, 64); err != nil {
return l.Errorf("Unable to convert '%v' to UID", in[6:])
}
if isSpace(r) {
l.Emit(styp)
return sfn
}
return l.Errorf("Invalid character %v found for UID node itemType: %v", r,
styp)
}