本文整理匯總了Golang中github.com/dgraph-io/dgraph/lex.Lexer類的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer類的具體用法?Golang Lexer怎麽用?Golang Lexer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Lexer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: lexPredicate
func lexPredicate(l *lex.Lexer) lex.StateFn {
r := l.Next()
if r != '<' {
return l.Errorf("Invalid character in lexPredicate: %v", r)
}
l.Depth += 1
return lexUntilClosing(l, itemPredicate, lexText)
}
示例2: lexArgumentVal
func lexArgumentVal(l *lex.Lexer) lex.StateFn {
for {
switch r := l.Next(); {
case isSpace(r):
l.Ignore()
}
}
}
示例3: lexPredicate
func lexPredicate(l *lex.Lexer) lex.StateFn {
r := l.Next()
// The predicate can only be an IRI according to the spec.
if r != '<' {
return l.Errorf("Invalid character in lexPredicate: %v", r)
}
l.Depth++
return lexUntilClosing(l, itemPredicate, lexText)
}
示例4: lexObject
func lexObject(l *lex.Lexer) lex.StateFn {
r := l.Next()
// The object can be an IRI, blank node or a literal.
if r == '<' {
l.Depth++
return lexUntilClosing(l, itemObject, lexText)
}
if r == '_' {
l.Depth++
r = l.Next()
// TODO - Remove this, doesn't conform to the spec.
if r == 'u' {
return lexUidNode(l, itemObject, lexText)
}
if r == ':' {
return lexBlankNode(l, itemObject, lexText)
}
}
if r == '"' {
l.Ignore()
return lexLiteral(l)
}
return l.Errorf("Invalid char: %v at lexObject", r)
}
示例5: lexTextMutation
// lexTextMutation lexes and absorbs the text inside a mutation operation block.
func lexTextMutation(l *lex.Lexer) lex.StateFn {
for {
r := l.Next()
if r == lex.EOF {
return l.Errorf("Unclosed mutation text")
}
if r == quote {
return lexMutationValue
}
if r == leftCurl {
l.Depth++
}
if r == rightCurl {
if l.Depth > 2 {
l.Depth--
continue
}
}
if r != rightCurl {
// Absorb everything until we find '}'.
continue
}
l.Backup()
l.Emit(itemMutationContent)
break
}
return lexInsideMutation
}
示例6: lexUntilClosing
func lexUntilClosing(l *lex.Lexer, styp lex.ItemType,
sfn lex.StateFn) lex.StateFn {
l.AcceptUntil(isClosingBracket)
r := l.Next()
if r == lex.EOF {
return l.Errorf("Unexpected end of subject")
}
if r == '>' {
l.Emit(styp)
return sfn
}
return l.Errorf("Invalid character %v found for itemType: %v", r, styp)
}
示例7: lexAlias
func lexAlias(l *lex.Lexer) lex.StateFn {
l.AcceptRun(isSpace)
l.Ignore() // Any spaces encountered.
for {
r := l.Next()
if isNameSuffix(r) {
continue
}
l.Backup()
l.Emit(itemAlias)
break
}
return lexInside
}
示例8: lexScalarBlock
func lexScalarBlock(l *lex.Lexer) lex.StateFn {
for {
switch r := l.Next(); {
case r == ')':
l.Emit(itemRightRound)
return lexText
case isNameBegin(r):
l.Backup()
return lexScalarPair1
case isSpace(r) || isEndOfLine(r):
l.Ignore()
default:
return l.Errorf("Invalid schema. Unexpected %s", l.Input[l.Start:l.Pos])
}
}
}
示例9: lexObjectBlock
func lexObjectBlock(l *lex.Lexer) lex.StateFn {
for {
switch r := l.Next(); {
case r == leftCurl:
l.Emit(itemLeftCurl)
case isSpace(r) || isEndOfLine(r):
l.Ignore()
case r == rightCurl:
l.Emit(itemRightCurl)
return lexText
case isNameBegin(r):
return lexObjectPair
default:
return l.Errorf("Invalid schema. Unexpected %s", l.Input[l.Start:l.Pos])
}
}
}
示例10: lexMutationValue
// This function is used to absorb the object value.
func lexMutationValue(l *lex.Lexer) lex.StateFn {
for {
r := l.Next()
if r == '\\' {
// So that we don't count \" as end of value.
if l.Next() == quote {
continue
}
}
// This is an end of value so lets return.
if r == quote {
break
}
// We absorb everything else.
continue
}
return lexTextMutation
}
示例11: 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)
}
示例12: lexOperationType
func lexOperationType(l *lex.Lexer) lex.StateFn {
for {
r := l.Next()
if isNameSuffix(r) {
continue // absorb
}
l.Backup()
word := l.Input[l.Start:l.Pos]
if word == "mutation" {
l.Emit(itemOpType)
l.Mode = mutationMode
} else if word == "query" {
l.Emit(itemOpType)
l.Mode = queryMode
}
break
}
return lexText
}
示例13: lexLabel
func lexLabel(l *lex.Lexer) lex.StateFn {
r := l.Next()
// Graph label can either be an IRI or a blank node according to spec.
if r == '<' {
l.Depth++
return lexUntilClosing(l, itemLabel, lexText)
}
if r == '_' {
l.Depth++
r = l.Next()
if r != ':' {
return l.Errorf("Invalid char: %c at lexLabel", r)
}
l.Backup()
return lexBlankNode(l, itemLabel, lexText)
}
return l.Errorf("Invalid char: %v at lexLabel", r)
}
示例14: lexStart
func lexStart(l *lex.Lexer) lex.StateFn {
for {
r := l.Next()
if isNameSuffix(r) {
continue // absorb
}
l.Backup()
// l.Pos would be index of the end of operation type + 1.
word := l.Input[l.Start:l.Pos]
if word == "scalar" {
l.Emit(itemScalar)
return lexScalar
} else if word == "type" {
l.Emit(itemType)
return lexObject
} else {
return l.Errorf("Invalid schema")
}
}
}
示例15: lexObject
func lexObject(l *lex.Lexer) lex.StateFn {
r := l.Next()
if r == '<' {
l.Depth += 1
return lexUntilClosing(l, itemObject, lexText)
}
if r == '_' {
l.Depth += 1
return lexBlankNode(l, itemObject, lexText)
}
if r == '"' {
l.Ignore()
return lexLiteral(l)
}
return l.Errorf("Invalid char: %v at lexObject", r)
}